Skip to content

Commit

Permalink
Add command for toggling filter by notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
rsandz committed Jun 24, 2024
1 parent d7e8794 commit a872af1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { FILTER_NOTES_BY_NOTEBOOK } from "@constants/Settings";
import joplin from "api";

export const TOGGLE_CALENDAR_COMMAND = "toggleCalendar";
export const FILTER_BY_NOTEBOOK_COMMAND = "filterNotesByNotebook";

export async function registerCommands(panelHandle: string) {
await joplin.commands.register({
Expand All @@ -16,6 +18,22 @@ export async function registerCommands(panelHandle: string) {
},
});

await joplin.commands.register({
name: FILTER_BY_NOTEBOOK_COMMAND,
label: "Toggle Filter by Notebook",
iconName: "fas fa-filter",
execute: async () => {
const currentSetting = await joplin.settings.value(
FILTER_NOTES_BY_NOTEBOOK
);
if (currentSetting) {
await joplin.settings.setValue(FILTER_NOTES_BY_NOTEBOOK, false);
} else {
await joplin.settings.setValue(FILTER_NOTES_BY_NOTEBOOK, true);
}
},
});

joplin.views.menus.create("calendar-menu", "Calendar", [
{
label: "Toggle Calendar",
Expand Down
5 changes: 4 additions & 1 deletion src/gui/NoteList/NoteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ function NoteList(props: NoteListProps) {

useWebviewApiOnMessage((data) => {
const message = data.message;
if (message.type === MsgType.NoteChanged) {
if (
message.type === MsgType.NoteChanged ||
message.type === MsgType.SettingChanged
) {
refetchCreatedNotes();
refetchModifiedNotes();
refetchRelatedNotes();
Expand Down
8 changes: 8 additions & 0 deletions src/gui/hooks/useGetMonthStatistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useQuery } from "@tanstack/react-query";
import { Moment } from "moment";
import useSelectedNote from "./useSelectedNote";
import { useEffect, useState } from "react";
import useWebviewApiOnMessage from "./useWebViewApiOnMessage";

function useGetMonthStatistics(
month: Moment,
Expand Down Expand Up @@ -32,6 +33,13 @@ function useGetMonthStatistics(
}
});

useWebviewApiOnMessage((data) => {
const message = data.message;
if (message.type === MsgType.SettingChanged) {
refetch();
}
});

return { data, refetch };
}

Expand Down
5 changes: 4 additions & 1 deletion src/gui/hooks/useSelectedNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ function useSelectedNote() {

useWebviewApiOnMessage((data) => {
const message = data.message;
if (message.type === MsgType.NoteChanged) {
if (
message.type === MsgType.NoteChanged ||
message.type === MsgType.SettingChanged
) {
refetch();
}
});
Expand Down
4 changes: 3 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
WeekStartDay,
} from "@constants/Settings";
import { getDateFormat } from "./handlers/GlobalSettings";
import { FILTER_BY_NOTEBOOK_COMMAND } from "./commands";

const SETTINGS_SECTION_ID = "joplinCalendarSection";

Expand Down Expand Up @@ -54,7 +55,8 @@ export async function registerSettings() {
[FILTER_NOTES_BY_NOTEBOOK]: {
label: "Filter Notes by Notebook",
description: `If enabled, the note list will only show notes in the selected notebook.
Note: Selecting "All Notes" will NOT show notes from all note books, just the previously selected one.`,
Note: Selecting "All Notes" will NOT show notes from all note books, just the previously selected one.
This setting can also be toggled using the ${FILTER_BY_NOTEBOOK_COMMAND} command.`,
public: true,
type: SettingItemType.Bool,
value: false,
Expand Down

0 comments on commit a872af1

Please sign in to comment.