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

Commit

Permalink
refactor: alter some logic
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Aug 3, 2023
1 parent 3acca74 commit b23fbd1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 56 deletions.
2 changes: 0 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ const treeHeight = computed(() => {
v-model:selected-keys="selectedKeysFilter"
block-line
selectable
expand-on-click
accordion
default-expand-all
:pattern="searchText"
:show-irrelevant-nodes="false"
Expand Down
53 changes: 3 additions & 50 deletions src/data.tsx → src/data.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { TreeOption } from 'naive-ui'
import { NButton, NIcon } from 'naive-ui'
import { computed, reactive } from 'vue'
import type { Task } from './types'
import { loadData } from './demo/loader'
import { AddOutlined, CreateNewFolderOutlined } from '@vicons/material'

export interface TaskData {
[task: string]: Task
Expand All @@ -19,52 +17,10 @@ function getNext(prf: string, opt: TreeOption[], key: string): TreeOption[] {
}
}

const add = (e: MouseEvent) => {
e.stopPropagation()
for (let i = 1; ; i++) {
const name = `${key}_${i}`
if (!(name in taskData.data)) {
taskData.data[name] = {
editor_info: {
path: `${prf}${key}`
}
}
return
}
}
}
const addDir = (e: MouseEvent) => {
e.stopPropagation()
}

const o: TreeOption = {
key: `${prf}${key}.`,
label: key,
children: [],
suffix: () => {
return (
<div class="flex gap-1">
<NButton text onClick={add}>
{{
icon: () => (
<NIcon>
<AddOutlined></AddOutlined>
</NIcon>
)
}}
</NButton>
<NButton text onClick={addDir}>
{{
icon: () => (
<NIcon>
<CreateNewFolderOutlined></CreateNewFolderOutlined>
</NIcon>
)
}}
</NButton>
</div>
)
}
children: []
}
opt.push(o)
return o.children!
Expand All @@ -76,11 +32,8 @@ export const taskTree = computed<TreeOption>(() => {

for (const key in taskData.data) {
const task = taskData.data[key]
const path = (task.editor_info?.path ?? 'default').split('.')
task.editor_info = {
...(task.editor_info ?? {}),
path: path.join('.')
}
const path = task.editor_info.path.split('.')

let opt = result
let prf = ''
for (const p of path) {
Expand Down
4 changes: 2 additions & 2 deletions src/demo/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { taskData, type TaskData } from '@/data'
function appendPath(data: TaskData, path: string) {
for (const key in data) {
data[key].editor_info = {
path,
...(data[key].editor_info ?? {})
...(data[key].editor_info ?? {}),
path
}
}
return data
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ export type Task = Recognition &
post_wait_freezes?: number | WaitFreezes
notify?: boolean

editor_info?: {
path?: string
editor_info: {
path: string
}
}

Expand Down

0 comments on commit b23fbd1

Please sign in to comment.