Something went wrong. Try again.
Something went wrong. Try again.
1.5 kB · 52 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import { computed, onUnmounted } from "vue"
import { noteEventBus } from "@/bus/noteEventBus"import { useRouteQueryStackedNotes } from "@/hooks/useRouteQueryStackedNotes.hook"import { resolvePath } from "@/modules/repo/services/resolvePath"import { useUserRepoStore } from "@/modules/repo/store/userRepo.store"import { pathToNotePathTitle } from "@/utils/noteTitle"import { errorMessage } from "@/utils/notif"
export const useNoteView = () => { const store = useUserRepoStore() const { stackedNotes, addStackedNote } = useRouteQueryStackedNotes()
const titles = computed(() => stackedNotes.value?.reduce((obj: Record<string, string>, note) => { if (!note) { return obj } const filePath = store.files.find((file) => file.sha === note)?.path ?? ""
obj[note] = pathToNotePathTitle(filePath)
return obj }, {}) )
const unsubscribeLink = noteEventBus.addEventBusListener( ({ path, hash, currentNoteSHA }) => { const currentFile = store.files.find( (file) => file.sha === currentNoteSHA )
const absolutePath = resolvePath(currentFile?.path ?? "", path)
const file = store.files.find((file) => file.path === absolutePath) if (!file?.sha) { errorMessage(`Note ${absolutePath} not found.`) return }
addStackedNote(currentNoteSHA ?? "", file.sha, undefined, hash) } )
onUnmounted(() => { unsubscribeLink() })
return { titles }}