Skip to content

Commit

Permalink
feat(editor): create page inside a editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Sep 24, 2021
1 parent 5f8960c commit 9c1c610
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 28 deletions.
19 changes: 6 additions & 13 deletions src/components/editor/aside/page/AsidePageNew.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
<template>
<button class="wb-aside-button" @click="onCreateNewPage">
<InjectButtonInstance
class="wb-aside-button"
@click.prevent="usePage().onCreatePage"
>
{{ t('editor.aside.project.page.new.title') }}
</button>
</InjectButtonInstance>
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { useStore } from 'vuex'
import { usePage } from '@/use/page'
const store = useStore()
const { t } = useI18n()
const onCreateNewPage = async () => {
store.commit('project/newPage')
const arr = store.state.project.pages
const obj = arr[arr.length - 1]
store.commit('context/load', obj)
}
</script>
2 changes: 1 addition & 1 deletion src/components/editor/main/EditorBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
rgba(0, 0, 0, 0.05) 0px 1px 1px 0px;
"
>
<EditorBaseHeader />
<EditorBaseHeader v-if="store.state.project.name !== '__NOT_CREATED__'" />
<EditorBaseBlocked
v-if="store.state.project.name === '__NOT_CREATED__'"
/>
Expand Down
36 changes: 22 additions & 14 deletions src/components/editor/main/EditorBaseHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,27 @@
<div
class="flex justify-end items-center relative bg-gray-300 dark:bg-gray-800"
>
<HeroIcon class="wb-icon inline-flex" @click.prevent="onDeletePage">
<HeroIcon
class="wb-icon inline-flex"
@click.prevent="usePage().onCreatePage"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M6 2a2 2 0 00-2 2v12a2 2 0 002 2h8a2 2 0 002-2V7.414A2 2 0 0015.414 6L12 2.586A2 2 0 0010.586 2H6zm5 6a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V8z"
clip-rule="evenodd"
/>
</svg>
</HeroIcon>
<HeroIcon
class="wb-icon inline-flex"
@click.prevent="usePage().onDeletePage"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6"
Expand All @@ -21,17 +41,5 @@
</template>

<script setup lang="ts">
import { nextTick } from 'vue'
import { useStore } from 'vuex'
const store = useStore()
const onDeletePage = async () => {
if (store.state.project.pages.length <= 1) return
store.commit('project/deletePage', store.state.context)
await nextTick
store.commit('context/load', store.state.project.pages[0])
}
import { usePage } from '@/use/page'
</script>
3 changes: 3 additions & 0 deletions src/components/utils/InjectButtonInstance.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<button><slot /></button>
</template>
26 changes: 26 additions & 0 deletions src/use/page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { nextTick } from 'vue'
import { useStore } from 'vuex'

export const usePage = () => {
const store = useStore()

const onCreatePage = async () => {
store.commit('project/newPage')

const arr = store.state.project.pages
const obj = arr[arr.length - 1]

store.commit('context/load', obj)
}

const onDeletePage = async () => {
if (store.state.project.pages.length <= 1) return

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

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

return { onCreatePage, onDeletePage }
}

0 comments on commit 9c1c610

Please sign in to comment.