🐛 (stacked notes) refacto query stacked notes in a local store

This commit is contained in:
2021-03-16 23:45:58 +01:00
parent 4b32a97699
commit 996d10b174
4 changed files with 47 additions and 40 deletions

View File

@@ -0,0 +1,30 @@
import { readonly, ref } from '@vue/reactivity'
import { useRoute } from 'vue-router'
const stackedNotes = ref<string[]>([])
let initial = true
export const useQueryStackedNotes = () => {
const { query } = useRoute()
if (initial) {
initial = false
stackedNotes.value = query.stackedNotes
? Array.isArray(query.stackedNotes)
? (query.stackedNotes
.map((n) => n?.toString())
.filter((n) => !!n) as string[])
: ([query.stackedNotes]
.map((n) => n?.toString())
.filter((n) => !!n) as string[])
: ([] as string[])
}
return {
stackedNotes: readonly(stackedNotes),
updateQueryStackedNotes: (newStackedNotes: string[]) =>
(stackedNotes.value = newStackedNotes),
resetStackedNotes: () => (stackedNotes.value = [])
}
}