(backlinks) implement backlinks in notes

This commit is contained in:
Julien Calixte
2021-06-06 11:11:15 +02:00
parent c6dec8769f
commit bff90e6ef5
7 changed files with 117 additions and 103 deletions

View File

@@ -2,19 +2,15 @@ import { computed, onMounted, onUnmounted, watch } from '@vue/runtime-core'
import { NOTE_WIDTH } from '@/constants/note-width'
import { noteEventBus } from '@/bus/noteEventBus'
import { useFocus } from '@/hooks/useFocus.hook'
import { useOverlay } from '@/hooks/useOverlay.hook'
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
import { useRouter } from 'vue-router'
import { resolvePath } from '@/modules/repo/services/resolvePath'
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
export const useNote = (containerClass: string) => {
const store = useUserRepoStore()
const { push, currentRoute } = useRouter()
const { isMobile } = useOverlay(false)
const { scrollToFocusedNote } = useFocus()
const { stackedNotes, updateQueryStackedNotes } = useQueryStackedNotes()
const { stackedNotes, addStackedNote } = useQueryStackedNotes()
const titles = computed(() =>
stackedNotes.value?.reduce((obj: Record<string, string>, note) => {
@@ -38,7 +34,7 @@ export const useNote = (containerClass: string) => {
)
const unsubscribeLink = noteEventBus.addEventBusListener(
({ user, repo, path, currentNoteSHA }) => {
({ path, currentNoteSHA }) => {
const currentFile = store.files.find(
(file) => file.sha === currentNoteSHA
)
@@ -46,47 +42,11 @@ export const useNote = (containerClass: string) => {
const finalPath = resolvePath(currentFile?.path ?? '', path)
const file = store.files.find((file) => file.path === finalPath)
if (!file?.sha || stackedNotes.value.includes(file.sha)) {
scrollToFocusedNote(file?.sha)
if (!file?.sha) {
return
}
const getStackedNotes = () => {
if (!file?.sha) {
return []
}
if (!currentNoteSHA) {
return [file.sha]
}
const [splittedStackedNotes] = stackedNotes.value
.join(';')
.split(currentNoteSHA)
return [
...splittedStackedNotes.replaceAll(';;', ';').split(';'),
currentNoteSHA,
file.sha
].filter((sha) => !!sha)
}
const newStackedNotes = getStackedNotes()
push({
name: currentRoute.value.name ?? 'Home',
params: {
user,
repo
},
query: {
stackedNotes: newStackedNotes
}
})
updateQueryStackedNotes(newStackedNotes)
scrollToFocusedNote(file.sha)
addStackedNote(currentNoteSHA ?? '', file.sha)
}
)