Task edit: change "All Day" to "Include Time"

master
Andrew P Maney 5 years ago committed by Tom Hacohen
parent e39974105f
commit b6b46d2b24

@ -62,7 +62,7 @@ class TaskEdit extends React.PureComponent<PropsType> {
title: string; title: string;
status: TaskStatusType; status: TaskStatusType;
priority: TaskPriorityType; priority: TaskPriorityType;
allDay: boolean; includeTime: boolean;
start?: Date; start?: Date;
due?: Date; due?: Date;
timezone: string | null; timezone: string | null;
@ -82,7 +82,7 @@ class TaskEdit extends React.PureComponent<PropsType> {
title: '', title: '',
status: TaskStatusType.NeedsAction, status: TaskStatusType.NeedsAction,
priority: TaskPriorityType.Undefined, priority: TaskPriorityType.Undefined,
allDay: false, includeTime: false,
location: '', location: '',
description: '', description: '',
tags: [], tags: [],
@ -100,7 +100,7 @@ class TaskEdit extends React.PureComponent<PropsType> {
this.state.status = task.status ?? TaskStatusType.NeedsAction; this.state.status = task.status ?? TaskStatusType.NeedsAction;
this.state.priority = task.priority ?? TaskPriorityType.Undefined; this.state.priority = task.priority ?? TaskPriorityType.Undefined;
if (task.startDate) { if (task.startDate) {
this.state.allDay = task.startDate.isDate; this.state.includeTime = !task.startDate.isDate;
this.state.start = task.startDate.convertToZone(ICAL.Timezone.localTimezone).toJSDate(); this.state.start = task.startDate.convertToZone(ICAL.Timezone.localTimezone).toJSDate();
} }
if (task.dueDate) { if (task.dueDate) {
@ -125,7 +125,7 @@ class TaskEdit extends React.PureComponent<PropsType> {
this.onSubmit = this.onSubmit.bind(this); this.onSubmit = this.onSubmit.bind(this);
this.handleChange = this.handleChange.bind(this); this.handleChange = this.handleChange.bind(this);
this.handleInputChange = this.handleInputChange.bind(this); this.handleInputChange = this.handleInputChange.bind(this);
this.toggleAllDay = this.toggleAllDay.bind(this); this.toggleTime = this.toggleTime.bind(this);
this.onDeleteRequest = this.onDeleteRequest.bind(this); this.onDeleteRequest = this.onDeleteRequest.bind(this);
} }
@ -157,29 +157,29 @@ class TaskEdit extends React.PureComponent<PropsType> {
this.handleChange(name, value); this.handleChange(name, value);
} }
public toggleAllDay() { public toggleTime() {
this.setState({ allDay: !this.state.allDay }); this.setState({ includeTime: !this.state.includeTime });
} }
public onSubmit(e: React.FormEvent<any>) { public onSubmit(e: React.FormEvent<any>) {
e.preventDefault(); e.preventDefault();
function fromDate(date: Date | undefined, allDay: boolean) { function fromDate(date: Date | undefined, includeTime: boolean) {
if (!date) { if (!date) {
return undefined; return undefined;
} }
const ret = ICAL.Time.fromJSDate(date, false); const ret = ICAL.Time.fromJSDate(date, false);
if (!allDay) { if (includeTime) {
return ret; return ret;
} else { } else {
const data = ret.toJSON(); const data = ret.toJSON();
data.isDate = allDay; data.isDate = false;
return ICAL.Time.fromData(data); return ICAL.Time.fromData(data);
} }
} }
const startDate = fromDate(this.state.start, this.state.allDay); const startDate = fromDate(this.state.start, this.state.includeTime);
const dueDate = fromDate(this.state.due, this.state.allDay); const dueDate = fromDate(this.state.due, this.state.includeTime);
if (startDate && dueDate) { if (startDate && dueDate) {
if (startDate.compare(dueDate) >= 0) { if (startDate.compare(dueDate) >= 0) {
@ -327,7 +327,7 @@ class TaskEdit extends React.PureComponent<PropsType> {
<FormControl style={styles.fullWidth}> <FormControl style={styles.fullWidth}>
<FormHelperText>Hide until</FormHelperText> <FormHelperText>Hide until</FormHelperText>
<DateTimePicker <DateTimePicker
dateOnly={this.state.allDay} dateOnly={!this.state.includeTime}
placeholder="Hide until" placeholder="Hide until"
value={this.state.start} value={this.state.start}
onChange={(date?: Date) => this.setState({ start: date })} onChange={(date?: Date) => this.setState({ start: date })}
@ -340,7 +340,7 @@ class TaskEdit extends React.PureComponent<PropsType> {
<FormControl style={styles.fullWidth}> <FormControl style={styles.fullWidth}>
<FormHelperText>Due</FormHelperText> <FormHelperText>Due</FormHelperText>
<DateTimePicker <DateTimePicker
dateOnly={this.state.allDay} dateOnly={!this.state.includeTime}
placeholder="Due" placeholder="Due"
value={this.state.due} value={this.state.due}
onChange={(date?: Date) => this.setState({ due: date })} onChange={(date?: Date) => this.setState({ due: date })}
@ -354,17 +354,17 @@ class TaskEdit extends React.PureComponent<PropsType> {
<FormControlLabel <FormControlLabel
control={ control={
<Switch <Switch
name="allDay" name="includeTime"
checked={this.state.allDay} checked={this.state.includeTime}
onChange={this.toggleAllDay} onChange={this.toggleTime}
color="primary" color="primary"
/> />
} }
label="All Day" label="Include time"
/> />
</FormGroup> </FormGroup>
{(!this.state.allDay) && ( {(this.state.includeTime) && (
<TimezonePicker style={styles.fullWidth} value={this.state.timezone} onChange={(zone) => this.setState({ timezone: zone })} /> <TimezonePicker style={styles.fullWidth} value={this.state.timezone} onChange={(zone) => this.setState({ timezone: zone })} />
)} )}

Loading…
Cancel
Save