chore: refactoring

This commit is contained in:
Anthony Fu 2020-08-22 01:10:18 +08:00
parent 86b3ed348f
commit c6547d4359
4 changed files with 12 additions and 7 deletions

View File

@ -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": {

1
src/store/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './local'

4
src/store/local.ts Normal file
View File

@ -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'>

View File

@ -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'
},
})