mirror of
https://github.com/zadam/trilium.git
synced 2025-12-04 22:44:25 +01:00
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:
parent
bcb8f29494
commit
9892298004
@ -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);
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user