From c6547d4359f5966a284d915a730ed3a1c6a88201 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 22 Aug 2020 01:10:18 +0800 Subject: [PATCH] chore: refactoring --- package.json | 2 +- src/store/index.ts | 1 + src/store/local.ts | 4 ++++ src/utils/dark.ts | 12 ++++++------ 4 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 src/store/index.ts create mode 100644 src/store/local.ts diff --git a/package.json b/package.json index aa6b9b5..f52be4b 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "private": true, "scripts": { - "dev": "vite", + "dev": "vite -p 3333 --open", "build": "cross-env NODE_ENV=production vite build" }, "dependencies": { diff --git a/src/store/index.ts b/src/store/index.ts new file mode 100644 index 0000000..87c2c0a --- /dev/null +++ b/src/store/index.ts @@ -0,0 +1 @@ +export * from './local' diff --git a/src/store/local.ts b/src/store/local.ts new file mode 100644 index 0000000..45fe7cb --- /dev/null +++ b/src/store/local.ts @@ -0,0 +1,4 @@ +import { Ref } from 'vue' +import { useStorage } from '@vueuse/core' + +export const colorSchema = useStorage('vitesse-schema', 'auto') as Ref<'auto' | 'dark' | 'light'> diff --git a/src/utils/dark.ts b/src/utils/dark.ts index 06c9593..413997b 100644 --- a/src/utils/dark.ts +++ b/src/utils/dark.ts @@ -1,18 +1,18 @@ -import { watch, computed, Ref } from 'vue' -import { useStorage, usePreferredDark } from '@vueuse/core' +import { watch, computed } from 'vue' +import { usePreferredDark } from '@vueuse/core' +import { colorSchema } from '../store' const preferredDark = usePreferredDark() -const schema = useStorage('vitesse-schema', 'auto') as Ref<'auto' | 'dark' | 'light'> export const isDark = computed({ get() { - return schema.value === 'auto' ? preferredDark.value : schema.value === 'dark' + return colorSchema.value === 'auto' ? preferredDark.value : colorSchema.value === 'dark' }, set(v: boolean) { if (v === preferredDark.value) - schema.value = 'auto' + colorSchema.value = 'auto' else - schema.value = v ? 'dark' : 'light' + colorSchema.value = v ? 'dark' : 'light' }, })