Skip to content

Commit

Permalink
refactor: load project hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Sep 27, 2021
1 parent 36dc07c commit 0f6c968
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 25 deletions.
12 changes: 2 additions & 10 deletions src/components/editor/aside/project/AsideLoadProject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@
import { useI18n } from 'vue-i18n'
import { useLocalStorage } from '@/use/storage/local'
import { useStore } from 'vuex'
import { nextTick } from 'vue'
const store = useStore()
const onLoadProject = async () => {
const context = useLocalStorage().getProject()
if (!context) return
store.commit('project/load', context.project)
await nextTick
store.commit('context/load', store.state.project.pages[0])
const onLoadProject = () => {
useLocalStorage(store).onLoadProject()
}
const { t } = useI18n()
Expand Down
2 changes: 1 addition & 1 deletion src/lang/br/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ export default {
],
},
},
}
}
4 changes: 2 additions & 2 deletions src/lang/br/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import editor from './editor';
import editor from './editor'

export default {
editor
editor,
}
2 changes: 1 addition & 1 deletion src/lang/en/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ export default {
],
},
},
}
}
4 changes: 2 additions & 2 deletions src/lang/en/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import editor from './editor';
import editor from './editor'

export default {
editor
editor,
}
9 changes: 1 addition & 8 deletions src/use/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@ export const useKeyboard: Callback<any> = () => {
async (e: Event) => {
useUtils().prevent(e)

const context = useLocalStorage().getProject()

if (!context) return

store.commit('project/load', context.project)
await nextTick

store.commit('context/load', store.state.project.pages[0])
useLocalStorage(store).onLoadProject()
}
)
}
Expand Down
14 changes: 13 additions & 1 deletion src/use/storage/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ProjectObject } from '@/types/project'
import { Callback } from '@/types/utils'
import { Store } from 'vuex'
import { useEnv } from '../env'
import { nextTick } from 'vue'

export const useLocalStorage: Callback<any> = (store: Store<any>) => {
const set = (obj: ProjectObject, name: string) => {
Expand Down Expand Up @@ -29,5 +30,16 @@ export const useLocalStorage: Callback<any> = (store: Store<any>) => {
})
}

return { set, get, setProject, getProject, onSaveProject }
const onLoadProject = async () => {
const context = useLocalStorage().getProject()

if (!context) return

store.commit('project/load', context.project)
await nextTick

store.commit('context/load', store.state.project.pages[0])
}

return { set, get, setProject, getProject, onSaveProject, onLoadProject }
}

0 comments on commit 0f6c968

Please sign in to comment.