Skip to content

Commit

Permalink
Adds many core features for Tasks
Browse files Browse the repository at this point in the history
Adds UI features like toolbar (w/ sorting & searching), sidebar (w/ filtering), light editing improvements.
Adds task type features like priority, tags.
Adds some use of Context for prop drilling.
Adds Task Settings to the redux store.

This is a massive commit. I wanted to keep everything separate but the code is too tightly coupled.
  • Loading branch information
AbleLincoln committed Feb 22, 2020
1 parent 0bdc0e2 commit 0907a47
Show file tree
Hide file tree
Showing 19 changed files with 639 additions and 223 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -10,6 +10,7 @@
"@material-ui/pickers": "^3.2.10",
"@material-ui/styles": "^4.6.0",
"etesync": "^0.3.1",
"fuse.js": "^3.4.6",
"ical.js": "^1.2.2",
"immutable": "^4.0.0-rc.12",
"localforage": "^1.7.3",
Expand Down
4 changes: 2 additions & 2 deletions src/Journals/Journal.tsx
Expand Up @@ -11,8 +11,8 @@ import SearchableAddressBook from '../components/SearchableAddressBook';
import Contact from '../components/Contact';
import Calendar from '../components/Calendar';
import Event from '../components/Event';
import Task from '../components/Task';
import TaskList from '../components/TaskList';
import Task from '../components/Tasks/Task';
import TaskList from '../components/Tasks/TaskList';

import AppBarOverride from '../widgets/AppBarOverride';
import Container from '../widgets/Container';
Expand Down
12 changes: 3 additions & 9 deletions src/Pim/PimMain.tsx
Expand Up @@ -7,17 +7,15 @@ import { Theme, withTheme } from '@material-ui/core/styles';

import * as ICAL from 'ical.js';

import * as EteSync from 'etesync';

import { Location, History } from 'history';

import Container from '../widgets/Container';

import SearchableAddressBook from '../components/SearchableAddressBook';
import Calendar from '../components/Calendar';
import TaskList from '../components/TaskList';
import TaskList from '../components/Tasks/TaskList';

import { EventType, ContactType, TaskType, PimType } from '../pim-types';
import { EventType, ContactType, TaskType } from '../pim-types';

import { routeResolver } from '../App';

Expand All @@ -36,8 +34,6 @@ interface PropsType {
location?: Location;
history?: History;
theme: Theme;
collectionsTaskList: EteSync.CollectionInfo[];
onItemSave: (item: PimType, journalUid: string, originalContact?: PimType) => void;
}

class PimMain extends React.PureComponent<PropsType> {
Expand Down Expand Up @@ -68,7 +64,7 @@ class PimMain extends React.PureComponent<PropsType> {
const itemUid = `${(event as any).journalUid}|${event.uid}`;

this.props.history!.push(
routeResolver.getRoute('pim.tasks._id', { itemUid }));
routeResolver.getRoute('pim.tasks._id.edit', { itemUid }));
}

public contactClicked(contact: ContactType) {
Expand Down Expand Up @@ -147,9 +143,7 @@ class PimMain extends React.PureComponent<PropsType> {
{tab === 2 &&
<TaskList
entries={this.props.tasks}
collections={this.props.collectionsTaskList}
onItemClick={this.taskClicked}
onItemSave={this.props.onItemSave}
/>
}
</Container>
Expand Down
17 changes: 11 additions & 6 deletions src/Pim/index.tsx
Expand Up @@ -24,8 +24,8 @@ import ContactEdit from '../components/ContactEdit';
import Contact from '../components/Contact';
import EventEdit from '../components/EventEdit';
import Event from '../components/Event';
import TaskEdit from '../components/TaskEdit';
import Task from '../components/Task';
import TaskEdit from '../components/Tasks/TaskEdit';
import Task from '../components/Tasks/Task';
import PimMain from './PimMain';

import { routeResolver } from '../App';
Expand Down Expand Up @@ -115,10 +115,10 @@ type CollectionRoutesPropsType = RouteComponentProps<{}> & {

const styles = (theme: any) => ({
button: {
marginLeft: theme.spacing.unit,
marginLeft: theme.spacing(1),
},
leftIcon: {
marginRight: theme.spacing.unit,
marginRight: theme.spacing(1),
},
});

Expand Down Expand Up @@ -220,6 +220,11 @@ const CollectionRoutes = withStyles(styles)(withRouter(
}
));

export const PimContext = React.createContext({
onItemSave: (_item: PimType, _journalUid: string, _originalEvent?: PimType, _goBack = true) => { return },
collectionsTaskList: [] as EteSync.CollectionInfo[],
});

class Pim extends React.PureComponent {
public props: {
etesync: CredentialsData;
Expand Down Expand Up @@ -313,6 +318,7 @@ class Pim extends React.PureComponent {
const { collectionsAddressBook, collectionsCalendar, collectionsTaskList, addressBookItems, calendarItems, taskListItems } = itemsSelector(this.props);

return (
<PimContext.Provider value={{ onItemSave: this.onItemSave, collectionsTaskList }}>
<Switch>
<Route
path={routeResolver.getRoute('pim')}
Expand All @@ -323,8 +329,6 @@ class Pim extends React.PureComponent {
events={objValues(calendarItems)}
tasks={objValues(taskListItems)}
history={history}
onItemSave={this.onItemSave}
collectionsTaskList={collectionsTaskList}
/>
)}
/>
Expand Down Expand Up @@ -377,6 +381,7 @@ class Pim extends React.PureComponent {
)}
/>
</Switch>
</PimContext.Provider>
);
}
}
Expand Down
118 changes: 0 additions & 118 deletions src/components/TaskList.tsx

This file was deleted.

50 changes: 50 additions & 0 deletions src/components/Tasks/AddNewTaskItem.tsx
@@ -0,0 +1,50 @@
import React, { useState, useContext } from 'react';

import ICAL from 'ical.js';
import uuid from 'uuid';

import Checkbox from '@material-ui/core/Checkbox';
import TextField from '@material-ui/core/TextField';

import { TaskType, TaskStatusType, TaskPriorityType } from '../../pim-types';
import { ListItem } from '../../widgets/List';
import { PimContext } from '../../Pim';

const AddNewTaskItem = () => {
const [title, setTitle] = useState('');
const { onItemSave: save, collectionsTaskList: collections } = useContext(PimContext);

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setTitle(e.target.value);
};

const handleKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') {
e.preventDefault();

const event = new TaskType(null);
event.uid = uuid.v4();
event.title = title;
event.status = TaskStatusType.NeedsAction;
event.priority = TaskPriorityType.None;
event.lastModified = ICAL.Time.now();

save(event, collections[0].uid, undefined, false);

setTitle('');
}
};

return (
<ListItem leftIcon={<Checkbox disabled />}>
<TextField
label="New task"
value={title}
onChange={handleChange}
onKeyPress={handleKeyPress}
/>
</ListItem>
);
};

export default AddNewTaskItem;
32 changes: 32 additions & 0 deletions src/components/Tasks/ColoredRadio.tsx
@@ -0,0 +1,32 @@
import React from 'react';

import { makeStyles } from '@material-ui/core/styles';
import * as colors from '@material-ui/core/colors';
import Radio from '@material-ui/core/Radio';
import { Omit } from '@material-ui/types';
import FormControlLabel, { FormControlLabelProps } from '@material-ui/core/FormControlLabel';

interface Props {
color: string;
label: string;
}

const useStyles = makeStyles({
root: {
color: (props: Props) => colors[props.color][600],
},
});

const ColoredRadio = (props: Props & Omit<FormControlLabelProps, keyof Props | 'control'>) => {
const { color, label, value, ...other } = props;
const { root } = useStyles(props);

return <FormControlLabel
className={root}
label={label}
control={<Radio color="default" className={root} value={value} />}
{...other}
/>;
};

export default ColoredRadio;

0 comments on commit 0907a47

Please sign in to comment.