forked from samuelmeuli/mini-diary
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
117 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { MenuItemConstructorOptions } from "electron"; | ||
|
||
import { translate } from "../i18n/i18n"; | ||
import { showPrefOverlay } from "../ipcMain/senders"; | ||
import { openOverlay } from "../ipcMain/senders"; | ||
|
||
export default function getPreferencesItem(): MenuItemConstructorOptions { | ||
return { | ||
label: `${translate("preferences")}…`, | ||
id: "preferences", | ||
accelerator: "CmdOrCtrl+,", | ||
click(): void { | ||
showPrefOverlay(); | ||
openOverlay("preferences"); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/renderer/components/overlays/go-to-date-overlay/GoToDateOverlay.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import logger from "electron-log"; | ||
import React, { ChangeEvent, FormEvent, ReactElement, useState } from "react"; | ||
|
||
import { momentIndex, toIndexDate } from "../../../utils/dateFormat"; | ||
import { translations } from "../../../utils/i18n"; | ||
import OverlayContainer from "../overlay-hoc/OverlayContainer"; | ||
|
||
export interface StateProps { | ||
allowFutureEntries: boolean; | ||
dateSelected: Date; | ||
} | ||
|
||
export interface DispatchProps { | ||
closeOverlay: () => void; | ||
setDateSelected: (date: Date) => void; | ||
} | ||
|
||
type Props = StateProps & DispatchProps; | ||
|
||
/** | ||
* Dialog for quickly jumping to a certain date. | ||
*/ | ||
export default function GoToDateOverlay(props: Props): ReactElement { | ||
const { allowFutureEntries, closeOverlay, dateSelected, setDateSelected } = props; | ||
|
||
const todayFormatted = toIndexDate(new Date()); | ||
const dateSelectedFormatted = toIndexDate(dateSelected); | ||
|
||
// `date` can become `undefined` when the user's date input is incomplete (e.g. year not filled in | ||
// yet | ||
const [date, setDate] = useState<string | undefined>(dateSelectedFormatted); | ||
|
||
const onChange = (event: ChangeEvent<HTMLInputElement>): void => setDate(event.target.value); | ||
|
||
const onSubmit = (event: FormEvent<HTMLFormElement>): void => { | ||
event.preventDefault(); | ||
if (!date) { | ||
logger.error("Cannot go to date: Date is not defined"); | ||
} else { | ||
setDateSelected(momentIndex(date).toDate()); | ||
closeOverlay(); | ||
} | ||
}; | ||
|
||
const canSubmit = | ||
date && // `date` must be defined (i.e. user must have provided a valid date input) | ||
date !== dateSelectedFormatted && // Selected date cannot be the currently selected one | ||
(allowFutureEntries || date <= todayFormatted); // Disallow future dates if option is set | ||
|
||
return ( | ||
<OverlayContainer className="go-to-date-overlay"> | ||
<form onSubmit={onSubmit}> | ||
<h1>{translations["go-to-date"]}</h1> | ||
<label htmlFor="input-go-to-date"> | ||
Date: | ||
<input | ||
type="date" | ||
id="input-go-to-date" | ||
defaultValue={dateSelectedFormatted} | ||
onChange={onChange} | ||
/> | ||
</label> | ||
<button type="submit" className="button button-main" disabled={!canSubmit}> | ||
{translations.ok} | ||
</button> | ||
</form> | ||
</OverlayContainer> | ||
); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/renderer/components/overlays/go-to-date-overlay/GoToDateOverlayContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { connect } from "react-redux"; | ||
|
||
import { closeOverlay } from "../../../store/app/actionCreators"; | ||
import { SetOverlayAction } from "../../../store/app/types"; | ||
import { setDateSelected } from "../../../store/diary/actionCreators"; | ||
import { SetDateSelectedAction } from "../../../store/diary/types"; | ||
import { RootState, ThunkDispatchT } from "../../../store/store"; | ||
import GoToDateOverlay, { DispatchProps, StateProps } from "./GoToDateOverlay"; | ||
|
||
const mapStateToProps = (state: RootState): StateProps => ({ | ||
allowFutureEntries: state.app.allowFutureEntries, | ||
dateSelected: state.diary.dateSelected, | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch: ThunkDispatchT): DispatchProps => ({ | ||
closeOverlay: (): SetOverlayAction => dispatch(closeOverlay()), | ||
setDateSelected: (date: Date): SetDateSelectedAction => dispatch(setDateSelected(date)), | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(GoToDateOverlay); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters