From 29d1e5cfe565c13ce54e929232bca97ed1a8d075 Mon Sep 17 00:00:00 2001 From: Andrew P Maney Date: Fri, 13 Mar 2020 01:30:20 -0700 Subject: [PATCH] Tasks: adds mapPriority helper function handles any possible issues with priorities that aren't 1, 5, or 9 --- src/components/Tasks/TaskEdit.tsx | 4 ++-- src/components/Tasks/TaskListItem.tsx | 4 +++- src/helpers.tsx | 13 +++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/components/Tasks/TaskEdit.tsx b/src/components/Tasks/TaskEdit.tsx index 42d1a22..a54f2ac 100644 --- a/src/components/Tasks/TaskEdit.tsx +++ b/src/components/Tasks/TaskEdit.tsx @@ -35,7 +35,7 @@ import * as ICAL from 'ical.js'; import * as EteSync from 'etesync'; -import { getCurrentTimezone } from '../../helpers'; +import { getCurrentTimezone, mapPriority } from '../../helpers'; import { TaskType, TaskStatusType, timezoneLoadFromName, TaskPriorityType } from '../../pim-types'; @@ -308,7 +308,7 @@ class TaskEdit extends React.PureComponent { this.handleChange('priority', Number(e.target.value))} > diff --git a/src/components/Tasks/TaskListItem.tsx b/src/components/Tasks/TaskListItem.tsx index 7e89c3b..40c4c42 100644 --- a/src/components/Tasks/TaskListItem.tsx +++ b/src/components/Tasks/TaskListItem.tsx @@ -19,6 +19,8 @@ const checkboxColor = { import moment from 'moment'; +import { mapPriority } from '../../helpers'; + interface PropsType { entry: TaskType; onClick: (task: TaskType) => void; @@ -49,7 +51,7 @@ export default React.memo(function TaskListItem(props: PropsType) { onClick={(e) => e.stopPropagation()} onChange={toggleComplete} checked={task.finished} - icon={} + icon={} /> } /> diff --git a/src/helpers.tsx b/src/helpers.tsx index 0aadeef..4615cb8 100644 --- a/src/helpers.tsx +++ b/src/helpers.tsx @@ -4,6 +4,7 @@ import * as React from 'react'; import * as ICAL from 'ical.js'; import moment from 'moment'; +import { TaskPriorityType } from './pim-types'; // Generic handling of input changes export function handleInputChange(self: React.Component, part?: string) { @@ -107,3 +108,15 @@ export function formatOurTimezoneOffset() { export function getCurrentTimezone() { 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; + } +} \ No newline at end of file