display links to the stacked note

This commit is contained in:
Julien Calixte
2021-06-06 10:47:36 +02:00
parent 4f13c18573
commit c6dec8769f
6 changed files with 66 additions and 12 deletions

View File

@@ -0,0 +1,36 @@
import { backlinkEventBus } from '@/bus/backlinkEventBus'
import { data } from '@/data/data'
import { DataType } from '@/data/DataType.enum'
import { BacklinkNote } from '@/modules/note/models/BacklinkNote'
import { useAsyncState } from '@vueuse/core'
import { onUnmounted } from 'vue'
export const useBacklinks = (sha: string) => {
const backlink = useAsyncState(
data.get<DataType.BacklinkNote, BacklinkNote>(
data.generateId(DataType.BacklinkNote, sha)
),
null,
{
resetOnExecute: true
}
)
const unsubscribe = backlinkEventBus.addEventBusListener(
({ fileSha }) => {
if (fileSha !== sha) {
return
}
backlink.execute()
},
{
retro: true
}
)
onUnmounted(() => unsubscribe())
return {
backlink
}
}

View File

@@ -1,3 +1,4 @@
import { backlinkEventBus } from '@/bus/backlinkEventBus'
import { data } from '@/data/data'
import { DataType } from '@/data/DataType.enum'
import { useFile } from '@/hooks/useFile.hook'
@@ -80,15 +81,7 @@ export const useComputeBacklinks = () => {
}
await data.add(backlinkNote)
backlinkEventBus.emit({ fileSha: sha })
}
const backlinksInDb = await data.getAll<
DataType.BacklinkNote,
BacklinkNote
>({
prefix: DataType.BacklinkNote
})
console.log(backlinksInDb.filter((b) => b.links.length))
})
}