From 98922980045f97cc19336b0c886445b75520a2a4 Mon Sep 17 00:00:00 2001 From: contributor Date: Wed, 12 Nov 2025 01:14:16 +0200 Subject: [PATCH] edited notes: extendable EditedNotesResponse this allows to return additional field along with notes, for example, a flag to indicate if response was truncated by limit --- apps/client/src/widgets/ribbon/EditedNotesTab.tsx | 8 ++++---- apps/server/src/routes/api/edited-notes.ts | 10 +++++++--- packages/commons/src/lib/server_api.ts | 8 +++++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/apps/client/src/widgets/ribbon/EditedNotesTab.tsx b/apps/client/src/widgets/ribbon/EditedNotesTab.tsx index 4bdae4126..b4fd1a19e 100644 --- a/apps/client/src/widgets/ribbon/EditedNotesTab.tsx +++ b/apps/client/src/widgets/ribbon/EditedNotesTab.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from "preact/hooks"; import { TabContext } from "./ribbon-interface"; -import { EditedNotesResponse } from "@triliumnext/commons"; +import { EditedNotesResponse, EditedNotes } from "@triliumnext/commons"; import server from "../../services/server"; import { t } from "../../services/i18n"; import froca from "../../services/froca"; @@ -8,12 +8,12 @@ import NoteLink from "../react/NoteLink"; import { joinElements } from "../react/react_utils"; export default function EditedNotesTab({ note }: TabContext) { - const [ editedNotes, setEditedNotes ] = useState(); + const [ editedNotes, setEditedNotes ] = useState(); useEffect(() => { if (!note) return; - server.get(`edited-notes/${note.getLabelValue("dateNote")}`).then(async editedNotes => { - editedNotes = editedNotes.filter((n) => n.noteId !== note.noteId); + server.get(`edited-notes/${note.getLabelValue("dateNote")}`).then(async response => { + const editedNotes = response.notes.filter((n) => n.noteId !== note.noteId); const noteIds = editedNotes.flatMap((n) => n.noteId); await froca.getNotes(noteIds, true); // preload all at once setEditedNotes(editedNotes); diff --git a/apps/server/src/routes/api/edited-notes.ts b/apps/server/src/routes/api/edited-notes.ts index c1efcefc4..050956ff4 100644 --- a/apps/server/src/routes/api/edited-notes.ts +++ b/apps/server/src/routes/api/edited-notes.ts @@ -6,7 +6,7 @@ import becca from "../../becca/becca.js"; import type { Request } from "express"; import { NotePojo } from "../../becca/becca-interface.js"; import type BNote from "../../becca/entities/bnote.js"; -import { EditedNotesResponse } from "@triliumnext/commons"; +import { EditedNotes, EditedNotesResponse } from "@triliumnext/commons"; import dateUtils from "../../services/date_utils.js"; interface NotePath { @@ -53,14 +53,18 @@ function getEditedNotesOnDate(req: Request) { notes = notes.filter((note) => note.hasAncestor(hoistedNoteId)); } - return notes.map((note) => { + const editedNotes = notes.map((note) => { const notePath = getNotePathData(note); const notePojo: NotePojoWithNotePath = note.getPojo(); notePojo.notePath = notePath ? notePath.notePath : null; return notePojo; - }) satisfies EditedNotesResponse; + }); + + return { + notes: editedNotes, + } satisfies EditedNotesResponse; } function getNotePathData(note: BNote): NotePath | undefined { diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.ts index 1e79c2151..38dcc3ee4 100644 --- a/packages/commons/src/lib/server_api.ts +++ b/packages/commons/src/lib/server_api.ts @@ -164,11 +164,17 @@ export type ToggleInParentResponse = { } export type EditedNotesResponse = { + notes: EditedNotes, +} + +export type EditedNote = { noteId: string; isDeleted: boolean; title?: string; notePath?: string[] | null; -}[]; +}; + +export type EditedNotes = EditedNote[]; export interface MetadataResponse { dateCreated: string | undefined;