web: fix tags not showing in locked note (#7061)

Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
01zulfi
2024-12-10 09:58:13 +05:00
committed by GitHub
parent aa72c33aea
commit 1d78402d5d
5 changed files with 41 additions and 13 deletions

View File

@@ -231,6 +231,23 @@ test("add tags to note", async ({ page }) => {
expect(noteTags.every((t, i) => t === tags[i])).toBe(true); expect(noteTags.every((t, i) => t === tags[i])).toBe(true);
}); });
test("add tags to locked note", async ({ page }) => {
const tags = ["incognito", "secret-stuff"];
const app = new AppModel(page);
await app.goto();
const notes = await app.goToNotes();
const note = await notes.createNote(NOTE);
await note?.contextMenu.lock(PASSWORD);
await note?.openLockedNote(PASSWORD);
await notes.editor.setTags(tags);
await page.waitForTimeout(200);
const noteTags = await notes.editor.getTags();
expect(noteTags).toHaveLength(tags.length);
expect(noteTags.every((t, i) => t === tags[i])).toBe(true);
});
for (const format of ["html", "txt", "md"] as const) { for (const format of ["html", "txt", "md"] as const) {
test(`export note as ${format}`, async ({ page }) => { test(`export note as ${format}`, async ({ page }) => {
const app = new AppModel(page); const app = new AppModel(page);

View File

@@ -834,6 +834,7 @@ function UnlockNoteView(props: UnlockNoteViewProps) {
if (!note || !note.content) if (!note || !note.content)
throw new Error("note with this id does not exist."); throw new Error("note with this id does not exist.");
const tags = await db.notes.tags(note.id);
useEditorStore.getState().addSession({ useEditorStore.getState().addSession({
type: session.note.readonly ? "readonly" : "default", type: session.note.readonly ? "readonly" : "default",
locked: true, locked: true,
@@ -841,6 +842,7 @@ function UnlockNoteView(props: UnlockNoteViewProps) {
note: session.note, note: session.note,
saveState: SaveState.Saved, saveState: SaveState.Saved,
sessionId: `${Date.now()}`, sessionId: `${Date.now()}`,
tags,
pinned: session.pinned, pinned: session.pinned,
preview: session.preview, preview: session.preview,
content: note.content content: note.content

View File

@@ -421,7 +421,7 @@ class EditorStore extends BaseStore<EditorStore> {
continue; continue;
updateSession(session.id, undefined, { updateSession(session.id, undefined, {
tags: await getTags(session.note.id) tags: await db.notes.tags(session.note.id)
}); });
} }
} else if ( } else if (
@@ -432,7 +432,7 @@ class EditorStore extends BaseStore<EditorStore> {
event.item.toType === "note" event.item.toType === "note"
) { ) {
updateSession(event.item.toId, undefined, { updateSession(event.item.toId, undefined, {
tags: await getTags(event.item.toId) tags: await db.notes.tags(event.item.toId)
}); });
} }
} else if (event.collection === "tags") { } else if (event.collection === "tags") {
@@ -445,7 +445,7 @@ class EditorStore extends BaseStore<EditorStore> {
continue; continue;
console.log("UDPATE"); console.log("UDPATE");
updateSession(session.id, undefined, { updateSession(session.id, undefined, {
tags: await getTags(session.note.id) tags: await db.notes.tags(session.note.id)
}); });
} }
} }
@@ -671,7 +671,7 @@ class EditorStore extends BaseStore<EditorStore> {
const attachmentsLength = await db.attachments const attachmentsLength = await db.attachments
.ofNote(note.id, "all") .ofNote(note.id, "all")
.count(); .count();
const tags = await getTags(note.id); const tags = await db.notes.tags(note.id);
const colors = await db.relations.to(note, "color").get(); const colors = await db.relations.to(note, "color").get();
if (note.readonly) { if (note.readonly) {
this.addSession( this.addSession(
@@ -1020,12 +1020,3 @@ async function waitForSync() {
db.eventManager.subscribe(EVENTS.syncCompleted, resolve, true); db.eventManager.subscribe(EVENTS.syncCompleted, resolve, true);
}); });
} }
async function getTags(noteId: string) {
return await db.relations
.to({ id: noteId, type: "note" }, "tag")
.selector.items(undefined, {
sortBy: "dateCreated",
sortDirection: "asc"
});
}

View File

@@ -197,6 +197,15 @@ test("update note", () =>
expect(note?.favorite).toBe(true); expect(note?.favorite).toBe(true);
})); }));
test("get note tags", () =>
noteTest({
...TEST_NOTE
}).then(async ({ db, id }) => {
const tag = await db.tags.add({ title: "hello" });
await db.relations.add({ type: "tag", id: tag }, { type: "note", id });
expect(await db.notes.tags(id)).toEqual([await db.tags.tag(tag)]);
}));
test("get favorite notes", () => test("get favorite notes", () =>
noteTest({ noteTest({
...TEST_NOTE, ...TEST_NOTE,

View File

@@ -176,6 +176,15 @@ export class Notes implements ICollection {
return note; return note;
} }
async tags(id: string) {
return this.db.relations
.to({ id, type: "note" }, "tag")
.selector.items(undefined, {
sortBy: "dateCreated",
sortDirection: "asc"
});
}
// note(idOrNote: string | Note) { // note(idOrNote: string | Note) {
// if (!idOrNote) return; // if (!idOrNote) return;
// const note = // const note =