Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
refactor: clean old fs
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Aug 9, 2023
1 parent 8bb9ecb commit 9d010f6
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 671 deletions.
9 changes: 4 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ import { produce } from 'immer'
import { NButton, NCard, NIcon } from 'naive-ui'
import { onMounted, ref } from 'vue'
import { active } from './data'
import { getTask, setTask } from './data/task'
import { history } from './history'
import { loadFS, saveFS } from './loader'
import { fs } from '@/filesystem'
import { active, getTask, history, setTask } from '@/data'
import { type PathKey, fs } from '@/filesystem'
import TaskEdit from '@/components/TaskEdit.vue'
import TaskTree from '@/components/TaskTree.vue'
const expands = ref<string[]>(['/'])
const expands = ref<PathKey[]>(['/' as PathKey])
onMounted(async () => {
await loadFS()
Expand Down Expand Up @@ -119,3 +117,4 @@ onMounted(async () => {
</div>
</div>
</template>
./data/history
18 changes: 9 additions & 9 deletions src/components/TaskEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import {
} from 'naive-ui'
import { computed, ref } from 'vue'
import { commitDelete, commitDuplicate, commitMove, navigate } from '@/data'
import { deleteTask, duplicateTask, moveTask, navigate } from '@/data'
import { taskBackwardIndex, taskIndex } from '@/data/task'
import { Util } from '@/fs'
import { type PathKey, path } from '@/filesystem'
import type { UseProducer } from '@/persis'
import type { Task } from '@/types'
Expand All @@ -35,13 +35,13 @@ import SingleNavigateEdit from '@/components/task/SingleNavigateEdit.vue'
import FormLayout from '@/layout/FormLayout.vue'
const props = defineProps<{
name: string
name: PathKey
value: Task
edit: UseProducer<Task>
}>()
const hash = computed(() => {
const [, , hash] = Util.pathdiv(props.name)
const [, , hash] = path.divide(props.name)
return hash!
})
Expand All @@ -58,14 +58,14 @@ function tryRename() {
return
}
showRename.value = false
const [dir, file] = Util.pathdiv(props.name)
const into = Util.pathjoin(dir, file, titleCache.value)
commitMove(props.name, into)
const [dir, file] = path.divide(props.name)
const into = path.joinkey(dir, file, titleCache.value)
moveTask(props.name, into)
navigate(into)
}
function tryDuplicate() {
commitDuplicate(props.name)
duplicateTask(props.name)
}
const showDelete = ref(false)
Expand All @@ -84,7 +84,7 @@ function tryDelete() {
return
}
showDelete.value = false
commitDelete(
deleteTask(
props.name,
doTransfer.value ? taskIndex.value[transferTo.value] : null
)
Expand Down
5 changes: 2 additions & 3 deletions src/components/TaskTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { computed, ref } from 'vue'
import { renderLabel, renderPrefix, renderSuffix } from './TaskTreeRender'
import { active, navigate } from '@/data'
import { filesystemTree } from '@/data/index'
import { active, filesystemTree, navigate } from '@/data'
import { type PathKey, path } from '@/filesystem'
const expand = defineModel<string[]>('expand', {
const expand = defineModel<PathKey[]>('expand', {
required: true
})
Expand Down
62 changes: 27 additions & 35 deletions src/components/TaskTreeRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ import {
} from 'naive-ui'
import { computed, ref } from 'vue'

import { commitDelete } from '@/data'
import { fs } from '@/data/fs'
import { setTask, taskIndex } from '@/data/task'
import { Util } from '@/fs'
import { deleteTask, setTask, taskIndex } from '@/data'
import { type PathKey, fs, path } from '@/filesystem'

export function renderLabel({ option }: { option: TreeOption }) {
const key = option.key as string
const key = option.key as PathKey

if (!key.endsWith('/')) {
const [dir, file, hash] = Util.pathdiv(key)
if (!path.key_is_dir(key)) {
const [dir, file, hash] = path.divide(key)
if (hash) {
return <span>{hash}</span>
} else {
Expand All @@ -42,7 +40,7 @@ export function renderLabel({ option }: { option: TreeOption }) {
}

export function renderPrefix({ option }: { option: TreeOption }) {
const key = option.key as string
const key = option.key as PathKey

if (key.endsWith('/')) {
return (
Expand All @@ -51,7 +49,7 @@ export function renderPrefix({ option }: { option: TreeOption }) {
</NIcon>
)
} else {
const [dir, file, hash] = Util.pathdiv(key)
const [dir, file, hash] = path.divide(key)
if (hash) {
return (
<NIcon>
Expand All @@ -77,8 +75,8 @@ export function renderPrefix({ option }: { option: TreeOption }) {
export function renderSuffix({ option }: { option: TreeOption }) {
const dialog = useDialog()

const key = option.key as string
if (key.endsWith('/')) {
const key = option.key as PathKey
if (path.key_is_dir(key)) {
return (
<div class="flex gap-2 mr-2">
<NButton
Expand All @@ -90,9 +88,9 @@ export function renderSuffix({ option }: { option: TreeOption }) {
const nameWithSfx = computed(() =>
name.value.endsWith('.json') ? name.value : `${name.value}.json`
)
const path = computed(() => Util.pathjoin(key, nameWithSfx.value))
const dir = fs.tree.traceDir(fs.tree.root, key)
const pathExists = computed(() => {
return !!fs.now().value?.getFile(path.value)
return !!fs.tree.traceFile(dir, nameWithSfx.value)
})
const dlg = dialog.create({
title: '创建json',
Expand All @@ -108,13 +106,7 @@ export function renderSuffix({ option }: { option: TreeOption }) {
disabled={!name.value || pathExists.value}
onClick={() => {
if (!pathExists.value) {
fs.change(draft => {
draft?.addTextFileViaEntry(
draft.trace(key)!,
nameWithSfx.value,
'{}'
)
})
fs.tree.traceFile(dir, nameWithSfx.value, '{}')
dlg.destroy()
}
}}
Expand All @@ -139,10 +131,11 @@ export function renderSuffix({ option }: { option: TreeOption }) {
e.stopPropagation()

const name = ref<string>('')
const path = computed(() => Util.pathjoin(key, name.value))
const p = computed(() => path.join(key, name.value))
const pathExists = computed(() => {
return !!fs.now().value?.trace(path.value)
return !!fs.tree.traceDir(fs.tree.root, p.value)
})

const dlg = dialog.create({
title: '创建目录',
content: () => (
Expand All @@ -157,9 +150,7 @@ export function renderSuffix({ option }: { option: TreeOption }) {
disabled={pathExists.value}
onClick={() => {
if (!pathExists.value) {
fs.change(draft => {
draft?.trace(path.value, true)
})
fs.tree.traceDir(fs.tree.root, p.value, true)
dlg.destroy()
}
}}
Expand All @@ -181,7 +172,7 @@ export function renderSuffix({ option }: { option: TreeOption }) {
</div>
)
} else {
const [dir, file, hash] = Util.pathdiv(key)
const [dir, file, hash] = path.divide(key)
if (!hash) {
const isJson = file.endsWith('.json')
return (
Expand All @@ -197,7 +188,7 @@ export function renderSuffix({ option }: { option: TreeOption }) {
if (name in taskIndex.value) {
continue
}
setTask(Util.pathjoin(dir, file, name), {})
setTask(path.joinkey(dir, file, name), {})
break
}
}}
Expand Down Expand Up @@ -245,21 +236,22 @@ export function renderSuffix({ option }: { option: TreeOption }) {
},
positiveText: '是',
onPositiveClick: () => {
const path = Util.pathjoin(dir, file)
const p = path.joinkey(dir, file)

fs.enterBlock()
fs.history.pause()

const d = fs.tree.traceDir(fs.tree.root, dir)
const obj = JSON.parse(
fs.now().value?.getFile(path)?.data ?? '{}'
fs.tree.traceFile(d, file)?.value ?? '{}'
)
for (const name in obj) {
commitDelete(taskIndex.value[name], null)
deleteTask(taskIndex.value[name], null)
}
fs.change(draft => {
draft!.removeFile(path)
})

fs.leaveBlock()
fs.tree.delFile(d, file)

fs.history.resume()
fs.history.commit()
}
})
}}
Expand Down
10 changes: 6 additions & 4 deletions src/components/atomic/ImageHover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { NAvatar, NPopover } from 'naive-ui'
import { computed } from 'vue'
import { fs } from '@/data/fs'
import { FS } from '@/fs'
import { type Path, fs, path, pool } from '@/filesystem'
const props = defineProps<{
url: string | string[]
Expand All @@ -12,9 +11,12 @@ const props = defineProps<{
function makeUrl(v: string | null) {
const fallback = '/favicon-32x32.png'
if (v && v.endsWith('.png')) {
const hash = fs.now().value?.getFile(v)?.ref
// TODO: maybe check?
const [dir, file] = path.divide(v as Path)
const hash = fs.tree.traceBinary(fs.tree.traceDir(fs.tree.root, dir), file)
?.value
if (hash) {
const url = FS.getBufferUrl(hash)
const url = pool.query(hash)
if (url) {
return url
}
Expand Down
124 changes: 0 additions & 124 deletions src/data.ts

This file was deleted.

Loading

0 comments on commit 9d010f6

Please sign in to comment.