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

@ -1,13 +1,19 @@
<script setup lang="ts">
import { useNotesStore } from "@/stores/notes";
import { RiArrowDownSLine, RiArrowRightSLine } from "@remixicon/vue";
import { computed, ref } from "vue";
import { computed, ref, watchEffect } from "vue";
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(() => {
if (note.value === undefined) return [];
const seen = new Map<string, number>();
@ -22,6 +28,12 @@ const children = computed(() => {
});
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>
<template>
@ -45,10 +57,10 @@ const open = ref(false);
<!-- Children -->
<div
v-if="note && open"
v-if="open && children.length > 0"
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>
</template>