Skip to content
Prev Previous commit
Next Next commit
feat: expand parent folder
  • Loading branch information
antonreshetov committed Aug 14, 2022
commit 481420eac9739d57e85d6ff9759026f723ee3d29
22 changes: 22 additions & 0 deletions src/renderer/composable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export const goToSnippet = async (snippetId: string) => {

folderStore.selectId(snippet.folderId)

expandParentFolders(snippet.folderId)

snippetStore.fragment = 0

await snippetStore.getSnippetsById(snippetId)
Expand All @@ -106,6 +108,26 @@ export const goToSnippet = async (snippetId: string) => {
emitter.emit('folder:click', snippet.folderId)
}

export const expandParentFolders = (folderId: string) => {
const folderStore = useFolderStore()

const findParentAndExpand = async (id: string) => {
const folder = folderStore.folders.find(i => i.id === id)

if (!folder) return

await folderStore.patchFoldersById(folder.id, {
isOpen: true
})

if (folder.parentId) {
findParentAndExpand(folder.parentId)
}
}

findParentAndExpand(folderId)
}

export const setScrollPosition = (el: HTMLElement, offset: number) => {
const ps = el.querySelector('.ps')
if (ps) ps.scrollTop = offset
Expand Down