feat: manually switch color scheme
This commit is contained in:
30
frontend/src/hooks/usePreferences.ts
Normal file
30
frontend/src/hooks/usePreferences.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
const defaultPreferences = [
|
||||
{
|
||||
key: "colorScheme",
|
||||
value: "system",
|
||||
},
|
||||
];
|
||||
|
||||
const get = (key: string) => {
|
||||
if (typeof window !== "undefined") {
|
||||
const preferences = JSON.parse(localStorage.getItem("preferences") ?? "{}");
|
||||
return (
|
||||
preferences[key] ??
|
||||
defaultPreferences.find((p) => p.key == key)?.value ??
|
||||
null
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const set = (key: string, value: string) => {
|
||||
if (typeof window !== "undefined") {
|
||||
const preferences = JSON.parse(localStorage.getItem("preferences") ?? "{}");
|
||||
preferences[key] = value;
|
||||
localStorage.setItem("preferences", JSON.stringify(preferences));
|
||||
}
|
||||
};
|
||||
const usePreferences = () => {
|
||||
return { get, set };
|
||||
};
|
||||
|
||||
export default usePreferences;
|
||||
Reference in New Issue
Block a user