Skip to content

Commit

Permalink
fix(editor): stores reset in new projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Nov 13, 2021
1 parent 7f3d801 commit e701567
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/pages/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<script setup lang="ts">
import { setTheme } from '@/plugin/theme/external'
import { ThemeNormalize } from '@/plugin/theme/utils'
import { ThemeNormalize } from '@/plugin/theme/utils'
import { useContextStore } from '@/store/context'
import { useEditorStore } from '@/store/editor'
import { useProjectStore } from '@/store/project'
Expand Down
26 changes: 15 additions & 11 deletions src/plugin/theme/external.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import { useEditorStore } from '@/store/editor'
import { onAfterMounted } from '../core/cycle'
import { ThemeNormalize } from './utils'
import { useProjectStore } from '@/store/project';
import { useEnv } from '@/use/env';
import { useProjectStore } from '@/store/project'
import { useEnv } from '@/use/env'

export const setTheme = () => {
onAfterMounted(() => {
const EDITOR = useEditorStore()
const PROJECT = useProjectStore()
setThemeInvokate()
})
}

const env = useEnv()
export const setThemeInvokate = () => {
const EDITOR = useEditorStore()
const PROJECT = useProjectStore()

if(PROJECT.name === env.projectEmpty()) return
const env = useEnv()

const theme = EDITOR.configuration.theme
if (PROJECT.name === env.projectEmpty()) return

const value = ThemeNormalize(theme)
const theme = EDITOR.configuration.theme

document.body.classList.add(value)
})
const value = ThemeNormalize(theme)

document.body.removeAttribute('class')
document.body.classList.add(value)
}

2 changes: 1 addition & 1 deletion src/store/absolute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const useAbsoluteStore = defineStore('absolute', {
modal: {
newProject: false,
},
aside: false,
aside: true,
shortcuts: {
switcher: false,
finder: false,
Expand Down
14 changes: 14 additions & 0 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { useEnv } from '@/use/env'
import { useLoggerStore } from './logger'
import { useEditorStore } from './editor'
import { usePDFStore } from './pdf'
import { useAbsoluteStore } from './absolute'
import { useShortcutsStore } from './shortcuts'

export const useProjectStore = defineStore('project', {
state: (): ProjectState => {
Expand All @@ -35,7 +37,11 @@ export const useProjectStore = defineStore('project', {
const logger = useLoggerStore()
const editor = useEditorStore()
const pdf = usePDFStore()
const absolute = useAbsoluteStore()
const shortcuts = useShortcutsStore()

absolute.$reset()
shortcuts.$reset()
editor.$reset()
pdf.resetStyles()
logger.reset()
Expand All @@ -58,7 +64,11 @@ export const useProjectStore = defineStore('project', {
const logger = useLoggerStore()
const editor = useEditorStore()
const pdf = usePDFStore()
const absolute = useAbsoluteStore()
const shortcuts = useShortcutsStore()

absolute.$reset()
shortcuts.$reset()
editor.$reset()
pdf.resetStyles()
logger.reset()
Expand Down Expand Up @@ -102,7 +112,11 @@ export const useProjectStore = defineStore('project', {
const logger = useLoggerStore()
const editor = useEditorStore()
const pdf = usePDFStore()
const absolute = useAbsoluteStore()
const shortcuts = useShortcutsStore()

absolute.$reset()
shortcuts.$reset()
editor.$reset()
pdf.resetStyles()
logger.reset()
Expand Down
13 changes: 13 additions & 0 deletions src/use/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useAbsoluteStore } from '@/store/absolute'
import { ProjectObject } from '@/types/project'
import { ContextState } from '@/types/context'
import { useStorage } from './storage/storage'
import { setThemeInvokate } from '@/plugin/theme/external'

export const useProject = () => {
const PROJECT = useProjectStore()
Expand Down Expand Up @@ -51,6 +52,12 @@ export const useProject = () => {
destroy()
init()

await nextTick

setThemeInvokate()

await nextTick

toast.success(t('toast.project.create'))
})
}
Expand Down Expand Up @@ -84,6 +91,12 @@ export const useProject = () => {

init()

await nextTick

setThemeInvokate()

await nextTick

ABSOLUTE.aside = true

toast.success(t('toast.project.load'))
Expand Down

0 comments on commit e701567

Please sign in to comment.