feat(views/calendar): filter notes by ancestor

This commit is contained in:
Elian Doran 2025-02-22 11:31:26 +02:00
parent a4a2e55415
commit 63584c153c
No known key found for this signature in database
2 changed files with 19 additions and 4 deletions

View File

@ -238,7 +238,7 @@ export default class CalendarView extends ViewMode {
let allDateNoteIds: string[] = []; let allDateNoteIds: string[] = [];
for (const month of dateRange) { for (const month of dateRange) {
// TODO: Deduplicate get type. // TODO: Deduplicate get type.
const dateNotesForMonth = await server.get<Record<string, string>>(`special-notes/notes-for-month/${month}`); const dateNotesForMonth = await server.get<Record<string, string>>(`special-notes/notes-for-month/${month}?calendarRoot=${this.parentNote.noteId}`);
const dateNoteIds = Object.values(dateNotesForMonth); const dateNoteIds = Object.values(dateNotesForMonth);
allDateNoteIds = [ ...allDateNoteIds, ...dateNoteIds ]; allDateNoteIds = [ ...allDateNoteIds, ...dateNoteIds ];
} }

View File

@ -29,8 +29,8 @@ function getYearNote(req: Request) {
function getDayNotesForMonth(req: Request) { function getDayNotesForMonth(req: Request) {
const month = req.params.month; const month = req.params.month;
const calendarRoot = req.query.calendarRoot;
return sql.getMap(` const query = `\
SELECT SELECT
attr.value AS date, attr.value AS date,
notes.noteId notes.noteId
@ -40,7 +40,22 @@ function getDayNotesForMonth(req: Request) {
AND attr.isDeleted = 0 AND attr.isDeleted = 0
AND attr.type = 'label' AND attr.type = 'label'
AND attr.name = 'dateNote' AND attr.name = 'dateNote'
AND attr.value LIKE '${month}%'`); AND attr.value LIKE '${month}%'`;
if (calendarRoot) {
const rows = sql.getRows<{ date: string, noteId: string }>(query);
const result: Record<string, string> = {};
for (const {date, noteId} of rows) {
const note = becca.getNote(noteId);
if (note?.hasAncestor(String(calendarRoot))) {
result[date] = noteId;
}
}
return result;
} else {
return sql.getMap(query);
}
} }
function saveSqlConsole(req: Request) { function saveSqlConsole(req: Request) {