✨ (backlinks) implement backlinks in notes
This commit is contained in:
@@ -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)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user