(notes) add routing between notes

This commit is contained in:
2021-03-13 22:11:58 +01:00
parent 2bb43ac961
commit 8fad931dfd
12 changed files with 343 additions and 65 deletions

View File

@@ -1,7 +1,27 @@
export const useLinks = (className: string) => {
const linkNote: EventListenerOrEventListenerObject = (e) => {
e.preventDefault()
console.log('use links')
import { noteEventBus } from '@/bus/noteBusEvent'
import { onUnmounted } from '@vue/runtime-core'
const LINKS = ['http://', 'https://']
export const useLinks = (className: string, sha?: string) => {
const linkNote: EventListener = (event) => {
event.preventDefault()
const target = event.target as HTMLElement
const href = target.getAttribute('href')
if (!href) {
return
}
if (LINKS.some((link) => href.startsWith(link))) {
window.open(href, '_blank')
return
}
noteEventBus.emit({
path: href,
currentNoteSHA: sha
})
}
const selector = `.${className} a`
@@ -21,8 +41,11 @@ export const useLinks = (className: string) => {
})
}
onUnmounted(() => {
removeListeners()
})
return {
listenToClick,
removeListeners
listenToClick
}
}