Tasks: adds mapPriority helper function

handles any possible issues with priorities that aren't 1, 5, or 9
master
Andrew P Maney 5 years ago committed by Tom Hacohen
parent bdd89fb533
commit 29d1e5cfe5

@ -35,7 +35,7 @@ import * as ICAL from 'ical.js';
import * as EteSync from 'etesync'; import * as EteSync from 'etesync';
import { getCurrentTimezone } from '../../helpers'; import { getCurrentTimezone, mapPriority } from '../../helpers';
import { TaskType, TaskStatusType, timezoneLoadFromName, TaskPriorityType } from '../../pim-types'; import { TaskType, TaskStatusType, timezoneLoadFromName, TaskPriorityType } from '../../pim-types';
@ -308,7 +308,7 @@ class TaskEdit extends React.PureComponent<PropsType> {
<RadioGroup <RadioGroup
row row
value={this.state.priority} value={mapPriority(this.state.priority)}
onChange={(e) => this.handleChange('priority', Number(e.target.value))} onChange={(e) => this.handleChange('priority', Number(e.target.value))}
> >
<ColoredRadio value={TaskPriorityType.Undefined} label="None" color={colors.grey[600]} /> <ColoredRadio value={TaskPriorityType.Undefined} label="None" color={colors.grey[600]} />

@ -19,6 +19,8 @@ const checkboxColor = {
import moment from 'moment'; import moment from 'moment';
import { mapPriority } from '../../helpers';
interface PropsType { interface PropsType {
entry: TaskType; entry: TaskType;
onClick: (task: TaskType) => void; onClick: (task: TaskType) => void;
@ -49,7 +51,7 @@ export default React.memo(function TaskListItem(props: PropsType) {
onClick={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}
onChange={toggleComplete} onChange={toggleComplete}
checked={task.finished} checked={task.finished}
icon={<CheckBoxOutlineBlankIcon style={{ color: checkboxColor[task.priority] }} />} icon={<CheckBoxOutlineBlankIcon style={{ color: checkboxColor[mapPriority(task.priority)] }} />}
/> />
} }
/> />

@ -4,6 +4,7 @@
import * as React from 'react'; import * as React from 'react';
import * as ICAL from 'ical.js'; import * as ICAL from 'ical.js';
import moment from 'moment'; import moment from 'moment';
import { TaskPriorityType } from './pim-types';
// Generic handling of input changes // Generic handling of input changes
export function handleInputChange(self: React.Component, part?: string) { export function handleInputChange(self: React.Component, part?: string) {
@ -107,3 +108,15 @@ export function formatOurTimezoneOffset() {
export function getCurrentTimezone() { export function getCurrentTimezone() {
return Intl.DateTimeFormat().resolvedOptions().timeZone; return Intl.DateTimeFormat().resolvedOptions().timeZone;
} }
export function mapPriority(priority: number): TaskPriorityType {
if (priority > 0 && priority < 5) {
return TaskPriorityType.High;
} else if (priority === 5) {
return TaskPriorityType.Medium;
} else if (priority > 5 && priority < 10) {
return TaskPriorityType.Low;
} else {
return TaskPriorityType.Undefined;
}
}
Loading…
Cancel
Save