Skip to content

Build your personal knowledge base with Trilium Notes

fix(calendar): wrong parent when creating day note from unhoisted workspace calendar root

Elian Doranb8a6cf0099e7
diff --git a/apps/client/src/services/date_notes.ts b/apps/client/src/services/date_notes.ts
index 340ebf7f8c..21709b1bb0 100644
--- a/apps/client/src/services/date_notes.ts
+++ b/apps/client/src/services/date_notes.ts
@@ -1,4 +1,5 @@
import { dayjs } from "@triliumnext/commons";
+
import type { FNoteRow } from "../entities/fnote.js";
import froca from "./froca.js";
import server from "./server.js";
@@ -14,8 +15,13 @@ async function getTodayNote() {
return await getDayNote(dayjs().format("YYYY-MM-DD"));
}
-async function getDayNote(date: string) {
- const note = await server.get<FNoteRow>(`special-notes/days/${date}`, "date-note");
+async function getDayNote(date: string, calendarRootId?: string) {
+ let url = `special-notes/days/${date}`;
+ if (calendarRootId) {
+ url += `?calendarRootId=${calendarRootId}`;
+ }
+
+ const note = await server.get<FNoteRow>(url, "date-note");
await ws.waitForMaxKnownEntityChangeId();
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index a8e7d17259..2a389a380d 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -307,11 +307,11 @@ function useEditing(note: FNote, isEditable: boolean, isCalendarRoot: boolean, c
// Called upon when clicking the day number in the calendar, opens or creates the day note but only if in a calendar root.
const onDateClick = useCallback(async (e: DateClickArg) => {
- const eventNote = await date_notes.getDayNote(e.dateStr);
+ const eventNote = await date_notes.getDayNote(e.dateStr, note.noteId);
if (eventNote) {
appContext.triggerCommand("openInPopup", { noteIdOrPath: eventNote.noteId });
}
- }, []);
+ }, [ note ]);
return {
select: onCalendarSelection,
diff --git a/apps/server/src/routes/api/special_notes.ts b/apps/server/src/routes/api/special_notes.ts
index 2c87e80984..8478ccad73 100644
--- a/apps/server/src/routes/api/special_notes.ts
+++ b/apps/server/src/routes/api/special_notes.ts
@@ -1,16 +1,19 @@
-import dateNoteService from "../../services/date_notes.js";
-import sql from "../../services/sql.js";
+import type { Request } from "express";
+
+import becca from "../../becca/becca.js";
import cls from "../../services/cls.js";
+import dateNoteService from "../../services/date_notes.js";
import specialNotesService, { type LauncherType } from "../../services/special_notes.js";
-import becca from "../../becca/becca.js";
-import type { Request } from "express";
+import sql from "../../services/sql.js";
function getInboxNote(req: Request) {
return specialNotesService.getInboxNote(req.params.date);
}
function getDayNote(req: Request) {
- return dateNoteService.getDayNote(req.params.date);
+ const calendarRootId = req.query.calendarRootId;
+ const calendarRoot = calendarRootId ? becca.getNoteOrThrow(String(calendarRootId)) : null;
+ return dateNoteService.getDayNote(req.params.date, calendarRoot);
}
function getWeekFirstDayNote(req: Request) {
@@ -59,9 +62,8 @@ function getDayNotesForMonth(req: Request) {
}
return result;
- } else {
- return sql.getMap(query);
}
+ return sql.getMap(query);
}
async function saveSqlConsole(req: Request) {