Skip to content

Commit

Permalink
fix(editor): overlap in save large scale projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Aug 19, 2022
1 parent 217cbba commit f74e028
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 97 deletions.
78 changes: 9 additions & 69 deletions packages/better-write-app/src/use/annotations.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,37 @@
import { useNProgress } from '@vueuse/integrations/useNProgress'
import { usePlugin } from 'better-write-plugin-core'
import {
ProjectStateAnnotationFile,
ProjectStateAnnotationFolder,
} from 'better-write-types'
import { useUtils } from './utils'
import { useI18n } from 'vue-i18n'

export const useAnnotations = () => {
const { fn } = useUtils()
const plugin = usePlugin()
const { isLoading } = useNProgress()
const { t } = useI18n()

const onStart = (file: ProjectStateAnnotationFile) => {
fn().promisedFn(
() => {
plugin.emit('plugin-annotations-start', file)
},
{
start: () => {
isLoading.value = true
},
end: () => {
isLoading.value = false
},
}
)
plugin.emit('plugin-annotations-start', file)
}

const onFileCreate = (folder: ProjectStateAnnotationFolder) => {
fn().promisedFn(
() => {
plugin.emit('plugin-annotations-file-create', folder)
},
{
start: () => {
isLoading.value = true
},
end: () => {
isLoading.value = false
},
}
)
plugin.emit('plugin-annotations-file-create', folder)
}

const onFileDelete = (obj: {
file: ProjectStateAnnotationFile
folder: ProjectStateAnnotationFolder
}) => {
fn().promisedFn(
() => {
plugin.emit('plugin-annotations-file-delete', obj)
},
{
start: () => {
isLoading.value = true
},
end: () => {
isLoading.value = false
},
}
)
if (confirm(t('toast.project.annotations.fileDelete')))
plugin.emit('plugin-annotations-file-delete', obj)
}

const onFolderCreate = () => {
fn().promisedFn(
() => {
plugin.emit('plugin-annotations-folder-create')
},
{
start: () => {
isLoading.value = true
},
end: () => {
isLoading.value = false
},
}
)
plugin.emit('plugin-annotations-folder-create')
}

const onFolderDelete = (folder: ProjectStateAnnotationFolder) => {
fn().promisedFn(
() => {
plugin.emit('plugin-annotations-folder-delete', folder)
},
{
start: () => {
isLoading.value = true
},
end: () => {
isLoading.value = false
},
}
)
if (confirm(t('toast.project.annotations.folderDelete')))
plugin.emit('plugin-annotations-folder-delete', folder)
}

return { onStart, onFileCreate, onFileDelete, onFolderCreate, onFolderDelete }
Expand Down
18 changes: 9 additions & 9 deletions packages/better-write-app/src/use/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { useEntity } from '@/use/entity'
import { useEnv } from '@/use/env'
import { useProject } from '@/use/project'
import { useLocalStorage } from '@/use/storage/local'
import { useEventListener, useFullscreen, useNetwork } from '@vueuse/core'
import {
useEventListener,
useFullscreen,
useIntervalFn,
useNetwork,
} from '@vueuse/core'
import { useHead } from '@vueuse/head'
import { usePlugin } from 'better-write-plugin-core'
import { computed, onBeforeMount, onMounted, watch } from 'vue'
Expand Down Expand Up @@ -52,14 +57,9 @@ export const useEditor = () => {
})

if (EDITOR.configuration.autosave) {
// tracking all mutate cases
watch(
[PROJECT.$state],
() => {
if (EDITOR.configuration.autosave) local.onSaveProject(false)
},
{ deep: true }
)
useIntervalFn(() => {
local.onSaveProject(false)
}, 1000 * 60)
}

// tracking normalize project cases
Expand Down
18 changes: 0 additions & 18 deletions packages/better-write-app/src/use/utils.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
import destr from 'destr'

export const useUtils = () => {
const fn = () => {
const promisedFn = async (
cb: () => any,
cl: { start: () => any; end: () => any },
delayValue: number = 10
) => {
cl.start()

await delay(delayValue)
;(await cb) && (await cb())

cl.end()
}

return { promisedFn }
}

const delay = (time: number) => {
return new Promise((resolve) => setTimeout(resolve, time))
}
Expand Down Expand Up @@ -416,7 +399,6 @@ export const useUtils = () => {
}

return {
fn,
id,
position,
delay,
Expand Down
4 changes: 4 additions & 0 deletions packages/better-write-languages/src/en-US/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export default {
txt: {
generate: 'Successfully Downloaded TXT!',
},
annotations: {
fileDelete: 'Are you sure you want to delete the file?',
folderDelete: 'Are you sure you want to delete the folder?',
},
},
dropbox: {
load: 'Connected with Dropbox!',
Expand Down
4 changes: 4 additions & 0 deletions packages/better-write-languages/src/pt-BR/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export default {
html: {
generate: 'HTML Baixado com Sucesso!',
},
annotations: {
fileDelete: 'Você tem certeza que deseja deletar o arquivo?',
folderDelete: 'Você tem certeza que deseja deletar a pasta?',
},
},
dropbox: {
load: 'Conectado com o Dropbox!',
Expand Down
1 change: 0 additions & 1 deletion packages/better-write-plugin-annotations/src/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export const PluginAnnotationsSet = (
const index = stores.PROJECT.annotations.folders.indexOf(folder)

stores.PROJECT.annotations.folders[index].files.push(file)
stores.PROJECT.annotations.activeId = file.id

return file
}
Expand Down

0 comments on commit f74e028

Please sign in to comment.