Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the theme of the page to light once the user is logged out #102

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/hooks/useThemes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useCurrentUser } from "~/routes/(app)/layout";
export const useThemes = () => {
const currentUser = useCurrentUser();
const theme = useSignal("");

useVisibleTask$(({ track }) => {
track(() => theme.value);
const html = document.querySelector("html");
Expand All @@ -16,17 +17,24 @@ export const useThemes = () => {
useVisibleTask$(({ track }) => {
track(() => currentUser.value);
const html = document.querySelector("html");
const value = currentUser.value?.theme as any;
const colorScheme = value?.colorScheme;
html?.setAttribute("data-theme", colorScheme);
theme.value = colorScheme;

if (!currentUser.value) {
html?.setAttribute("data-theme", "light");
theme.value = "light";
} else {
const value = currentUser.value?.theme as any;
const colorScheme = value?.colorScheme;
html?.setAttribute("data-theme", colorScheme);
theme.value = colorScheme;
}
});

const updateTheme = $((value: string) => {
const html = document.querySelector("html");
html?.setAttribute("data-theme", value);
theme.value = value;
});

return {
theme,
updateTheme,
Expand Down