Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Anything Llm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
Mintplex Labs
Anything Llm
Commits
363f51ab
Commit
363f51ab
authored
4 months ago
by
timothycarambat
Browse files
Options
Downloads
Patches
Plain Diff
refresh theme without reloading page
parent
af16332c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/LogoContext.jsx
+22
-17
22 additions, 17 deletions
frontend/src/LogoContext.jsx
frontend/src/hooks/useTheme.js
+10
-7
10 additions, 7 deletions
frontend/src/hooks/useTheme.js
with
32 additions
and
24 deletions
frontend/src/LogoContext.jsx
+
22
−
17
View file @
363f51ab
...
@@ -5,6 +5,7 @@ import DefaultLoginLogoLight from "./media/illustrations/login-logo.svg";
...
@@ -5,6 +5,7 @@ import DefaultLoginLogoLight from "./media/illustrations/login-logo.svg";
import
DefaultLoginLogoDark
from
"
./media/illustrations/login-logo-light.svg
"
;
import
DefaultLoginLogoDark
from
"
./media/illustrations/login-logo-light.svg
"
;
import
System
from
"
./models/system
"
;
import
System
from
"
./models/system
"
;
export
const
REFETCH_LOGO_EVENT
=
"
refetch-logo
"
;
export
const
LogoContext
=
createContext
();
export
const
LogoContext
=
createContext
();
export
function
LogoProvider
({
children
})
{
export
function
LogoProvider
({
children
})
{
...
@@ -16,32 +17,36 @@ export function LogoProvider({ children }) {
...
@@ -16,32 +17,36 @@ export function LogoProvider({ children }) {
?
DefaultLoginLogoDark
?
DefaultLoginLogoDark
:
DefaultLoginLogoLight
;
:
DefaultLoginLogoLight
;
useEffect
(()
=>
{
async
function
fetchInstanceLogo
()
{
async
function
fetchInstanceLogo
()
{
try
{
try
{
const
{
isCustomLogo
,
logoURL
}
=
await
System
.
fetchLogo
();
const
{
isCustomLogo
,
logoURL
}
=
await
System
.
fetchLogo
();
if
(
logoURL
)
{
if
(
logoURL
)
{
setLogo
(
logoURL
);
setLogo
(
logoURL
);
setLoginLogo
(
isCustomLogo
?
logoURL
:
DefaultLoginLogo
);
setLoginLogo
(
isCustomLogo
?
logoURL
:
DefaultLoginLogo
);
setIsCustomLogo
(
isCustomLogo
);
setIsCustomLogo
(
isCustomLogo
);
}
else
{
}
else
{
localStorage
.
getItem
(
"
theme
"
)
!==
"
default
"
?
setLogo
(
AnythingLLMDark
)
:
setLogo
(
AnythingLLM
);
setLoginLogo
(
DefaultLoginLogo
);
setIsCustomLogo
(
false
);
}
}
catch
(
err
)
{
localStorage
.
getItem
(
"
theme
"
)
!==
"
default
"
localStorage
.
getItem
(
"
theme
"
)
!==
"
default
"
?
setLogo
(
AnythingLLMDark
)
?
setLogo
(
AnythingLLMDark
)
:
setLogo
(
AnythingLLM
);
:
setLogo
(
AnythingLLM
);
setLoginLogo
(
DefaultLoginLogo
);
setLoginLogo
(
DefaultLoginLogo
);
setIsCustomLogo
(
false
);
setIsCustomLogo
(
false
);
console
.
error
(
"
Failed to fetch logo:
"
,
err
);
}
}
}
catch
(
err
)
{
localStorage
.
getItem
(
"
theme
"
)
!==
"
default
"
?
setLogo
(
AnythingLLMDark
)
:
setLogo
(
AnythingLLM
);
setLoginLogo
(
DefaultLoginLogo
);
setIsCustomLogo
(
false
);
console
.
error
(
"
Failed to fetch logo:
"
,
err
);
}
}
}
useEffect
(()
=>
{
fetchInstanceLogo
();
fetchInstanceLogo
();
window
.
addEventListener
(
REFETCH_LOGO_EVENT
,
fetchInstanceLogo
);
return
()
=>
{
window
.
removeEventListener
(
REFETCH_LOGO_EVENT
,
fetchInstanceLogo
);
};
},
[]);
},
[]);
return
(
return
(
...
...
This diff is collapsed.
Click to expand it.
frontend/src/hooks/useTheme.js
+
10
−
7
View file @
363f51ab
import
{
REFETCH_LOGO_EVENT
}
from
"
@/LogoContext
"
;
import
{
useState
,
useEffect
}
from
"
react
"
;
import
{
useState
,
useEffect
}
from
"
react
"
;
const
availableThemes
=
{
const
availableThemes
=
{
...
@@ -26,6 +27,7 @@ export function useTheme() {
...
@@ -26,6 +27,7 @@ export function useTheme() {
document
.
documentElement
.
setAttribute
(
"
data-theme
"
,
theme
);
document
.
documentElement
.
setAttribute
(
"
data-theme
"
,
theme
);
document
.
body
.
classList
.
toggle
(
"
light
"
,
theme
===
"
light
"
);
document
.
body
.
classList
.
toggle
(
"
light
"
,
theme
===
"
light
"
);
localStorage
.
setItem
(
"
theme
"
,
theme
);
localStorage
.
setItem
(
"
theme
"
,
theme
);
window
.
dispatchEvent
(
new
Event
(
REFETCH_LOGO_EVENT
));
},
[
theme
]);
},
[
theme
]);
// In development, attach keybind combinations to toggle theme
// In development, attach keybind combinations to toggle theme
...
@@ -34,20 +36,21 @@ export function useTheme() {
...
@@ -34,20 +36,21 @@ export function useTheme() {
function
toggleOnKeybind
(
e
)
{
function
toggleOnKeybind
(
e
)
{
if
(
e
.
metaKey
&&
e
.
key
===
"
.
"
)
{
if
(
e
.
metaKey
&&
e
.
key
===
"
.
"
)
{
e
.
preventDefault
();
e
.
preventDefault
();
const
newTheme
=
theme
===
"
light
"
?
"
default
"
:
"
light
"
;
setTheme
((
prev
)
=>
(
prev
===
"
light
"
?
"
default
"
:
"
light
"
));
console
.
log
(
"
toggling theme to
"
,
newTheme
);
setTheme
(
newTheme
);
}
}
}
}
document
.
addEventListener
(
"
keydown
"
,
toggleOnKeybind
);
document
.
addEventListener
(
"
keydown
"
,
toggleOnKeybind
);
return
()
=>
document
.
removeEventListener
(
"
keydown
"
,
toggleOnKeybind
);
return
()
=>
document
.
removeEventListener
(
"
keydown
"
,
toggleOnKeybind
);
},
[]);
},
[]);
// Refresh on theme change
/**
const
setTheme
=
(
newTheme
)
=>
{
* Sets the theme of the application and runs any
* other necessary side effects
* @param {string} newTheme The new theme to set
*/
function
setTheme
(
newTheme
)
{
_setTheme
(
newTheme
);
_setTheme
(
newTheme
);
window
.
location
.
reload
();
}
};
return
{
theme
,
setTheme
,
availableThemes
};
return
{
theme
,
setTheme
,
availableThemes
};
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment