Exifly / ApiVault

Your gateway to a world of public APIs.
https://apivault.dev
Other
435 stars 39 forks source link

refactoring and optimization for theme handler #206

Closed gdjohn4s closed 1 year ago

gdjohn4s commented 1 year ago

Description

Refactored theme handler functions on themeutils.ts and Navbar.vue component. Removed useless code logic and cleaned existent codebase.

Additional Information

With those changes, the theme handler is more efficient and stable using localStorage to store user theme preference. In the future, we'd like to make sure to apply theme preference on website pre-rendering stage, to provide a powerful theme handler to users.

Major changes

setLocalStorage function

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

Checklist