Skip to content

Commit

Permalink
fix(graph): individual chapters approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Sep 3, 2022
1 parent 67eeb24 commit 7eeba2a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@
<div>
<IconUp
class="wb-icon w-5 h-5 ml-2"
@click.prevent.stop="page.onUpPage"
@click.prevent.stop="page.onUpPage(props.page)"
/>
</div>
<div>
<IconDown
class="wb-icon w-5 h-5"
@click.prevent.stop="page.onDownPage"
@click.prevent.stop="page.onDownPage(props.page)"
/>
</div>
<div>
<IconTrash
class="wb-icon w-5 h-5"
@click.prevent.stop="page.onDeletePage"
@click.prevent.stop="page.onDeletePage(props.page)"
/>
</div>
</div>
Expand Down
28 changes: 6 additions & 22 deletions packages/better-write-app/src/use/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useProjectStore } from '@/store/project'
import { useContextStore } from '@/store/context'
import { ContextState } from 'better-write-types'
import { useScroll } from './scroll'
import { usePlugin } from 'better-write-plugin-core'
import { useI18n } from 'vue-i18n'
import useEmitter from './emitter'
import { useBar } from './global/bar'
Expand All @@ -14,7 +13,6 @@ export const usePage = () => {
const CONTEXT = useContextStore()

const env = useEnv()
const plugin = usePlugin()
const bar = useBar()
const scroll = useScroll()
const { t } = useI18n()
Expand All @@ -39,8 +37,6 @@ export const usePage = () => {

scroll.force('#editor-aside')

plugin.emit('plugin-project-page-new', arr.length - 1)

await nextTick

emitter.emit('entity-text-focus', {
Expand All @@ -50,47 +46,35 @@ export const usePage = () => {
})
}

const onDeletePage = async () => {
const onDeletePage = async (page: ContextState) => {
if (!confirm(t('editor.window.deleteChapterPage'))) return

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

if (PROJECT.pages.length <= 1) return

bar.load(async () => {
plugin.emit('plugin-project-page-delete', CONTEXT.entities[0].raw)

PROJECT.deletePage(CONTEXT.$state)
PROJECT.deletePage(page)

await nextTick

CONTEXT.load(PROJECT.pages[PROJECT.pages.length - 1])
})
}

const onUpPage = (e: MouseEvent) => {
const onUpPage = (page: ContextState) => {
bar.load(() => {
plugin.emit('plugin-project-page-swap', {
index: utils().getPageIndex(CONTEXT.$state.id),
direction: 'up',
})

PROJECT.switchPage({
page: CONTEXT.$state,
page,
direction: 'up',
})
})
}

const onDownPage = (e: MouseEvent) => {
const onDownPage = (page: ContextState) => {
bar.load(() => {
plugin.emit('plugin-project-page-swap', {
index: utils().getPageIndex(CONTEXT.$state.id),
direction: 'down',
})

PROJECT.switchPage({
page: CONTEXT.$state,
page,
direction: 'down',
})
})
Expand Down

0 comments on commit 7eeba2a

Please sign in to comment.