Add forceOpen prop to CNote

This commit is contained in:
Joscha 2025-02-05 20:07:56 +01:00
parent 89c0396778
commit af99414d6a
2 changed files with 18 additions and 6 deletions

View file

@ -10,7 +10,7 @@ const ui = useUiStore();
<div class="flex h-screen touch-pan-x touch-pan-y flex-col"> <div class="flex h-screen touch-pan-x touch-pan-y flex-col">
<CNavbar /> <CNavbar />
<div class="h-full overflow-auto px-2 py-1"> <div class="h-full overflow-auto px-2 py-1">
<CNote :id="ui.anchor" /> <CNote :noteId="ui.anchor" />
</div> </div>
</div> </div>
</template> </template>

View file

@ -1,13 +1,19 @@
<script setup lang="ts"> <script setup lang="ts">
import { useNotesStore } from "@/stores/notes"; import { useNotesStore } from "@/stores/notes";
import { RiArrowDownSLine, RiArrowRightSLine } from "@remixicon/vue"; import { RiArrowDownSLine, RiArrowRightSLine } from "@remixicon/vue";
import { computed, ref } from "vue"; import { computed, ref, watchEffect } from "vue";
const { notes } = useNotesStore(); const { notes } = useNotesStore();
const props = defineProps<{ id: string | undefined }>(); const props = defineProps<{
noteId?: string;
forceOpen?: boolean;
}>();
const note = computed(() =>
props.noteId ? notes.get(props.noteId) : undefined,
);
const note = computed(() => (props.id ? notes.get(props.id) : undefined));
const children = computed(() => { const children = computed(() => {
if (note.value === undefined) return []; if (note.value === undefined) return [];
const seen = new Map<string, number>(); const seen = new Map<string, number>();
@ -22,6 +28,12 @@ const children = computed(() => {
}); });
const open = ref(false); const open = ref(false);
// We want to set open to true when forced, but then it should stay true. Hence
// a computed() combining open and forceOpen would not suffice.
watchEffect(() => {
if (props.forceOpen) open.value = true;
});
</script> </script>
<template> <template>
@ -45,10 +57,10 @@ const open = ref(false);
<!-- Children --> <!-- Children -->
<div <div
v-if="note && open" v-if="open && children.length > 0"
class="flex flex-col border-l border-neutral-300 pl-3" class="flex flex-col border-l border-neutral-300 pl-3"
> >
<CNote v-for="[id, key] in children" :id :key></CNote> <CNote v-for="[noteId, key] in children" :key :note-id />
</div> </div>
</div> </div>
</template> </template>