From ec9d8d33299a48f99630458062189d6ad5bcefd1 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 17 Mar 2020 13:23:45 +0200 Subject: [PATCH] Revert "Tasks: adds filter by tag feature" Reverting because I'm not the author. The next commit will have the right author set. This reverts commit b14697474c0628041bc1c0e01987ee5f2d6b24ef. --- src/components/Tasks/Sidebar.tsx | 62 --------------------------- src/components/Tasks/TaskList.tsx | 70 +++++++++---------------------- src/store/reducers.ts | 16 ++----- src/widgets/List.tsx | 3 -- 4 files changed, 23 insertions(+), 128 deletions(-) delete mode 100644 src/components/Tasks/Sidebar.tsx diff --git a/src/components/Tasks/Sidebar.tsx b/src/components/Tasks/Sidebar.tsx deleted file mode 100644 index 69fff91..0000000 --- a/src/components/Tasks/Sidebar.tsx +++ /dev/null @@ -1,62 +0,0 @@ -import * as React from 'react'; - -import { useSelector, useDispatch } from 'react-redux'; - -import InboxIcon from '@material-ui/icons/Inbox'; -import LabelIcon from '@material-ui/icons/LabelOutlined'; - -import { setSettings } from '../../store/actions'; -import { StoreState } from '../../store'; - -import { List, ListItem, ListSubheader } from '../../widgets/List'; - -interface ListItemPropsType { - name: string | null; - icon?: React.ReactElement; - primaryText: string; - amount?: number; -} - -function SidebarListItem(props: ListItemPropsType) { - const { name, icon, primaryText, amount } = props; - const dispatch = useDispatch(); - const taskSettings = useSelector((state: StoreState) => state.settings.taskSettings); - const { filterBy } = taskSettings; - - const handleClick = () => { - dispatch(setSettings({ taskSettings: { ...taskSettings, filterBy: name } })); - }; - - return ( - {amount}} - primaryText={primaryText} - /> - ); -} - -export default function Sidebar(props: { tags: Map, totalTasks: number }) { - const { tags, totalTasks } = props; - - const tagsList = [...tags].sort(([a], [b]) => a.localeCompare(b)).map(([tag, amount]) => ( - } - amount={amount} - /> - )); - - return ( - - } amount={totalTasks} /> - - Tags - {tagsList} - - ); -} \ No newline at end of file diff --git a/src/components/Tasks/TaskList.tsx b/src/components/Tasks/TaskList.tsx index 3b5559c..1b3e065 100644 --- a/src/components/Tasks/TaskList.tsx +++ b/src/components/Tasks/TaskList.tsx @@ -13,16 +13,9 @@ import { TaskType, PimType } from '../../pim-types'; import FormControlLabel from '@material-ui/core/FormControlLabel'; import Checkbox from '@material-ui/core/Checkbox'; import Divider from '@material-ui/core/Divider'; -import Grid from '@material-ui/core/Grid'; -import { useTheme } from '@material-ui/core/styles'; - -import { useSelector } from 'react-redux'; import TaskListItem from './TaskListItem'; import QuickAdd from './QuickAdd'; -import Sidebar from './Sidebar'; - -import { StoreState } from '../../store'; const sortSelector = createSelector( (entries: TaskType[]) => entries, @@ -38,26 +31,7 @@ interface PropsType { export default React.memo(function TaskList(props: PropsType) { const [showCompleted, setShowCompleted] = React.useState(false); - const settings = useSelector((state: StoreState) => state.settings.taskSettings); - const { filterBy } = settings; - const theme = useTheme(); - - const potentialEntries = props.entries.filter((x) => showCompleted || !x.finished); - let entries; - const tagPrefix = 'tag:'; - if (filterBy?.startsWith(tagPrefix)) { - const tag = filterBy.slice(tagPrefix.length); - entries = potentialEntries.filter((x) => x.tags.includes(tag)); - } else { - entries = potentialEntries; - } - - // TODO: memoize - const tags = new Map(); - potentialEntries.forEach((entry) => entry.tags.forEach((tag) => { - tags.set(tag, (tags.get(tag) ?? 0) + 1); - })); - + const entries = props.entries.filter((x) => showCompleted || !x.finished); const sortedEntries = sortSelector(entries); const itemList = sortedEntries.map((entry) => { @@ -74,29 +48,23 @@ export default React.memo(function TaskList(props: PropsType) { }); return ( - - - - - - - -
- {props.collections && } - - setShowCompleted(!showCompleted)} /> - } - label="Show Completed" - /> -
- - - - {itemList} - -
-
+ <> + +
+ {props.collections && } + + setShowCompleted(!showCompleted)} /> + } + label="Show Completed" + /> +
+ + + + {itemList} + + ); }); diff --git a/src/store/reducers.ts b/src/store/reducers.ts index 9480459..59e8c15 100644 --- a/src/store/reducers.ts +++ b/src/store/reducers.ts @@ -28,13 +28,13 @@ export type UserInfoData = EteSync.UserInfo; export const encryptionKeyReducer = handleActions( { - [actions.deriveKey.toString()]: (_state: { key: string | null }, action: any) => ( + [actions.deriveKey.toString()]: (_state: {key: string | null}, action: any) => ( { key: action.payload } ), - [actions.resetKey.toString()]: (_state: { key: string | null }, _action: any) => ( + [actions.resetKey.toString()]: (_state: {key: string | null}, _action: any) => ( { key: null } ), - [actions.logout.toString()]: (_state: { key: string | null }, _action: any) => { + [actions.logout.toString()]: (_state: {key: string | null}, _action: any) => { return { out: true, key: null }; }, }, @@ -272,9 +272,6 @@ export const errorsReducer = handleActions( // FIXME Move all the below (potentially the fetchCount ones too) to their own file export interface SettingsType { locale: string; - taskSettings: { - filterBy: string | null; - }; } export const settingsReducer = handleActions( @@ -283,10 +280,5 @@ export const settingsReducer = handleActions( { ...state, ...action.payload } ), }, - { - locale: 'en-gb', - taskSettings: { - filterBy: null, - }, - } + { locale: 'en-gb' } ); diff --git a/src/widgets/List.tsx b/src/widgets/List.tsx index d9af26e..53e96c2 100644 --- a/src/widgets/List.tsx +++ b/src/widgets/List.tsx @@ -45,7 +45,6 @@ interface ListItemPropsType { href?: string; insetChildren?: boolean; nestedItems?: React.ReactNode[]; - selected?: boolean; } export const ListItem = React.memo(function ListItem(_props: ListItemPropsType) { @@ -61,7 +60,6 @@ export const ListItem = React.memo(function ListItem(_props: ListItemPropsType) style, insetChildren, nestedItems, - selected, } = _props; const extraProps = (onClick || href) ? { @@ -76,7 +74,6 @@ export const ListItem = React.memo(function ListItem(_props: ListItemPropsType) {leftIcon && (