Skip to content

Commit 6777fac

Browse files
committed
feat: simple save and load project
1 parent 539b365 commit 6777fac

File tree

12 files changed

+181
-3
lines changed

12 files changed

+181
-3
lines changed

.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
VITE_PROJECT_EMPTY=__NOT_CREATED__
1+
VITE_PROJECT_EMPTY=__NOT_CREATED__
2+
VITE_LOCAL_STORAGE=__BETTER_WRITE__

src/App.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
</template>
55

66
<script setup lang="ts">
7+
import { onMounted } from 'vue'
78
import { useI18n } from 'vue-i18n'
89
import { useStart } from '@/use/start'
10+
import { useIndexedDB } from '@/use/storage/indexed'
911
1012
const { t } = useI18n()
1113
1214
useStart().init()
15+
16+
onMounted(() => {})
1317
</script>

src/components/editor/aside/project/AsideBarProject.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
<AsideProjectNew />
1919
<AsidePageNew v-if="store.state.project.name !== useEnv().projectEmpty()" />
2020
<AsideLine v-if="store.state.project.name !== useEnv().projectEmpty()" />
21+
<AsideLoadProject />
22+
<AsideSaveProject
23+
v-if="store.state.project.name !== useEnv().projectEmpty()"
24+
/>
25+
<AsideLine v-if="store.state.project.name !== useEnv().projectEmpty()" />
2126
<AsideGeneratePDF
2227
v-if="store.state.project.name !== useEnv().projectEmpty()"
2328
/>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<InjectButtonInstance class="wb-aside-button" @click.prevent="onSaveProject">
3+
{{ t('editor.aside.project.load.title') }}
4+
</InjectButtonInstance>
5+
</template>
6+
7+
<script setup lang="ts">
8+
import { useI18n } from 'vue-i18n'
9+
import { useLocalStorage } from '@/use/storage/local'
10+
import { useStore } from 'vuex'
11+
import { nextTick } from 'vue'
12+
13+
const store = useStore()
14+
15+
const onSaveProject = async () => {
16+
const context = useLocalStorage().getProject()
17+
18+
store.commit('project/load', context.project)
19+
await nextTick
20+
21+
store.commit('context/load', store.state.project.pages[0])
22+
}
23+
24+
const { t } = useI18n()
25+
</script>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<template>
2+
<InjectButtonInstance class="wb-aside-button" @click.prevent="onSaveProject">
3+
{{ t('editor.aside.project.save.title') }}
4+
</InjectButtonInstance>
5+
</template>
6+
7+
<script setup lang="ts">
8+
import { useI18n } from 'vue-i18n'
9+
import { useLocalStorage } from '@/use/storage/local'
10+
import { useStore } from 'vuex'
11+
12+
const store = useStore()
13+
14+
const onSaveProject = () => {
15+
useLocalStorage().setProject({
16+
project: store.state.project,
17+
editor: store.state.editor,
18+
})
19+
}
20+
21+
const { t } = useI18n()
22+
</script>

src/lang/br.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export default {
2222
},
2323
project: {
2424
title: 'Projeto',
25+
save: {
26+
title: 'Salvar Projeto',
27+
},
28+
load: {
29+
title: 'Carregar Projeto',
30+
},
2531
blocked: 'Crie ou carregue um projeto!!!',
2632
page: {
2733
new: {

src/lang/en.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export default {
2222
},
2323
project: {
2424
title: 'Project',
25+
save: {
26+
title: 'Save Project',
27+
},
28+
load: {
29+
title: 'Load Project',
30+
},
2531
blocked: 'Create or load a project!!!',
2632
page: {
2733
new: {

src/store/module/project.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ProjectState } from '@/types/project'
22
import { useText } from '@/use/text'
33
import { useFormat } from '@/use/format'
44
import { ContextState, ContextStatePageContent } from '@/types/context'
5-
import { useI18n } from 'vue-i18n'
65

76
export default {
87
namespaced: true,
@@ -18,6 +17,16 @@ export default {
1817
pageLoaded: 0,
1918
} as ProjectState),
2019
mutations: {
20+
load(state: any, payload: ProjectState) {
21+
state.name = payload.name
22+
state.nameRaw = payload.nameRaw
23+
state.version = payload.version
24+
state.totalPagesCreated = payload.totalPagesCreated
25+
state.main = payload.main
26+
state.summary = payload.summary
27+
state.pages = payload.pages
28+
state.pageLoaded = payload.pageLoaded
29+
},
2130
create(state: any, payload: Record<any, any>) {
2231
state.name = useText().kebab(payload.name)
2332
state.nameRaw = payload.name

src/types/project.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ContextState } from '@/types/context'
2+
import { EditorState } from './editor'
23

34
export interface ProjectState {
45
name: string
@@ -10,3 +11,8 @@ export interface ProjectState {
1011
pages: Array<ContextState>
1112
pageLoaded: number
1213
}
14+
15+
export interface ProjectObject {
16+
project: ProjectState
17+
editor: EditorState
18+
}

src/use/env.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@ export const useEnv: Callback<any> = () => {
55
return import.meta.env.VITE_PROJECT_EMPTY as string
66
}
77

8-
return { projectEmpty }
8+
const projectLocalStorage = () => {
9+
return import.meta.env.VITE_LOCAL_STORAGE as string
10+
}
11+
12+
return { projectEmpty, projectLocalStorage }
913
}

0 commit comments

Comments
 (0)