mirror of
https://github.com/versia-pub/frontend.git
synced 2026-06-14 07:29:15 +02:00
chore: ⬆️ Upgrade to Nuxt 4
Some checks failed
Some checks failed
This commit is contained in:
parent
8debe97f63
commit
7f7cf20311
386 changed files with 2376 additions and 2332 deletions
56
app/composables/Preference.ts
Normal file
56
app/composables/Preference.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { StorageSerializers } from "@vueuse/core";
|
||||
import { preferences as prefs } from "~/components/preferences/preferences";
|
||||
|
||||
type SerializedPreferences = {
|
||||
[K in keyof typeof prefs]: (typeof prefs)[K]["options"]["defaultValue"];
|
||||
};
|
||||
|
||||
const usePreferences = (): {
|
||||
[K in keyof typeof prefs]: WritableComputedRef<
|
||||
(typeof prefs)[K]["options"]["defaultValue"]
|
||||
>;
|
||||
} => {
|
||||
const localStorage = useLocalStorage<SerializedPreferences>(
|
||||
"versia:preferences",
|
||||
Object.fromEntries(
|
||||
Object.entries(prefs).map(([key, value]) => [
|
||||
key,
|
||||
value.options.defaultValue,
|
||||
]),
|
||||
) as SerializedPreferences,
|
||||
{
|
||||
serializer: {
|
||||
read(raw) {
|
||||
return StorageSerializers.object.read(raw);
|
||||
},
|
||||
write(value) {
|
||||
return StorageSerializers.object.write(value);
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return Object.fromEntries(
|
||||
Object.entries(prefs).map(([key, value]) => [
|
||||
key,
|
||||
computed({
|
||||
get() {
|
||||
return (
|
||||
localStorage.value[key as keyof typeof prefs] ??
|
||||
value.options.defaultValue
|
||||
);
|
||||
},
|
||||
set(newValue) {
|
||||
// @ts-expect-error Key is marked as readonly in the type
|
||||
localStorage.value[key] = newValue;
|
||||
},
|
||||
}),
|
||||
]),
|
||||
) as {
|
||||
[K in keyof typeof prefs]: WritableComputedRef<
|
||||
(typeof prefs)[K]["options"]["defaultValue"]
|
||||
>;
|
||||
};
|
||||
};
|
||||
|
||||
export const preferences = usePreferences();
|
||||
Loading…
Add table
Add a link
Reference in a new issue