From a744ce1ac229b45f6054c8c019589f8ac289c468 Mon Sep 17 00:00:00 2001 From: robo <30987265+Robonau@users.noreply.github.com> Date: Fri, 4 Mar 2022 01:35:16 +0000 Subject: [PATCH] Update LibraryOptions.tsx --- src/components/library/LibraryOptions.tsx | 179 +++++----------------- 1 file changed, 38 insertions(+), 141 deletions(-) diff --git a/src/components/library/LibraryOptions.tsx b/src/components/library/LibraryOptions.tsx index c6d111c0b3..c9a4130aac 100644 --- a/src/components/library/LibraryOptions.tsx +++ b/src/components/library/LibraryOptions.tsx @@ -6,101 +6,26 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import React, { useState } from 'react'; +import React from 'react'; import FilterListIcon from '@mui/icons-material/FilterList'; +import SortIcon from '@mui/icons-material/Sort'; import { - Drawer, - FormControlLabel, - IconButton, - Tabs, - Tab, - Box, - Stack, - Checkbox, - Radio, - Switch, + Drawer, FormControlLabel, IconButton, ListItem, ListItemButton, ListItemIcon, ListItemText, } from '@mui/material'; import useLibraryOptions from 'util/useLibraryOptions'; import ThreeStateCheckbox from 'components/util/ThreeStateCheckbox'; -import TabPanel from 'components/util/TabPanel'; -import { useLibraryOptionsContext } from 'components/context/LibraryOptionsContext'; -import SortIcon from '@mui/icons-material/Sort'; +import { Box } from '@mui/system'; +import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward'; +import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward'; function Options() { const { downloaded, setDownloaded, unread, setUnread, } = useLibraryOptions(); - const [currentTab, setCurrentTab] = useState(0); - const { options, setOptions } = useLibraryOptionsContext(); - - function setContextOptions( - e: React.ChangeEvent, - checked: boolean, - ) { - setOptions((prev) => ({ ...prev, [e.target.name]: checked })); - } - return ( - - setCurrentTab(newTab)} - indicatorColor="primary" - textColor="primary" - > - - - - - - - )} - label="Unread" - /> - - )} - label="Downloaded" - /> - - - - - - )} - /> - - )} - /> - - + + } label="Unread" /> + } label="Downloaded" /> ); } @@ -110,58 +35,35 @@ function SortOptions() { sorts, setSorts, sortDesc, setSortDesc, } = useLibraryOptions(); - const handleSortChange = (name: string) => (event: { target: { checked: boolean } }) => { - setSorts(event.target.checked ? name : undefined); - }; - - const handleOrderChange = () => (event: { target: { checked: boolean } }) => { - setSortDesc(event.target.checked); + const handleChange = (event: + React.MouseEvent, index: string) => { + if (sorts === index) { + setSortDesc(!sortDesc); + } else { setSortDesc(false); } + setSorts(index); }; return ( - - - )} - label="Asc/Desc" - /> - - )} - label="Sort by left to read" - /> - - )} - label="Sort alphbetical" - /> - - )} - label="Sort by ID" - /> - + <> + { + ['sortToRead', 'sortAlph', 'sortID'].map((e) => { + let icon; + if (sorts === e) { + icon = !sortDesc ? () + : (); + } + icon = icon === undefined && sortDesc === undefined && e === 'sortID' ? () : icon; + return ( + + handleChange(event, e)}> + {icon} + + + + ); + }) + } + ); } @@ -184,10 +86,7 @@ export default function LibraryOptions() { onClose={() => setFiltersOpen(false)} PaperProps={{ style: { - maxWidth: 600, - padding: '1em', - marginLeft: 'auto', - marginRight: 'auto', + maxWidth: 600, padding: '1em', marginLeft: 'auto', marginRight: 'auto', }, }} > @@ -207,15 +106,13 @@ export default function LibraryOptions() { onClose={() => setSortsOpen(false)} PaperProps={{ style: { - maxWidth: 600, - padding: '1em', - marginLeft: 'auto', - marginRight: 'auto', + maxWidth: 600, padding: '1em', marginLeft: 'auto', marginRight: 'auto', }, }} > + ); }