From 20732eb04077e5e46ce386dba76fcaf1a4ab2705 Mon Sep 17 00:00:00 2001 From: Giacomo Rossetto Date: Fri, 8 Mar 2024 00:42:10 +0100 Subject: [PATCH] Initial work to show due notes --- src/constants/Note.ts | 1 + src/constants/NoteSearchTypes.ts | 1 + src/constants/Settings.ts | 1 + src/gui/NoteList/NoteList.tsx | 30 +++++++++++++++++++++++++++ src/gui/hooks/useNoteSearchTypes.ts | 13 ++++++++---- src/handlers/GetMonthStatistics.ts | 7 +++++++ src/handlers/GetNearestDayWithNote.ts | 16 ++++++++++++-- src/handlers/GetNotesForDay.ts | 20 ++++++++++++++++-- src/handlers/PanelMessageHandler.ts | 7 +++++++ src/handlers/Transforms.ts | 1 + 10 files changed, 89 insertions(+), 8 deletions(-) diff --git a/src/constants/Note.ts b/src/constants/Note.ts index eb10c3a..61b4ac1 100644 --- a/src/constants/Note.ts +++ b/src/constants/Note.ts @@ -6,6 +6,7 @@ interface Note { title: string; createdTime: string; updatedTime: string; + dueTime: string; } export default Note; diff --git a/src/constants/NoteSearchTypes.ts b/src/constants/NoteSearchTypes.ts index 747ebf2..e706ce2 100644 --- a/src/constants/NoteSearchTypes.ts +++ b/src/constants/NoteSearchTypes.ts @@ -5,6 +5,7 @@ enum NoteSearchTypes { Created, Modified, Related, + Due, } export default NoteSearchTypes; diff --git a/src/constants/Settings.ts b/src/constants/Settings.ts index c37d63e..a798c5a 100644 --- a/src/constants/Settings.ts +++ b/src/constants/Settings.ts @@ -1,5 +1,6 @@ export const SHOW_CALENDAR_BUTTON = "showCalendarToggleOnToolbar"; export const SHOW_MODIFIED_NOTES = "showModifiedNotes"; +export const SHOW_DUE_NOTES = "showDueNotes"; export const SHOW_RELATED_NOTES = "showRelatedNotes"; export const WEEK_START_DAY = "weekStartDay"; diff --git a/src/gui/NoteList/NoteList.tsx b/src/gui/NoteList/NoteList.tsx index 06e448c..b9ad873 100644 --- a/src/gui/NoteList/NoteList.tsx +++ b/src/gui/NoteList/NoteList.tsx @@ -84,6 +84,7 @@ function NoteList(props: NoteListProps) { if (message.type === MsgType.NoteChanged) { refetchCreatedNotes(); refetchModifiedNotes(); + refetchDueNotes(); refetchRelatedNotes(); refetchSelectedNote(); } @@ -119,6 +120,19 @@ function NoteList(props: NoteListProps) { enabled: noteSearchTypes.includes(NoteSearchTypes.Modified), }); + const { data: dueNotesData, refetch: refetchDueNotes } = useQuery({ + queryKey: ["notes", "due", currentDate.toISOString()], + queryFn: async () => { + console.debug(`Requesting notes for ${currentDate.toLocaleString()}`); + return await webviewApi.postMessage({ + type: MsgType.GetNotes, + currentDate: currentDate.toISOString(), + noteSearchTypes: [NoteSearchTypes.Due], + }); + }, + enabled: noteSearchTypes.includes(NoteSearchTypes.Due), + }); + const { data: relatedNotesData, refetch: refetchRelatedNotes } = useQuery< Note[] >({ @@ -215,6 +229,22 @@ function NoteList(props: NoteListProps) { /> )} + + {noteSearchTypes.includes(NoteSearchTypes.Dued) && ( + <> + Due Notes + + `${moment(note.dueTime).format("LT")}` + } + /> + + )} ); diff --git a/src/gui/hooks/useNoteSearchTypes.ts b/src/gui/hooks/useNoteSearchTypes.ts index a85ae2b..e3f8888 100644 --- a/src/gui/hooks/useNoteSearchTypes.ts +++ b/src/gui/hooks/useNoteSearchTypes.ts @@ -1,8 +1,9 @@ import NoteSearchTypes from "@constants/NoteSearchTypes"; -import MsgType from "@constants/messageTypes"; -import { useEffect, useState } from "react"; -import useWebviewApiOnMessage from "./useWebViewApiOnMessage"; -import { SHOW_MODIFIED_NOTES, SHOW_RELATED_NOTES } from "@constants/Settings"; +import { + SHOW_DUE_NOTES, + SHOW_MODIFIED_NOTES, + SHOW_RELATED_NOTES, +} from "@constants/Settings"; import useOnSettingsChange from "./useOnSettingsChange"; /** @@ -15,6 +16,7 @@ function useNoteSearchTypes() { SHOW_MODIFIED_NOTES, false ); + const showDueNotes = useOnSettingsChange(SHOW_DUE_NOTES, true); const showRelatedNotes = useOnSettingsChange( SHOW_RELATED_NOTES, false @@ -26,6 +28,9 @@ function useNoteSearchTypes() { if (showModifiedNotes) { noteSearchTypes.push(NoteSearchTypes.Modified); } + if (showDueNotes) { + noteSearchTypes.push(NoteSearchTypes.Due); + } if (showRelatedNotes) { noteSearchTypes.push(NoteSearchTypes.Related); } diff --git a/src/handlers/GetMonthStatistics.ts b/src/handlers/GetMonthStatistics.ts index 3ef459b..4b3ee7b 100644 --- a/src/handlers/GetMonthStatistics.ts +++ b/src/handlers/GetMonthStatistics.ts @@ -3,6 +3,7 @@ import MonthStatistics from "@constants/MonthStatistics"; import { getCreatedNotesForDay, getModifiedNotesForDay, + getDueNotesForDay, getRelatedNotesForDay, } from "./GetNotesForDay"; import Note from "@constants/Note"; @@ -63,6 +64,12 @@ export async function getMonthModifiedNoteStatistics( return getMonthStatistics(date, getModifiedNotesForDay); } +export async function getMonthDueNoteStatistics( + date: moment.Moment +): Promise { + return getMonthStatistics(date, getDueNotesForDay); +} + export async function getMonthRelatedNoteStatistics( date: moment.Moment ): Promise { diff --git a/src/handlers/GetNearestDayWithNote.ts b/src/handlers/GetNearestDayWithNote.ts index bd90cc4..247d05d 100644 --- a/src/handlers/GetNearestDayWithNote.ts +++ b/src/handlers/GetNearestDayWithNote.ts @@ -32,7 +32,13 @@ async function getNearestDayWithNote( } const response = await joplin.data.get(["search"], { - fields: ["id", "title", "user_created_time", "user_updated_time"], + fields: [ + "id", + "title", + "user_created_time", + "user_updated_time", + "due_time", + ], limit: 1, order_by: orderByTerm, order_dir: direction === "past" ? "DESC" : "ASC", @@ -114,7 +120,13 @@ export async function getNearestDayWithRelatedNote( const dateString = workingDate.format(dateFormat); const response = await joplin.data.get(["search"], { - fields: ["id", "title", "user_created_time", "user_updated_time"], + fields: [ + "id", + "title", + "user_created_time", + "user_updated_time", + "due_time", + ], limit: 1, query: `title:/"${dateString}"`, }); diff --git a/src/handlers/GetNotesForDay.ts b/src/handlers/GetNotesForDay.ts index 48d2a35..2107d4c 100644 --- a/src/handlers/GetNotesForDay.ts +++ b/src/handlers/GetNotesForDay.ts @@ -23,7 +23,13 @@ async function getNotesForDay(date: moment.Moment, operatorTerm: string) { let paginatedResponse: Record; do { paginatedResponse = await joplin.data.get(["search"], { - fields: ["id", "title", "user_created_time", "user_updated_time"], + fields: [ + "id", + "title", + "user_created_time", + "user_updated_time", + "due_time", + ], query: `${operatorTerm}:${fromDate} -${operatorTerm}:${toDate}`, page: page, }); @@ -45,6 +51,10 @@ export async function getModifiedNotesForDay(date: moment.Moment) { return getNotesForDay(date, "updated"); } +export async function getDueNotesForDay(date: moment.Moment) { + return getNotesForDay(date, "due"); +} + /** * Gets list of related notes for a specific day. * Related notes are notes that have the day in the title. @@ -58,7 +68,13 @@ export async function getRelatedNotesForDay(date: moment.Moment) { let paginatedResponse: Record; do { paginatedResponse = await joplin.data.get(["search"], { - fields: ["id", "title", "user_created_time", "user_updated_time"], + fields: [ + "id", + "title", + "user_created_time", + "user_updated_time", + "due_time", + ], query: `title:/"${dateString}"`, page: page, }); diff --git a/src/handlers/PanelMessageHandler.ts b/src/handlers/PanelMessageHandler.ts index 910e634..9cb12f8 100644 --- a/src/handlers/PanelMessageHandler.ts +++ b/src/handlers/PanelMessageHandler.ts @@ -9,11 +9,13 @@ import { import { getMonthCreatedNoteStatistics, getMonthModifiedNoteStatistics, + getMonthDueNoteStatistics, getMonthRelatedNoteStatistics, } from "./GetMonthStatistics"; import { getCreatedNotesForDay, getModifiedNotesForDay, + getDueNotesForDay, getRelatedNotesForDay, } from "./GetNotesForDay"; import NoteSearchTypes from "@constants/NoteSearchTypes"; @@ -51,6 +53,11 @@ async function handleGetNotes(message) { )) ); } + if (noteTypes.includes(NoteSearchTypes.Due)) { + notes.push( + ...(await getDueNotesForDay(moment(message.currentDate, moment.ISO_8601))) + ); + } if (noteTypes.includes(NoteSearchTypes.Related)) { notes.push( ...(await getRelatedNotesForDay( diff --git a/src/handlers/Transforms.ts b/src/handlers/Transforms.ts index 4f46e92..f14ca5b 100644 --- a/src/handlers/Transforms.ts +++ b/src/handlers/Transforms.ts @@ -20,5 +20,6 @@ export function convertEpochDateInNoteToIsoString(note: Note): Note { ...note, createdTime: moment(note.createdTime).toISOString(), updatedTime: moment(note.updatedTime).toISOString(), + dueTime: moment(note.dueTime).toISOString(), }; }