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
This commit is contained in:
contributor 2025-11-12 01:14:16 +02:00
parent bcb8f29494
commit 9892298004
3 changed files with 18 additions and 8 deletions

View File

@ -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<EditedNotesResponse>();
const [ editedNotes, setEditedNotes ] = useState<EditedNotes>();
useEffect(() => {
if (!note) return;
server.get<EditedNotesResponse>(`edited-notes/${note.getLabelValue("dateNote")}`).then(async editedNotes => {
editedNotes = editedNotes.filter((n) => n.noteId !== note.noteId);
server.get<EditedNotesResponse>(`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);

View File

@ -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 {

View File

@ -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;