From 40e9af06cf28b7348152f8ec3898fa2b27ec0b21 Mon Sep 17 00:00:00 2001 From: Corentin Thomasset Date: Mon, 4 Apr 2022 17:27:34 +0200 Subject: [PATCH] feat: persistent theme selection fallback to prefered theme --- src/stores/style.store.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/stores/style.store.ts b/src/stores/style.store.ts index 7c2099c0..c11fde2d 100644 --- a/src/stores/style.store.ts +++ b/src/stores/style.store.ts @@ -1,5 +1,13 @@ +import { useStorage, usePreferredDark } from '@vueuse/core'; import { defineStore } from 'pinia'; +import type { Ref } from 'vue'; -export const useStyleStore = defineStore('style', () => ({ - isDarkTheme: true, -})); +export const useStyleStore = defineStore('style', { + state: () => { + const isDark = usePreferredDark(); + + return { + isDarkTheme: useStorage('useDarkTheme', isDark) as Ref, + }; + }, +});