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 MenuItem from '@material-ui/core/MenuItem';
|
2020-03-22 11:55:48 +00:00
|
|
|
import SortIcon from '@material-ui/icons/Sort';
|
2020-03-25 10:54:54 +00:00
|
|
|
import SearchIcon from '@material-ui/icons/Search';
|
|
|
|
import CloseIcon from '@material-ui/icons/Close';
|
|
|
|
import TextField from '@material-ui/core/TextField';
|
|
|
|
import { makeStyles } from '@material-ui/core/styles';
|
|
|
|
import { Transition } from 'react-transition-group';
|
|
|
|
import InputAdornment from '@material-ui/core/InputAdornment';
|
2020-03-20 11:33:13 +00:00
|
|
|
|
|
|
|
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-23 11:24:04 +00:00
|
|
|
import Menu from '../../widgets/Menu';
|
|
|
|
|
2020-03-25 10:54:54 +00:00
|
|
|
const transitionTimeout = 300;
|
|
|
|
|
|
|
|
const transitionStyles = {
|
|
|
|
entering: { visibility: 'visible', width: '100%', overflow: 'hidden' },
|
|
|
|
entered: { visibility: 'visible', width: '100%' },
|
|
|
|
exiting: { visibility: 'visible', width: '0%', overflow: 'hidden' },
|
|
|
|
exited: { visibility: 'hidden', width: '0%' },
|
|
|
|
};
|
|
|
|
|
|
|
|
const useStyles = makeStyles((theme) => ({
|
|
|
|
button: {
|
|
|
|
marginRight: theme.spacing(1),
|
|
|
|
},
|
|
|
|
textField: {
|
|
|
|
transition: `width ${transitionTimeout}ms`,
|
|
|
|
marginRight: theme.spacing(1),
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2020-03-20 11:33:13 +00:00
|
|
|
interface PropsType {
|
|
|
|
defaultCollection: EteSync.CollectionInfo;
|
|
|
|
onItemSave: (item: PimType, journalUid: string, originalItem?: PimType) => Promise<void>;
|
|
|
|
showCompleted: boolean;
|
2020-03-30 14:01:38 +00:00
|
|
|
showHidden: boolean;
|
2020-03-20 11:33:13 +00:00
|
|
|
setShowCompleted: (completed: boolean) => void;
|
2020-03-30 14:01:38 +00:00
|
|
|
setShowHidden: (hidden: boolean) => void;
|
2020-03-25 10:54:54 +00:00
|
|
|
searchTerm: string;
|
|
|
|
setSearchTerm: (term: string) => void;
|
2020-03-20 11:33:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function Toolbar(props: PropsType) {
|
2020-03-30 14:01:38 +00:00
|
|
|
const { showCompleted, setShowCompleted, searchTerm, setSearchTerm, showHidden, setShowHidden } = props;
|
2020-03-20 11:33:13 +00:00
|
|
|
|
2020-03-25 10:54:54 +00:00
|
|
|
const [showSearchField, setShowSearchField] = React.useState(false);
|
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-25 10:54:54 +00:00
|
|
|
const classes = useStyles();
|
|
|
|
|
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-25 10:54:54 +00:00
|
|
|
const toggleSearchField = () => {
|
|
|
|
if (showSearchField) {
|
|
|
|
setSearchTerm('');
|
|
|
|
}
|
|
|
|
setShowSearchField(!showSearchField);
|
|
|
|
};
|
|
|
|
|
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 (
|
2020-03-25 10:54:54 +00:00
|
|
|
<div style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
|
|
|
|
<Transition in={showSearchField} timeout={transitionTimeout}>
|
|
|
|
{(state) => (
|
|
|
|
<TextField
|
|
|
|
fullWidth
|
|
|
|
placeholder="Search"
|
|
|
|
value={searchTerm}
|
|
|
|
color="secondary"
|
|
|
|
variant="standard"
|
|
|
|
className={classes.textField}
|
|
|
|
style={transitionStyles[state]}
|
|
|
|
onChange={(e) => setSearchTerm(e.target.value)}
|
|
|
|
InputProps={{
|
|
|
|
startAdornment: (
|
|
|
|
<InputAdornment position="start">
|
|
|
|
<SearchIcon />
|
|
|
|
</InputAdornment>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Transition>
|
|
|
|
|
|
|
|
<div className={classes.button}>
|
2020-03-25 09:44:24 +00:00
|
|
|
<IconButton size="small" onClick={toggleSearchField} title={showSearchField ? 'Close' : 'Search'}>
|
2020-03-25 10:54:54 +00:00
|
|
|
{showSearchField ? <CloseIcon /> : <SearchIcon />}
|
|
|
|
</IconButton>
|
|
|
|
</div>
|
2020-03-20 11:33:13 +00:00
|
|
|
|
2020-03-25 10:54:54 +00:00
|
|
|
<div className={classes.button}>
|
2020-03-20 11:33:13 +00:00
|
|
|
<IconButton
|
2020-03-25 10:54:54 +00:00
|
|
|
size="small"
|
2020-03-25 09:44:24 +00:00
|
|
|
title="Sort"
|
|
|
|
aria-label="Sort"
|
|
|
|
aria-controls="sort-menu"
|
2020-03-20 11:33:13 +00:00
|
|
|
aria-haspopup="true"
|
2020-03-22 11:55:48 +00:00
|
|
|
onClick={(e) => setSortAnchorEl(e.currentTarget)}
|
|
|
|
>
|
|
|
|
<SortIcon />
|
|
|
|
</IconButton>
|
|
|
|
<Menu
|
2020-03-25 09:44:24 +00:00
|
|
|
id="sort-menu"
|
2020-03-22 11:55:48 +00:00
|
|
|
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>
|
|
|
|
|
2020-03-25 10:54:54 +00:00
|
|
|
<div className={classes.button}>
|
2020-03-22 11:55:48 +00:00
|
|
|
<IconButton
|
2020-03-25 10:54:54 +00:00
|
|
|
size="small"
|
2020-03-25 09:44:24 +00:00
|
|
|
title="Options"
|
|
|
|
aria-label="Options"
|
|
|
|
aria-controls="options-menu"
|
2020-03-22 11:55:48 +00:00
|
|
|
aria-haspopup="true"
|
|
|
|
onClick={(e) => setOptionsAnchorEl(e.currentTarget)}
|
2020-03-20 11:33:13 +00:00
|
|
|
>
|
|
|
|
<MoreVertIcon />
|
|
|
|
</IconButton>
|
|
|
|
<Menu
|
2020-03-25 09:44:24 +00:00
|
|
|
id="options-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>
|
2020-03-30 14:01:38 +00:00
|
|
|
<MenuItem>
|
|
|
|
<FormControlLabel
|
|
|
|
label="Show hidden"
|
|
|
|
labelPlacement="start"
|
|
|
|
control={<Switch checked={showHidden} onChange={(_e, checked) => setShowHidden(checked)} />}
|
|
|
|
/>
|
|
|
|
</MenuItem>
|
2020-03-20 11:33:13 +00:00
|
|
|
</Menu>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|