Skip to content
This repository has been archived by the owner on Jul 12, 2021. It is now read-only.

Commit

Permalink
Add "Go to Today" menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmeuli committed Jan 24, 2020
1 parent 9f23d8d commit 15d57d2
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/main/i18n/translations/de.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Translations } from "../../../shared/types";

// prettier-ignore
const translationsDe: Partial<Translations> = {
const translationsDe: Translations = {
// Menu (defined by macOS)
"about-app": "Über {appName}",
"bring-all-to-front": "Alle nach vorne bringen",
Expand Down Expand Up @@ -32,6 +32,7 @@ const translationsDe: Partial<Translations> = {
"export": "Exportieren",
"export-to-format": "Als {format} exportieren",
"go-to-date": "Zu Datum gehen",
"go-to-today": "Heute anzeigen",
"import": "Importieren",
"import-from-format": "Von {format} importieren",
"license": "Lizenz",
Expand Down
1 change: 1 addition & 0 deletions src/main/i18n/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const translationsEn: Translations = {
"export": "Export",
"export-to-format": "Export to {format}",
"go-to-date": "Go to Date",
"go-to-today": "Go to Today",
"import": "Import",
"import-from-format": "Import from {format}",
"license": "License",
Expand Down
4 changes: 4 additions & 0 deletions src/main/ipcMain/senders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export const setDaySelectedPrevious = (): void => {
getWindow().webContents.send("previousDay");
};

export const setDaySelectedToday = (): void => {
getWindow().webContents.send("goToToday");
};

export const setMonthSelectedNext = (): void => {
getWindow().webContents.send("nextMonth");
};
Expand Down
1 change: 1 addition & 0 deletions src/main/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const DISABLED_MENU_ITEMS = [
"exportPdf",
"exportTxtDayOne",
"goToDate",
"goToToday",
"importJsonDayOne",
"importJsonJrnl",
"importJsonMiniDiary",
Expand Down
8 changes: 8 additions & 0 deletions src/main/menu/menus/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { translate } from "../../i18n/i18n";
import {
setDaySelectedNext,
setDaySelectedPrevious,
setDaySelectedToday,
setMonthSelectedNext,
setMonthSelectedPrevious,
openOverlay,
Expand All @@ -13,6 +14,13 @@ export default function getViewMenu(): MenuItemConstructorOptions {
return {
label: translate("view"),
submenu: [
{
label: `${translate("go-to-today")}`,
id: "goToToday",
click(): void {
setDaySelectedToday();
},
},
{
label: `${translate("go-to-date")}…`,
id: "goToDate",
Expand Down
9 changes: 6 additions & 3 deletions src/renderer/electron/ipcRenderer/listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { openOverlay, setTheme } from "../../store/app/actionCreators";
import {
setDateSelectedPrevious,
setDaySelectedNext,
setDaySelectedToday,
setMonthSelectedNext,
setMonthSelectedPrevious,
} from "../../store/diary/actionCreators";
Expand All @@ -21,7 +22,7 @@ import store, { ThunkDispatchT } from "../../store/store";

const dispatchThunk = store.dispatch as ThunkDispatchT;

function initIpcListeners(): void {
export default function initIpcListeners(): void {
// Date

ipcRenderer.on("nextDay", (): void => {
Expand All @@ -32,6 +33,10 @@ function initIpcListeners(): void {
dispatchThunk(setMonthSelectedNext());
});

ipcRenderer.on("goToToday", (): void => {
dispatchThunk(setDaySelectedToday());
});

ipcRenderer.on("previousDay", (): void => {
dispatchThunk(setDateSelectedPrevious());
});
Expand Down Expand Up @@ -108,5 +113,3 @@ function initIpcListeners(): void {
dispatchThunk(setTheme(darkMode.isEnabled ? "dark" : "light"));
});
}

export default initIpcListeners;
5 changes: 5 additions & 0 deletions src/renderer/store/diary/actionCreators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export const setDateSelectedPrevious = (): ThunkActionT => (dispatch, getState):
dispatch(setDateSelected(previousDay.toDate()));
};

export const setDaySelectedToday = (): ThunkActionT => (dispatch): void => {
const today = new Date();
dispatch(setDateSelected(today));
};

export const setMonthSelectedNext = (): ThunkActionT => (dispatch, getState): void => {
const { app, diary } = getState();
const { allowFutureEntries } = app;
Expand Down
1 change: 1 addition & 0 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface Translations {
"export": string,
"export-to-format": string,
"go-to-date": string,
"go-to-today": string,
"import": string,
"import-from-format": string,
"license": string,
Expand Down

0 comments on commit 15d57d2

Please sign in to comment.