Render notes from store
This commit is contained in:
parent
6fb900fe4b
commit
bb665d3b7d
6 changed files with 114 additions and 21 deletions
37
gdn-app/src/stores/notes.ts
Normal file
37
gdn-app/src/stores/notes.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
|
||||
type Note = {
|
||||
id: string;
|
||||
text: string;
|
||||
children: string[];
|
||||
};
|
||||
|
||||
export const useNotesStore = defineStore("notes", () => {
|
||||
const notes = ref<Map<string, Note>>(new Map());
|
||||
|
||||
function addNote(text: string): Note {
|
||||
const id = crypto.randomUUID();
|
||||
notes.value.set(id, { id, text, children: [] });
|
||||
return notes.value.get(id)!; // Re-getting so returned Note is reactive
|
||||
}
|
||||
|
||||
function appendChildNote(parentId: string, text: string): Note | undefined {
|
||||
const parent = notes.value.get(parentId);
|
||||
if (parent === undefined) return undefined;
|
||||
const note = addNote(text);
|
||||
parent.children.push(note.id);
|
||||
return note;
|
||||
}
|
||||
|
||||
function clearNotes() {
|
||||
notes.value.clear();
|
||||
}
|
||||
|
||||
return {
|
||||
notes,
|
||||
addNote,
|
||||
appendChildNote,
|
||||
clearNotes,
|
||||
};
|
||||
});
|
||||
10
gdn-app/src/stores/ui.ts
Normal file
10
gdn-app/src/stores/ui.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
|
||||
export const useUiStore = defineStore("ui", () => {
|
||||
const anchor = ref<string>();
|
||||
|
||||
return {
|
||||
anchor,
|
||||
};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue