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

Colorscheme refactoring and fixes #179

Merged
merged 17 commits into from
May 25, 2023
Merged
Changes from 1 commit
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
29 changes: 11 additions & 18 deletions frontend/utils/themeutils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function getTheme(): string {
export function setTheme(): string {
const theme = localStorage.getItem("APIVaultTheme");
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
if (process.client) {
Expand All @@ -18,35 +18,28 @@ export const themeIcons: { [key: string]: string } = {
dark: "fa-solid fa-moon",
};

export const setThemeElements = (theme: globalThis.Ref<string>): void => {
if (theme.value === null) {
document.querySelector("body")?.setAttribute("data-theme", "dark");
export const getThemeElements = (theme: globalThis.Ref<string>): boolean => {
if (theme.value === null || theme.value === 'dark') {
return true
}
document.querySelector("body")?.setAttribute("data-theme", theme.value);
return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be replaced with

+ return theme.value === null || theme.value === 'dark'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


export const setThemeLogoPath = (theme: globalThis.Ref<string>): string => {
if (theme.value === null || theme.value === undefined) {
return `/img/apivault-full-dark-nobg.png`;
}
return `/img/apivault-full-${theme.value}-nobg.png`;
}

/**
This code generates a string that represents the mode of the theme,
either "Light Mode" or "Dark Mode", depending on the theme.value
*/
export const setIconThemeText = (theme: globalThis.Ref<string>): string => {
return theme.value
? theme.value[0].toUpperCase() +
theme.value.slice(1, theme.value.length) +
" Mode"
: " Mode"
}

export const setLocalStorage = (theme: globalThis.Ref<string>): void => {
export const setLocalStorage = (theme: globalThis.Ref<string>): boolean => {
if (theme.value === "dark" || theme.value === undefined) {
theme.value = "light";
localStorage.setItem("APIVaultTheme", "light");
return false;
} else {
theme.value = "dark";
localStorage.setItem("APIVaultTheme", "dark");
return true;
}
}