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'; import SortIcon from '@material-ui/icons/Sort'; import QuickAdd from './QuickAdd'; import { PimType } from '../../pim-types'; import { useSelector, useDispatch } from 'react-redux'; import { setSettings } from '../../store/actions'; import { StoreState } from '../../store'; import Menu from '../../widgets/Menu'; interface PropsType { defaultCollection: EteSync.CollectionInfo; onItemSave: (item: PimType, journalUid: string, originalItem?: PimType) => Promise; showCompleted: boolean; setShowCompleted: (completed: boolean) => void; } export default function Toolbar(props: PropsType) { const { defaultCollection, onItemSave, showCompleted, setShowCompleted } = props; const [sortAnchorEl, setSortAnchorEl] = React.useState(null); const [optionsAnchorEl, setOptionsAnchorEl] = React.useState(null); const dispatch = useDispatch(); const taskSettings = useSelector((state: StoreState) => state.settings.taskSettings); const { sortBy } = taskSettings; const handleSortChange = (sort: string) => { dispatch(setSettings({ taskSettings: { ...taskSettings, sortBy: sort } })); setSortAnchorEl(null); }; const SortMenuItem = React.forwardRef(function SortMenuItem(props: { name: string, label: string }, ref) { return ( handleSortChange(props.name)}>{props.label} ); }); return (
{defaultCollection && }
setSortAnchorEl(e.currentTarget)} > setSortAnchorEl(null)} >
setOptionsAnchorEl(e.currentTarget)} > setOptionsAnchorEl(null)} > setShowCompleted(checked)} />} />
); }