🐛 (stacked notes) refacto query stacked notes in a local store
This commit is contained in:
30
src/hooks/useQueryStackedNotes.hook.ts
Normal file
30
src/hooks/useQueryStackedNotes.hook.ts
Normal 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 = [])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user