Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Add an unset button to datetime picker
Browse files Browse the repository at this point in the history
  • Loading branch information
tdemin committed Jan 16, 2020
1 parent b66248d commit 9c21b62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/views/assets/locales.ts
Expand Up @@ -36,6 +36,7 @@ export default new LocalizedStrings({
editor_parentNoParentVal: "No parent",
editor_deadline: "Deadline:",
editor_reminder: "Reminder:",
editor_unsetTp: "Unset",
task_toggleBtnCompleted: "Completed",
task_toggleBtnPending: "Pending",
app_versionString: `${appFullName} v${appVersion} by ${appAuthor}`,
Expand Down
9 changes: 8 additions & 1 deletion src/views/components/dateTimePicker.tsx
Expand Up @@ -7,6 +7,7 @@ import {
DateFormat,
TimeFormat,
} from "../../helpers/datetime";
import strings from "../assets/locales";

/** Helper for `new Date()`. */
const FDate = (v: number | undefined) => new Date(v || 0);
Expand Down Expand Up @@ -46,9 +47,10 @@ export class DateTimePicker extends React.Component<Props, State> {
const date = parse(e.currentTarget.value, TimeFormat, this.state.date);
this.setState({ date });
};
// TODO: add an "Unset" button
unsetDate = () => this.setState({ date: FDate(0) });
render = () => {
let date, time;
// date/time input sometimes reports weird values that are out of range
try {
date = format(this.state.date, DateFormat);
time = format(this.state.date, TimeFormat);
Expand All @@ -70,6 +72,11 @@ export class DateTimePicker extends React.Component<Props, State> {
value={time}
required={this.props.timeRequired}
/>
<input
type="button"
value={strings.editor_unsetTp}
onClick={this.unsetDate}
/>
</div>
);
};
Expand Down

0 comments on commit 9c21b62

Please sign in to comment.