Files
standardnotes-app-web/packages/web/src/javascripts/Hooks/useItemLinks.ts
Karol Sójko 325737bfbd chore: fix ContentType usage (#2353)
* chore: fix ContentType usage

* chore: fix specs
2023-07-12 13:53:29 +02:00

34 lines
1.1 KiB
TypeScript

import { useApplication } from '@/Components/ApplicationProvider'
import { useLinkingController } from '@/Controllers/LinkingControllerProvider'
import { ContentType, DecryptedItem } from '@standardnotes/snjs'
import { useEffect, useState } from 'react'
export const useItemLinks = (item: DecryptedItem | undefined) => {
const application = useApplication()
const linkingController = useLinkingController()
const { getLinkedNotesForItem, getNotesLinkingToItem, getFilesLinksForItem, getLinkedTagsForItem } = linkingController
const [, refresh] = useState(Date.now())
const notesLinkedToItem = getLinkedNotesForItem(item) || []
const notesLinkingToItem = getNotesLinkingToItem(item) || []
const { filesLinkedToItem, filesLinkingToItem } = getFilesLinksForItem(item)
const tagsLinkedToItem = getLinkedTagsForItem(item) || []
useEffect(
() =>
application.streamItems([ContentType.TYPES.Note, ContentType.TYPES.File, ContentType.TYPES.Tag], () => {
refresh(Date.now())
}),
[application],
)
return {
notesLinkedToItem,
notesLinkingToItem,
filesLinkedToItem,
filesLinkingToItem,
tagsLinkedToItem,
}
}