Skip to content

Commit 7aff5d1

Browse files
committed
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
1 parent d167caa commit 7aff5d1

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

apps/client/src/widgets/ribbon/EditedNotesTab.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { useEffect, useState } from "preact/hooks";
22
import { TabContext } from "./ribbon-interface";
3-
import { EditedNotesResponse } from "@triliumnext/commons";
3+
import { EditedNotesResponse, EditedNotes } from "@triliumnext/commons";
44
import server from "../../services/server";
55
import { t } from "../../services/i18n";
66
import froca from "../../services/froca";
77
import NoteLink from "../react/NoteLink";
88
import { joinElements } from "../react/react_utils";
99

1010
export default function EditedNotesTab({ note }: TabContext) {
11-
const [ editedNotes, setEditedNotes ] = useState<EditedNotesResponse>();
11+
const [ editedNotes, setEditedNotes ] = useState<EditedNotes>();
1212

1313
useEffect(() => {
1414
if (!note) return;
15-
server.get<EditedNotesResponse>(`edited-notes/${note.getLabelValue("dateNote")}`).then(async editedNotes => {
16-
editedNotes = editedNotes.filter((n) => n.noteId !== note.noteId);
15+
server.get<EditedNotesResponse>(`edited-notes/${note.getLabelValue("dateNote")}`).then(async response => {
16+
const editedNotes = response.notes.filter((n) => n.noteId !== note.noteId);
1717
const noteIds = editedNotes.flatMap((n) => n.noteId);
1818
await froca.getNotes(noteIds, true); // preload all at once
1919
setEditedNotes(editedNotes);

apps/server/src/routes/api/edited-notes.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import becca from "../../becca/becca.js";
66
import type { Request } from "express";
77
import { NotePojo } from "../../becca/becca-interface.js";
88
import type BNote from "../../becca/entities/bnote.js";
9-
import { EditedNotesResponse } from "@triliumnext/commons";
9+
import { EditedNotes, EditedNotesResponse } from "@triliumnext/commons";
1010
import dateUtils from "../../services/date_utils.js";
1111

1212
interface NotePath {
@@ -53,14 +53,18 @@ function getEditedNotesOnDate(req: Request) {
5353
notes = notes.filter((note) => note.hasAncestor(hoistedNoteId));
5454
}
5555

56-
return notes.map((note) => {
56+
const editedNotes = notes.map((note) => {
5757
const notePath = getNotePathData(note);
5858

5959
const notePojo: NotePojoWithNotePath = note.getPojo();
6060
notePojo.notePath = notePath ? notePath.notePath : null;
6161

6262
return notePojo;
63-
}) satisfies EditedNotesResponse;
63+
});
64+
65+
return {
66+
notes: editedNotes,
67+
} satisfies EditedNotesResponse;
6468
}
6569

6670
function getNotePathData(note: BNote): NotePath | undefined {

packages/commons/src/lib/server_api.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,17 @@ export type ToggleInParentResponse = {
164164
}
165165

166166
export type EditedNotesResponse = {
167+
notes: EditedNotes,
168+
}
169+
170+
export type EditedNote = {
167171
noteId: string;
168172
isDeleted: boolean;
169173
title?: string;
170174
notePath?: string[] | null;
171-
}[];
175+
};
176+
177+
export type EditedNotes = EditedNote[];
172178

173179
export interface MetadataResponse {
174180
dateCreated: string | undefined;

0 commit comments

Comments
 (0)