🐛 (flux) listen to click day 1

This commit is contained in:
2021-03-24 21:33:21 +01:00
parent e199c68d68
commit 55faf04d4f
5 changed files with 32 additions and 12 deletions

View File

@@ -1,6 +1,8 @@
import { createEventBus } from 'retrobus' import { createEventBus } from 'retrobus'
interface EventBusParams { interface EventBusParams {
user: string
repo: string
path: string path: string
currentNoteSHA?: string currentNoteSHA?: string
} }

View File

@@ -39,6 +39,7 @@ import {
computed, computed,
watch, watch,
nextTick, nextTick,
toRefs,
onUnmounted onUnmounted
} from 'vue' } from 'vue'
import HeaderNote from '@/components/HeaderNote.vue' import HeaderNote from '@/components/HeaderNote.vue'
@@ -63,6 +64,7 @@ export default defineComponent({
content: { type: String, required: false, default: null } content: { type: String, required: false, default: null }
}, },
setup(props) { setup(props) {
const refProps = toRefs(props)
const store = useUserRepoStore() const store = useUserRepoStore()
const { renderString } = useMarkdown() const { renderString } = useMarkdown()
const { listenToClick } = useLinks('note-display') const { listenToClick } = useLinks('note-display')
@@ -76,18 +78,26 @@ export default defineComponent({
const hasContent = computed(() => !!renderedContent.value) const hasContent = computed(() => !!renderedContent.value)
watch(renderedContent, () => watch(
nextTick(() => { renderedContent,
console.log(renderedContent) () =>
nextTick(() => {
listenToClick() listenToClick()
}) }),
{ immediate: true }
) )
store.setUserRepo(props.user, props.repo) watch(
[refProps.user, refProps.repo],
() => {
store.setUserRepo(props.user, props.repo)
},
{ immediate: true }
)
onUnmounted(() => { onUnmounted(() => {
store.resetUserRepo() store.resetFiles()
resetStackedNotes()
}) })
return { return {

View File

@@ -1,9 +1,12 @@
import { noteEventBus } from '@/bus/noteBusEvent' import { noteEventBus } from '@/bus/noteBusEvent'
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
import { onUnmounted } from '@vue/runtime-core' import { onUnmounted } from '@vue/runtime-core'
const LINKS = ['http://', 'https://'] const LINKS = ['http://', 'https://']
export const useLinks = (className: string, sha?: string) => { export const useLinks = (className: string, sha?: string) => {
const store = useUserRepoStore()
const linkNote: EventListener = (event) => { const linkNote: EventListener = (event) => {
event.preventDefault() event.preventDefault()
const target = event.target as HTMLElement const target = event.target as HTMLElement
@@ -20,7 +23,9 @@ export const useLinks = (className: string, sha?: string) => {
noteEventBus.emit({ noteEventBus.emit({
path: href, path: href,
currentNoteSHA: sha currentNoteSHA: sha,
user: store.user,
repo: store.repo
}) })
} }

View File

@@ -38,7 +38,7 @@ export const useNote = (containerClass: string) => {
) )
const unsubscribeLink = noteEventBus.addEventBusListener( const unsubscribeLink = noteEventBus.addEventBusListener(
({ path, currentNoteSHA }) => { ({ user, repo, path, currentNoteSHA }) => {
const currentFile = store.files.find( const currentFile = store.files.find(
(file) => file.sha === currentNoteSHA (file) => file.sha === currentNoteSHA
) )
@@ -77,8 +77,8 @@ export const useNote = (containerClass: string) => {
push({ push({
name: currentRoute.value.name ?? 'Home', name: currentRoute.value.name ?? 'Home',
params: { params: {
user: store.user, user,
repo: store.repo repo
}, },
query: { query: {
stackedNotes: newStackedNotes stackedNotes: newStackedNotes

View File

@@ -32,6 +32,9 @@ export const useUserRepoStore = defineStore({
resetUserRepo() { resetUserRepo() {
this.user = '' this.user = ''
this.repo = '' this.repo = ''
this.resetFiles()
},
resetFiles() {
this.files = [] this.files = []
this.readme = null this.readme = null
} }