From a9b6978ae51617fb15f023fd0aa4c927f88a7666 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 7 Jan 2019 21:12:08 +0000 Subject: [PATCH] Add basic support for viewing tasks. --- src/Journal/index.tsx | 14 +++++++++++--- src/SideMenu/SideMenuJournals.tsx | 8 +++++++- src/components/JournalEntries.tsx | 14 ++++++++++---- src/pim-types.ts | 27 +++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/Journal/index.tsx b/src/Journal/index.tsx index 7ed58cd..c70c131 100644 --- a/src/Journal/index.tsx +++ b/src/Journal/index.tsx @@ -51,7 +51,8 @@ class Journal extends React.PureComponent { render() { const { theme } = this.props; - const currentTab = this.state.tab; + let currentTab = this.state.tab; + let journalOnly = false; const journalUid = this.props.match.params.journalUid; const syncJournal = this.props.syncInfo.get(journalUid); @@ -73,11 +74,18 @@ class Journal extends React.PureComponent { itemsView = ; itemsTitle = 'Contacts'; + } else if (collectionInfo.type === 'TASKS') { + itemsView =
Task preview is not yet supported
; + itemsTitle = 'Tasks'; + journalOnly = true; } else { - itemsView =
Unsupported type
; + itemsView =
Preview is not supported for this journal type
; itemsTitle = 'Items'; + journalOnly = true; } + currentTab = journalOnly ? 1 : currentTab; + return ( @@ -87,7 +95,7 @@ class Journal extends React.PureComponent { value={currentTab} onChange={(event, tab) => this.setState({ tab })} > - + { currentTab === 0 && diff --git a/src/SideMenu/SideMenuJournals.tsx b/src/SideMenu/SideMenuJournals.tsx index 9934c53..24218ca 100644 --- a/src/SideMenu/SideMenuJournals.tsx +++ b/src/SideMenu/SideMenuJournals.tsx @@ -46,7 +46,8 @@ class SideMenuJournals extends React.PureComponent { return ret; }, { CALENDAR: [], - ADDRESS_BOOK: [] + ADDRESS_BOOK: [], + TASKS: [] }); return ( @@ -60,6 +61,11 @@ class SideMenuJournals extends React.PureComponent { primaryText="Calendars" nestedItems={journalMap.CALENDAR} /> + + ); } diff --git a/src/components/JournalEntries.tsx b/src/components/JournalEntries.tsx index 6f423aa..0dbc5bd 100644 --- a/src/components/JournalEntries.tsx +++ b/src/components/JournalEntries.tsx @@ -13,7 +13,7 @@ import IconEdit from '@material-ui/icons/Edit'; import * as ICAL from 'ical.js'; -import { EventType, ContactType } from '../pim-types'; +import { TaskType, EventType, ContactType } from '../pim-types'; import * as EteSync from '../api/EteSync'; @@ -57,9 +57,15 @@ class JournalEntries extends React.PureComponent { let name; let uid; if (comp.name === 'vcalendar') { - const vevent = EventType.fromVCalendar(comp); - name = vevent.summary; - uid = vevent.uid; + if (EventType.isEvent(comp)) { + const vevent = EventType.fromVCalendar(comp); + name = vevent.summary; + uid = vevent.uid; + } else { + const vtodo = TaskType.fromVCalendar(comp); + name = vtodo.summary; + uid = vtodo.uid; + } } else if (comp.name === 'vcard') { const vcard = new ContactType(comp); name = vcard.fn; diff --git a/src/pim-types.ts b/src/pim-types.ts index 775a612..bdf7299 100644 --- a/src/pim-types.ts +++ b/src/pim-types.ts @@ -9,6 +9,10 @@ export interface PimType { export class EventType extends ICAL.Event implements PimType { color: string; + static isEvent(comp: ICAL.Component) { + return !!comp.getFirstSubcomponent('vevent'); + } + static fromVCalendar(comp: ICAL.Component) { return new EventType(comp.getFirstSubcomponent('vevent')); } @@ -49,6 +53,29 @@ export class EventType extends ICAL.Event implements PimType { } } +export class TaskType extends ICAL.Event implements PimType { + color: string; + + static fromVCalendar(comp: ICAL.Component) { + return new EventType(comp.getFirstSubcomponent('vtodo')); + } + + toIcal() { + let comp = new ICAL.Component(['vcalendar', [], []]); + comp.updatePropertyWithValue('prodid', '-//iCal.js EteSync Web'); + comp.updatePropertyWithValue('version', '4.0'); + + comp.addSubcomponent(this.component); + return comp.toString(); + } + + clone() { + const ret = new TaskType(new ICAL.Component(this.component.toJSON())); + ret.color = this.color; + return ret; + } +} + export class ContactType implements PimType { comp: ICAL.Component;