Skip to content

Commit

Permalink
chore: styleStore重命名为globalStore
Browse files Browse the repository at this point in the history
  • Loading branch information
ZvonimirSun committed Feb 27, 2024
1 parent 5c07304 commit c577bc8
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .eslintrc-auto-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@
"useTinyEditorStore": true,
"useToolsStore": true,
"useUserStore": true,
"useSettingStore": true
"useSettingStore": true,
"useGlobalStore": true
}
}
3 changes: 2 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
type="primary"
class="dark-mode-trigger"
circle
@click="useStyleStore().toggleTheme"
@click="useGlobalStore().toggleTheme"
>
<i
class="dark:i-icon-park-outline-moon i-icon-park-outline-sun-one"
Expand Down Expand Up @@ -104,6 +104,7 @@ import { useRegisterSW } from 'virtual:pwa-register/vue'
import zhCN from 'element-plus/es/locale/lang/zh-cn'
import $axios from '@/plugins/Axios'
import config from '@/config'
import { useGlobalStore } from '@/stores/global'
const {
offlineReady,
Expand Down
2 changes: 1 addition & 1 deletion src/components/JsonEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import 'vanilla-jsoneditor/themes/jse-theme-dark.css'
import JsonEditorVue from 'json-editor-vue'
const isDark = useStyleStore().isDark
const isDark = useGlobalStore().isDark
</script>

<template>
Expand Down
4 changes: 2 additions & 2 deletions src/components/VanillaJsonEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ onBeforeUnmount(() => {
})
watch(
() => useStyleStore().isDark,
() => useGlobalStore().isDark,
() => {
jsonEditor?.refresh()
}
Expand Down Expand Up @@ -422,7 +422,7 @@ function _pickDefinedProps (object: Record<string, any>, propNames: string[]) {
ref="jsonEditorDiv"
class="json-editor"
:class="{
'jse-theme-dark': useStyleStore().isDark
'jse-theme-dark': useGlobalStore().isDark
}"
/>
<input
Expand Down
6 changes: 3 additions & 3 deletions src/components/editor/EditorMini.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const extensions = [
mini.extensions,
props.plugin ? props.plugin.miniExtensions || props.plugin.extensions : [],
EditorView.updateListener.of(onChange),
themeCompartment.of(useStyleStore().isDark ? oneDarkTheme : EditorView.theme({}, { dark: false })),
highLightCompartment.of(useStyleStore().isDark ? syntaxHighlighting(oneDarkHighlightStyle, { fallback: true }) : syntaxHighlighting(defaultHighlightStyle))
themeCompartment.of(useGlobalStore().isDark ? oneDarkTheme : EditorView.theme({}, { dark: false })),
highLightCompartment.of(useGlobalStore().isDark ? syntaxHighlighting(oneDarkHighlightStyle, { fallback: true }) : syntaxHighlighting(defaultHighlightStyle))
]
if (props.placeholder) {
extensions.push(PlaceHolder(props.placeholder))
Expand All @@ -56,7 +56,7 @@ onUnmounted(() => {
cm?.destroy()
})
watch(() => useStyleStore().isDark, (val) => {
watch(() => useGlobalStore().isDark, (val) => {
cm.dispatch({
effects: [
themeCompartment.reconfigure(val ? oneDarkTheme : EditorView.theme({}, { dark: false })),
Expand Down
13 changes: 0 additions & 13 deletions src/pages/Loading.vue

This file was deleted.

1 change: 0 additions & 1 deletion src/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export { default as Page404 } from './404.vue'
export { default as Home } from './Home.vue'
export { default as Offline } from './Offline.vue'
export { default as Redirect } from './Redirect.vue'
export { default as Loading } from './Loading.vue'
2 changes: 1 addition & 1 deletion src/plugins/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import type { DefineComponent } from 'vue'
import { isExternalLink } from '@/utils/common'
import config from '@/config'
import { Home, Offline, Page404, Page403, Redirect } from '@/pages'
import { Home, Offline, Page403, Page404, Redirect } from '@/pages'

const toolsStore = useToolsStore()
const userStore = useUserStore()
Expand Down
12 changes: 4 additions & 8 deletions src/stores/style.ts → src/stores/global.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { acceptHMRUpdate, defineStore } from 'pinia'

const isDark = useDark()
const toggleDark = useToggle(isDark)

export const useStyleStore = defineStore('style', {
export const useGlobalStore = defineStore('global', {
state: () => ({
isDark,
toggleDark
isDark
}),
actions: {
setTheme (value?: 'dark' | 'light' | 'auto') {
Expand Down Expand Up @@ -48,9 +44,9 @@ export const useStyleStore = defineStore('style', {
})

watch(isDark, function () {
useStyleStore().setTheme()
useGlobalStore().setTheme()
})

if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useStyleStore, import.meta.hot))
import.meta.hot.accept(acceptHMRUpdate(useGlobalStore, import.meta.hot))
}
2 changes: 1 addition & 1 deletion src/tools/internal/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ import type { FormInstance, FormRules } from 'element-plus'
const router = useRouter()
const route = useRoute()
const styleStore = useStyleStore()
const styleStore = useGlobalStore()
const userStore = useUserStore()
const settingStore = useSettingStore()
Expand Down
5 changes: 3 additions & 2 deletions src/types/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ declare global {
const useFullscreen: typeof import('@vueuse/core')['useFullscreen']
const useGamepad: typeof import('@vueuse/core')['useGamepad']
const useGeolocation: typeof import('@vueuse/core')['useGeolocation']
const useGlobalStore: typeof import('../stores/global')['useGlobalStore']
const useIdle: typeof import('@vueuse/core')['useIdle']
const useImage: typeof import('@vueuse/core')['useImage']
const useImgHostingStore: typeof import('../stores/imgHosting')['useImgHostingStore']
Expand Down Expand Up @@ -505,6 +506,7 @@ declare module 'vue' {
readonly useFullscreen: UnwrapRef<typeof import('@vueuse/core')['useFullscreen']>
readonly useGamepad: UnwrapRef<typeof import('@vueuse/core')['useGamepad']>
readonly useGeolocation: UnwrapRef<typeof import('@vueuse/core')['useGeolocation']>
readonly useGlobalStore: UnwrapRef<typeof import('../stores/global')['useGlobalStore']>
readonly useIdle: UnwrapRef<typeof import('@vueuse/core')['useIdle']>
readonly useImage: UnwrapRef<typeof import('@vueuse/core')['useImage']>
readonly useImgHostingStore: UnwrapRef<typeof import('../stores/imgHosting')['useImgHostingStore']>
Expand Down Expand Up @@ -571,7 +573,6 @@ declare module 'vue' {
readonly useStorage: UnwrapRef<typeof import('@vueuse/core')['useStorage']>
readonly useStorageAsync: UnwrapRef<typeof import('@vueuse/core')['useStorageAsync']>
readonly useStore: UnwrapRef<typeof import('../stores/urlEncode')['useStore']>
readonly useStyleStore: UnwrapRef<typeof import('../stores/style')['useStyleStore']>
readonly useStyleTag: UnwrapRef<typeof import('@vueuse/core')['useStyleTag']>
readonly useSupported: UnwrapRef<typeof import('@vueuse/core')['useSupported']>
readonly useSwipe: UnwrapRef<typeof import('@vueuse/core')['useSwipe']>
Expand Down Expand Up @@ -814,6 +815,7 @@ declare module '@vue/runtime-core' {
readonly useFullscreen: UnwrapRef<typeof import('@vueuse/core')['useFullscreen']>
readonly useGamepad: UnwrapRef<typeof import('@vueuse/core')['useGamepad']>
readonly useGeolocation: UnwrapRef<typeof import('@vueuse/core')['useGeolocation']>
readonly useGlobalStore: UnwrapRef<typeof import('../stores/global')['useGlobalStore']>
readonly useIdle: UnwrapRef<typeof import('@vueuse/core')['useIdle']>
readonly useImage: UnwrapRef<typeof import('@vueuse/core')['useImage']>
readonly useImgHostingStore: UnwrapRef<typeof import('../stores/imgHosting')['useImgHostingStore']>
Expand Down Expand Up @@ -880,7 +882,6 @@ declare module '@vue/runtime-core' {
readonly useStorage: UnwrapRef<typeof import('@vueuse/core')['useStorage']>
readonly useStorageAsync: UnwrapRef<typeof import('@vueuse/core')['useStorageAsync']>
readonly useStore: UnwrapRef<typeof import('../stores/urlEncode')['useStore']>
readonly useStyleStore: UnwrapRef<typeof import('../stores/style')['useStyleStore']>
readonly useStyleTag: UnwrapRef<typeof import('@vueuse/core')['useStyleTag']>
readonly useSupported: UnwrapRef<typeof import('@vueuse/core')['useSupported']>
readonly useSwipe: UnwrapRef<typeof import('@vueuse/core')['useSwipe']>
Expand Down

0 comments on commit c577bc8

Please sign in to comment.