From 2fd674a4566edfd5dbbbe89f42c1a5175a696566 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 14 Feb 2019 09:26:41 +0000 Subject: [PATCH] Add support for tasks. --- src/App.tsx | 13 ++++++- src/Journals/Journal.tsx | 18 ++++++--- src/Pim/PimMain.tsx | 38 ++++++++++++++----- src/Pim/index.tsx | 35 +++++++++++++++--- src/components/TaskList.tsx | 73 +++++++++++++++++++++++++++++++++++++ src/journal-processors.ts | 19 ++++++++-- src/pim-types.ts | 14 +++---- 7 files changed, 177 insertions(+), 33 deletions(-) create mode 100644 src/components/TaskList.tsx diff --git a/src/App.tsx b/src/App.tsx index 1ac3549..baeb464 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -37,7 +37,10 @@ const muiTheme = createMuiTheme({ dark: lightBlue.A700, contrastText: 'white', }, - } + }, + typography: { + useNextVariants: true, + }, }); export const routeResolver = new RouteResolver({ @@ -59,6 +62,14 @@ export const routeResolver = new RouteResolver({ }, new: 'new', }, + tasks: { + _id: { + _base: ':itemUid', + edit: 'edit', + log: 'log', + }, + new: 'new', + }, }, journals: { _id: { diff --git a/src/Journals/Journal.tsx b/src/Journals/Journal.tsx index 519c1cf..823dc71 100644 --- a/src/Journals/Journal.tsx +++ b/src/Journals/Journal.tsx @@ -10,6 +10,7 @@ import SearchableAddressBook from '../components/SearchableAddressBook'; import Contact from '../components/Contact'; import Calendar from '../components/Calendar'; import Event from '../components/Event'; +import TaskList from '../components/TaskList'; import AppBarOverride from '../widgets/AppBarOverride'; import Container from '../widgets/Container'; @@ -17,7 +18,7 @@ import Container from '../widgets/Container'; import JournalEntries from '../components/JournalEntries'; import journalView from './journalView'; -import { syncEntriesToItemMap, syncEntriesToCalendarItemMap } from '../journal-processors'; +import { syncEntriesToItemMap, syncEntriesToEventItemMap, syncEntriesToTaskItemMap } from '../journal-processors'; import { SyncInfo, SyncInfoJournal } from '../SyncGate'; @@ -39,6 +40,7 @@ interface PropsTypeInner extends PropsType { const JournalAddressBook = journalView(SearchableAddressBook, Contact); const PersistCalendar = historyPersistor('Calendar')(Calendar); const JournalCalendar = journalView(PersistCalendar, Event); +const JournalTaskList = journalView(TaskList, Event); class Journal extends React.Component { state: { @@ -65,17 +67,23 @@ class Journal extends React.Component { let itemsTitle: string; let itemsView: JSX.Element; if (collectionInfo.type === 'CALENDAR') { - itemsView = - ; + itemsView = ( + ); itemsTitle = 'Events'; } else if (collectionInfo.type === 'ADDRESS_BOOK') { itemsView = ; itemsTitle = 'Contacts'; } else if (collectionInfo.type === 'TASKS') { - itemsView =
Task preview is not yet supported
; + itemsView = ( + ); itemsTitle = 'Tasks'; - journalOnly = true; } else { itemsView =
Preview is not supported for this journal type
; itemsTitle = 'Items'; diff --git a/src/Pim/PimMain.tsx b/src/Pim/PimMain.tsx index bbf58e7..41f9b2d 100644 --- a/src/Pim/PimMain.tsx +++ b/src/Pim/PimMain.tsx @@ -13,8 +13,9 @@ import Container from '../widgets/Container'; import SearchableAddressBook from '../components/SearchableAddressBook'; import Calendar from '../components/Calendar'; +import TaskList from '../components/TaskList'; -import { EventType, ContactType } from '../pim-types'; +import { EventType, ContactType, TaskType } from '../pim-types'; import { routeResolver } from '../App'; @@ -22,12 +23,14 @@ import { historyPersistor } from '../persist-state-history'; const addressBookTitle = 'Address Book'; const calendarTitle = 'Calendar'; +const tasksTitle = 'Tasks'; const PersistCalendar = historyPersistor('Calendar')(Calendar); interface PropsType { contacts: Array; events: Array; + tasks: Array; location?: Location; history?: History; theme: Theme; @@ -42,6 +45,7 @@ class PimMain extends React.PureComponent { super(props); this.state = {tab: 1}; this.eventClicked = this.eventClicked.bind(this); + this.taskClicked = this.taskClicked.bind(this); this.contactClicked = this.contactClicked.bind(this); this.floatingButtonClicked = this.floatingButtonClicked.bind(this); this.newEvent = this.newEvent.bind(this); @@ -54,6 +58,13 @@ class PimMain extends React.PureComponent { routeResolver.getRoute('pim.events._id', { itemUid: uid })); } + taskClicked(event: ICAL.Event) { + const uid = event.uid; + + this.props.history!.push( + routeResolver.getRoute('pim.tasks._id', { itemUid: uid })); + } + contactClicked(contact: ContactType) { const uid = contact.uid; @@ -106,24 +117,33 @@ class PimMain extends React.PureComponent { + - { tab === 0 && - + + + { tab === 0 && - - } - { tab === 1 && - + } + { tab === 1 && - - } + } + { tab === 2 && + + } + diff --git a/src/Pim/index.tsx b/src/Pim/index.tsx index 88a4da9..7ea9234 100644 --- a/src/Pim/index.tsx +++ b/src/Pim/index.tsx @@ -16,7 +16,7 @@ import { pure } from 'recompose'; import { History } from 'history'; -import { PimType, ContactType, EventType } from '../pim-types'; +import { PimType, ContactType, EventType, TaskType } from '../pim-types'; import Container from '../widgets/Container'; @@ -36,7 +36,7 @@ import { SyncInfo } from '../SyncGate'; import { createJournalEntry } from '../etesync-helpers'; -import { syncEntriesToItemMap, syncEntriesToCalendarItemMap } from '../journal-processors'; +import { syncEntriesToItemMap, syncEntriesToEventItemMap, syncEntriesToTaskItemMap } from '../journal-processors'; function objValues(obj: any) { return Object.keys(obj).map((x) => obj[x]); @@ -47,8 +47,10 @@ const itemsSelector = createSelector( (syncInfo) => { let collectionsAddressBook: Array = []; let collectionsCalendar: Array = []; + let collectionsTaskList: Array = []; let addressBookItems: {[key: string]: ContactType} = {}; let calendarItems: {[key: string]: EventType} = {}; + let taskListItems: {[key: string]: TaskType} = {}; syncInfo.forEach( (syncJournal) => { const syncEntries = syncJournal.entries; @@ -59,13 +61,18 @@ const itemsSelector = createSelector( addressBookItems = syncEntriesToItemMap(collectionInfo, syncEntries, addressBookItems); collectionsAddressBook.push(collectionInfo); } else if (collectionInfo.type === 'CALENDAR') { - calendarItems = syncEntriesToCalendarItemMap(collectionInfo, syncEntries, calendarItems); + calendarItems = syncEntriesToEventItemMap(collectionInfo, syncEntries, calendarItems); collectionsCalendar.push(collectionInfo); + } else if (collectionInfo.type === 'TASKS') { + taskListItems = syncEntriesToTaskItemMap(collectionInfo, syncEntries, taskListItems); + collectionsTaskList.push(collectionInfo); } } ); - return { collectionsAddressBook, collectionsCalendar, addressBookItems, calendarItems }; + return { + collectionsAddressBook, collectionsCalendar, collectionsTaskList, addressBookItems, calendarItems, taskListItems + }; }, ); @@ -188,6 +195,7 @@ const CollectionRoutes = withStyles(styles)(withRouter(