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 { useEffect, useState } from "preact/hooks";
|
||||||
import { TabContext } from "./ribbon-interface";
|
import { TabContext } from "./ribbon-interface";
|
||||||
import { EditedNotesResponse } from "@triliumnext/commons";
|
import { EditedNotesResponse, EditedNotes } from "@triliumnext/commons";
|
||||||
import server from "../../services/server";
|
import server from "../../services/server";
|
||||||
import { t } from "../../services/i18n";
|
import { t } from "../../services/i18n";
|
||||||
import froca from "../../services/froca";
|
import froca from "../../services/froca";
|
||||||
@ -8,12 +8,12 @@ import NoteLink from "../react/NoteLink";
|
|||||||
import { joinElements } from "../react/react_utils";
|
import { joinElements } from "../react/react_utils";
|
||||||
|
|
||||||
export default function EditedNotesTab({ note }: TabContext) {
|
export default function EditedNotesTab({ note }: TabContext) {
|
||||||
const [ editedNotes, setEditedNotes ] = useState<EditedNotesResponse>();
|
const [ editedNotes, setEditedNotes ] = useState<EditedNotes>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!note) return;
|
if (!note) return;
|
||||||
server.get<EditedNotesResponse>(`edited-notes/${note.getLabelValue("dateNote")}`).then(async editedNotes => {
|
server.get<EditedNotesResponse>(`edited-notes/${note.getLabelValue("dateNote")}`).then(async response => {
|
||||||
editedNotes = editedNotes.filter((n) => n.noteId !== note.noteId);
|
const editedNotes = response.notes.filter((n) => n.noteId !== note.noteId);
|
||||||
const noteIds = editedNotes.flatMap((n) => n.noteId);
|
const noteIds = editedNotes.flatMap((n) => n.noteId);
|
||||||
await froca.getNotes(noteIds, true); // preload all at once
|
await froca.getNotes(noteIds, true); // preload all at once
|
||||||
setEditedNotes(editedNotes);
|
setEditedNotes(editedNotes);
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import becca from "../../becca/becca.js";
|
|||||||
import type { Request } from "express";
|
import type { Request } from "express";
|
||||||
import { NotePojo } from "../../becca/becca-interface.js";
|
import { NotePojo } from "../../becca/becca-interface.js";
|
||||||
import type BNote from "../../becca/entities/bnote.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";
|
import dateUtils from "../../services/date_utils.js";
|
||||||
|
|
||||||
interface NotePath {
|
interface NotePath {
|
||||||
@ -53,14 +53,18 @@ function getEditedNotesOnDate(req: Request) {
|
|||||||
notes = notes.filter((note) => note.hasAncestor(hoistedNoteId));
|
notes = notes.filter((note) => note.hasAncestor(hoistedNoteId));
|
||||||
}
|
}
|
||||||
|
|
||||||
return notes.map((note) => {
|
const editedNotes = notes.map((note) => {
|
||||||
const notePath = getNotePathData(note);
|
const notePath = getNotePathData(note);
|
||||||
|
|
||||||
const notePojo: NotePojoWithNotePath = note.getPojo();
|
const notePojo: NotePojoWithNotePath = note.getPojo();
|
||||||
notePojo.notePath = notePath ? notePath.notePath : null;
|
notePojo.notePath = notePath ? notePath.notePath : null;
|
||||||
|
|
||||||
return notePojo;
|
return notePojo;
|
||||||
}) satisfies EditedNotesResponse;
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
notes: editedNotes,
|
||||||
|
} satisfies EditedNotesResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNotePathData(note: BNote): NotePath | undefined {
|
function getNotePathData(note: BNote): NotePath | undefined {
|
||||||
|
|||||||
@ -164,11 +164,17 @@ export type ToggleInParentResponse = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type EditedNotesResponse = {
|
export type EditedNotesResponse = {
|
||||||
|
notes: EditedNotes,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type EditedNote = {
|
||||||
noteId: string;
|
noteId: string;
|
||||||
isDeleted: boolean;
|
isDeleted: boolean;
|
||||||
title?: string;
|
title?: string;
|
||||||
notePath?: string[] | null;
|
notePath?: string[] | null;
|
||||||
}[];
|
};
|
||||||
|
|
||||||
|
export type EditedNotes = EditedNote[];
|
||||||
|
|
||||||
export interface MetadataResponse {
|
export interface MetadataResponse {
|
||||||
dateCreated: string | undefined;
|
dateCreated: string | undefined;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user