2020-03-20 11:33:13 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
import * as EteSync from 'etesync';
|
|
|
|
|
|
|
|
import Switch from '@material-ui/core/Switch';
|
|
|
|
import FormControlLabel from '@material-ui/core/FormControlLabel';
|
|
|
|
import IconButton from '@material-ui/core/IconButton';
|
|
|
|
import MoreVertIcon from '@material-ui/icons/MoreVert';
|
|
|
|
import Menu from '@material-ui/core/Menu';
|
|
|
|
import MenuItem from '@material-ui/core/MenuItem';
|
2020-03-22 11:55:48 +00:00
|
|
|
import SortIcon from '@material-ui/icons/Sort';
|
2020-03-20 11:33:13 +00:00
|
|
|
|
|
|
|
import QuickAdd from './QuickAdd';
|
|
|
|
|
|
|
|
import { PimType } from '../../pim-types';
|
|
|
|
|
2020-03-22 11:55:48 +00:00
|
|
|
import { useSelector, useDispatch } from 'react-redux';
|
|
|
|
|
|
|
|
import { setSettings } from '../../store/actions';
|
|
|
|
import { StoreState } from '../../store';
|
|
|
|
|
2020-03-20 11:33:13 +00:00
|
|
|
interface PropsType {
|
|
|
|
defaultCollection: EteSync.CollectionInfo;
|
|
|
|
onItemSave: (item: PimType, journalUid: string, originalItem?: PimType) => Promise<void>;
|
|
|
|
showCompleted: boolean;
|
|
|
|
setShowCompleted: (completed: boolean) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function Toolbar(props: PropsType) {
|
|
|
|
const { defaultCollection, onItemSave, showCompleted, setShowCompleted } = props;
|
|
|
|
|
2020-03-22 11:55:48 +00:00
|
|
|
const [sortAnchorEl, setSortAnchorEl] = React.useState<null | HTMLElement>(null);
|
|
|
|
const [optionsAnchorEl, setOptionsAnchorEl] = React.useState<null | HTMLElement>(null);
|
2020-03-20 11:33:13 +00:00
|
|
|
|
2020-03-22 11:55:48 +00:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
const taskSettings = useSelector((state: StoreState) => state.settings.taskSettings);
|
|
|
|
const { sortBy } = taskSettings;
|
2020-03-20 11:33:13 +00:00
|
|
|
|
2020-03-22 11:55:48 +00:00
|
|
|
const handleSortChange = (sort: string) => {
|
|
|
|
dispatch(setSettings({ taskSettings: { ...taskSettings, sortBy: sort } }));
|
|
|
|
setSortAnchorEl(null);
|
2020-03-20 11:33:13 +00:00
|
|
|
};
|
|
|
|
|
2020-03-22 11:55:48 +00:00
|
|
|
const SortMenuItem = React.forwardRef(function SortMenuItem(props: { name: string, label: string }, ref) {
|
|
|
|
return (
|
|
|
|
<MenuItem innerRef={ref} selected={sortBy === props.name} onClick={() => handleSortChange(props.name)}>{props.label}</MenuItem>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-03-20 11:33:13 +00:00
|
|
|
return (
|
|
|
|
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
|
|
|
{defaultCollection && <QuickAdd style={{ flexGrow: 1, marginRight: '0.75em' }} onSubmit={onItemSave} defaultCollection={defaultCollection} />}
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<IconButton
|
|
|
|
aria-label="more"
|
|
|
|
aria-controls="long-menu"
|
|
|
|
aria-haspopup="true"
|
2020-03-22 11:55:48 +00:00
|
|
|
onClick={(e) => setSortAnchorEl(e.currentTarget)}
|
|
|
|
>
|
|
|
|
<SortIcon />
|
|
|
|
</IconButton>
|
|
|
|
<Menu
|
|
|
|
anchorEl={sortAnchorEl}
|
|
|
|
keepMounted
|
|
|
|
open={!!sortAnchorEl}
|
|
|
|
onClose={() => setSortAnchorEl(null)}
|
|
|
|
>
|
|
|
|
<SortMenuItem name="smart" label="Smart" />
|
|
|
|
<SortMenuItem name="dueDate" label="Due Date" />
|
|
|
|
<SortMenuItem name="priority" label="Priority" />
|
|
|
|
<SortMenuItem name="title" label="Title" />
|
|
|
|
<SortMenuItem name="lastModifiedDate" label="Last Modified" />
|
|
|
|
</Menu>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<IconButton
|
|
|
|
aria-label="more"
|
|
|
|
aria-controls="long-menu"
|
|
|
|
aria-haspopup="true"
|
|
|
|
onClick={(e) => setOptionsAnchorEl(e.currentTarget)}
|
2020-03-20 11:33:13 +00:00
|
|
|
>
|
|
|
|
<MoreVertIcon />
|
|
|
|
</IconButton>
|
|
|
|
<Menu
|
|
|
|
id="simple-menu"
|
2020-03-22 11:55:48 +00:00
|
|
|
anchorEl={optionsAnchorEl}
|
2020-03-20 11:33:13 +00:00
|
|
|
keepMounted
|
2020-03-22 11:55:48 +00:00
|
|
|
open={!!optionsAnchorEl}
|
|
|
|
onClose={() => setOptionsAnchorEl(null)}
|
2020-03-20 11:33:13 +00:00
|
|
|
>
|
|
|
|
<MenuItem>
|
|
|
|
<FormControlLabel
|
|
|
|
label="Show completed"
|
|
|
|
labelPlacement="start"
|
|
|
|
control={<Switch checked={showCompleted} onChange={(_e, checked) => setShowCompleted(checked)} />}
|
|
|
|
/>
|
|
|
|
</MenuItem>
|
|
|
|
</Menu>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|