Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show due notes #23

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/constants/Note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface Note {
title: string;
createdTime: string;
updatedTime: string;
dueTime: string;
}

export default Note;
1 change: 1 addition & 0 deletions src/constants/NoteSearchTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enum NoteSearchTypes {
Created,
Modified,
Related,
Due,
}

export default NoteSearchTypes;
1 change: 1 addition & 0 deletions src/constants/Settings.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
30 changes: 30 additions & 0 deletions src/gui/NoteList/NoteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function NoteList(props: NoteListProps) {
if (message.type === MsgType.NoteChanged) {
refetchCreatedNotes();
refetchModifiedNotes();
refetchDueNotes();
refetchRelatedNotes();
refetchSelectedNote();
}
Expand Down Expand Up @@ -119,6 +120,19 @@ function NoteList(props: NoteListProps) {
enabled: noteSearchTypes.includes(NoteSearchTypes.Modified),
});

const { data: dueNotesData, refetch: refetchDueNotes } = useQuery<Note[]>({
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[]
>({
Expand Down Expand Up @@ -215,6 +229,22 @@ function NoteList(props: NoteListProps) {
/>
</>
)}

{noteSearchTypes.includes(NoteSearchTypes.Dued) && (
<>
<NoteTypeHeader>Due Notes</NoteTypeHeader>
<NoteListItems
notes={dueNotesData ?? []}
selectedNoteId={selectedNote?.id}
sortBy={sortBy}
sortDirection={sortDirection}
key={`DuedNotes:{currentDate.toISOString()}`}
primaryTextStrategy={(note) =>
`${moment(note.dueTime).format("LT")}`
}
/>
</>
)}
</ListContainer>
</>
);
Expand Down
13 changes: 9 additions & 4 deletions src/gui/hooks/useNoteSearchTypes.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand All @@ -15,6 +16,7 @@ function useNoteSearchTypes() {
SHOW_MODIFIED_NOTES,
false
);
const showDueNotes = useOnSettingsChange<boolean>(SHOW_DUE_NOTES, true);
const showRelatedNotes = useOnSettingsChange<boolean>(
SHOW_RELATED_NOTES,
false
Expand All @@ -26,6 +28,9 @@ function useNoteSearchTypes() {
if (showModifiedNotes) {
noteSearchTypes.push(NoteSearchTypes.Modified);
}
if (showDueNotes) {
noteSearchTypes.push(NoteSearchTypes.Due);
}
if (showRelatedNotes) {
noteSearchTypes.push(NoteSearchTypes.Related);
}
Expand Down
7 changes: 7 additions & 0 deletions src/handlers/GetMonthStatistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MonthStatistics from "@constants/MonthStatistics";
import {
getCreatedNotesForDay,
getModifiedNotesForDay,
getDueNotesForDay,
getRelatedNotesForDay,
} from "./GetNotesForDay";
import Note from "@constants/Note";
Expand Down Expand Up @@ -63,6 +64,12 @@ export async function getMonthModifiedNoteStatistics(
return getMonthStatistics(date, getModifiedNotesForDay);
}

export async function getMonthDueNoteStatistics(
date: moment.Moment
): Promise<MonthStatistics> {
return getMonthStatistics(date, getDueNotesForDay);
}

export async function getMonthRelatedNoteStatistics(
date: moment.Moment
): Promise<MonthStatistics> {
Expand Down
16 changes: 14 additions & 2 deletions src/handlers/GetNearestDayWithNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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}"`,
});
Expand Down
20 changes: 18 additions & 2 deletions src/handlers/GetNotesForDay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ async function getNotesForDay(date: moment.Moment, operatorTerm: string) {
let paginatedResponse: Record<string, any>;
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,
});
Expand All @@ -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.
Expand All @@ -58,7 +68,13 @@ export async function getRelatedNotesForDay(date: moment.Moment) {
let paginatedResponse: Record<string, any>;
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,
});
Expand Down
7 changes: 7 additions & 0 deletions src/handlers/PanelMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import {
import {
getMonthCreatedNoteStatistics,
getMonthModifiedNoteStatistics,
getMonthDueNoteStatistics,
getMonthRelatedNoteStatistics,
} from "./GetMonthStatistics";
import {
getCreatedNotesForDay,
getModifiedNotesForDay,
getDueNotesForDay,
getRelatedNotesForDay,
} from "./GetNotesForDay";
import NoteSearchTypes from "@constants/NoteSearchTypes";
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/handlers/Transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
}
Loading