Skip to content

Commit dfb3ca9

Browse files
committed
refactor(tree): separate build tree by feature
1 parent d2f2d88 commit dfb3ca9

File tree

5 files changed

+27
-112
lines changed

5 files changed

+27
-112
lines changed

src/app/src/composables/useDraftDocuments.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const useDraftDocuments = createSharedComposable((host: StudioHost, git:
5454

5555
list.value.push(item)
5656

57-
await hooks.callHook('studio:draft:updated')
57+
await hooks.callHook('studio:draft:document:updated')
5858

5959
return item
6060
}
@@ -81,7 +81,7 @@ export const useDraftDocuments = createSharedComposable((host: StudioHost, git:
8181

8282
// Trigger hook to warn that draft list has changed
8383
if (existingItem.status !== oldStatus) {
84-
await hooks.callHook('studio:draft:updated')
84+
await hooks.callHook('studio:draft:document:updated')
8585
}
8686

8787
return existingItem
@@ -150,7 +150,7 @@ export const useDraftDocuments = createSharedComposable((host: StudioHost, git:
150150
await storage.setItem(id, existingItem)
151151
}
152152

153-
await hooks.callHook('studio:draft:updated')
153+
await hooks.callHook('studio:draft:document:updated')
154154

155155
host.app.requestRerender()
156156
}
@@ -195,7 +195,7 @@ export const useDraftDocuments = createSharedComposable((host: StudioHost, git:
195195

196196
host.app.requestRerender()
197197

198-
await hooks.callHook('studio:draft:updated')
198+
await hooks.callHook('studio:draft:document:updated')
199199
}
200200

201201
function select(draftItem: DraftItem<DatabaseItem> | null) {

src/app/src/composables/useDraftMedias.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const useDraftMedias = createSharedComposable((host: StudioHost, git: Ret
4747

4848
list.value.push(item)
4949

50-
await hooks.callHook('studio:draft:updated')
50+
await hooks.callHook('studio:draft:media:updated')
5151

5252
return item
5353
}
@@ -74,7 +74,7 @@ export const useDraftMedias = createSharedComposable((host: StudioHost, git: Ret
7474

7575
// Trigger hook to warn that draft list has changed
7676
if (existingItem.status !== oldStatus) {
77-
await hooks.callHook('studio:draft:updated')
77+
await hooks.callHook('studio:draft:media:updated')
7878
}
7979

8080
return existingItem
@@ -130,7 +130,7 @@ export const useDraftMedias = createSharedComposable((host: StudioHost, git: Ret
130130
await storage.setItem(id, existingItem)
131131
}
132132

133-
await hooks.callHook('studio:draft:updated')
133+
await hooks.callHook('studio:draft:media:updated')
134134

135135
host.app.requestRerender()
136136
}
@@ -175,12 +175,11 @@ export const useDraftMedias = createSharedComposable((host: StudioHost, git: Ret
175175

176176
host.app.requestRerender()
177177

178-
await hooks.callHook('studio:draft:updated')
178+
await hooks.callHook('studio:draft:media:updated')
179179
}
180180

181181
function select(draftItem: DraftItem | null) {
182182
current.value = draftItem
183-
console.log('select', draftItem)
184183
}
185184

186185
async function selectById(id: string) {

src/app/src/composables/useMediaTree.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/app/src/composables/useStudio.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export const useStudio = createSharedComposable(() => {
3232

3333
host.on.mounted(async () => {
3434
await draftDocuments.load()
35+
await draftMedias.load()
36+
3537
host.app.requestRerender()
3638
isReady.value = true
3739

src/app/src/composables/useTree.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,31 @@ export const useTree = (type: StudioFeature, host: StudioHost, draft: ReturnType
6767
select(treeItem)
6868
}
6969

70-
hooks.hook('studio:draft:updated', async () => {
71-
const hostList = type === 'content' ? host.document : host.media
72-
const hostGetFileSystemPath = type === 'content' ? host.document.getFileSystemPath : host.media.getFileSystemPath
73-
const list = await hostList.list()
74-
70+
async function handleDraftUpdate() {
71+
const api = type === StudioFeature.Content ? host.document : host.media
72+
const list = await api.list()
7573
const listWithFsPath = list.map((item) => {
76-
const fsPath = hostGetFileSystemPath(item.id)
77-
return {
78-
...item,
79-
fsPath,
80-
}
74+
const fsPath = api.getFileSystemPath(item.id)
75+
return { ...item, fsPath }
8176
})
8277

8378
// Trigger tree rebuild to update files status
8479
tree.value = buildTree(listWithFsPath, draft.list.value)
8580

8681
// Reselect current item to update status
8782
select(findItemFromId(tree.value, currentItem.value.id)!)
83+
}
84+
85+
hooks.hook('studio:draft:document:updated', async () => {
86+
if (type !== StudioFeature.Content) return
87+
88+
await handleDraftUpdate()
89+
})
90+
91+
hooks.hook('studio:draft:media:updated', async () => {
92+
if (type !== StudioFeature.Media) return
93+
94+
await handleDraftUpdate()
8895
})
8996

9097
return {

0 commit comments

Comments
 (0)