Adds Sidebar icons to filter

This commit is contained in:
LIAUD Corentin
2024-03-24 17:00:36 +01:00
parent a7417a221a
commit 6ade9223a6
6 changed files with 67 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ import {
useTheme, useTheme,
} from '@material-ui/core' } from '@material-ui/core'
import { HighlightOff as HighlightOffIcon } from '@material-ui/icons' import { HighlightOff as HighlightOffIcon } from '@material-ui/icons'
import { TORRENT_CATEGORIES } from 'components/categories'
import { import {
ClearPosterButton, ClearPosterButton,
@@ -69,8 +70,6 @@ export default function RightSideComponent({
setIsUserInteractedWithPoster(true) setIsUserInteractedWithPoster(true)
} }
const torrentCategories = ['Movies', 'Series', 'Music', 'Other', 'Unknown']
return ( return (
<RightSide> <RightSide>
<RightSideContainer isHidden={!isTorrentSourceCorrect || (isHashAlreadyExists && !isEditMode)}> <RightSideContainer isHidden={!isTorrentSourceCorrect || (isHashAlreadyExists && !isEditMode)}>
@@ -151,8 +150,8 @@ export default function RightSideComponent({
fullWidth fullWidth
defaultValue='Unknown' defaultValue='Unknown'
> >
{torrentCategories.map(category => ( {TORRENT_CATEGORIES.map(category => (
<MenuItem value={category}>{category}</MenuItem> <MenuItem value={category.name}>{category.name}</MenuItem>
))} ))}
</Select> </Select>
</FormControl> </FormControl>

View File

@@ -11,10 +11,13 @@ import RemoveAll from 'components/RemoveAll'
import AboutDialog from 'components/About' import AboutDialog from 'components/About'
import CloseServer from 'components/CloseServer' import CloseServer from 'components/CloseServer'
import { memo } from 'react' import { memo } from 'react'
import CheckIcon from '@material-ui/icons/Check'
import { TORRENT_CATEGORIES } from 'components/categories'
import FilterByCategory from 'components/FilterByCategory'
import { AppSidebarStyle } from './style' import { AppSidebarStyle } from './style'
const Sidebar = ({ isDrawerOpen, setIsDonationDialogOpen, isOffline, isLoading }) => { const Sidebar = ({ isDrawerOpen, setIsDonationDialogOpen, isOffline, isLoading, setGlobalFilterCategory }) => {
const { t } = useTranslation() const { t } = useTranslation()
return ( return (
@@ -27,6 +30,20 @@ const Sidebar = ({ isDrawerOpen, setIsDonationDialogOpen, isOffline, isLoading }
<Divider /> <Divider />
<List>
<FilterByCategory categoryName='All' icon={<CheckIcon />} setGlobalFilterCategory={setGlobalFilterCategory} />
{TORRENT_CATEGORIES.map(category => (
<FilterByCategory
key={category.name}
categoryName={category.name}
icon={category.icon}
setGlobalFilterCategory={setGlobalFilterCategory}
/>
))}
</List>
<Divider />
<List> <List>
<SettingsDialog isOffline={isOffline} isLoading={isLoading} /> <SettingsDialog isOffline={isOffline} isLoading={isLoading} />

View File

@@ -43,6 +43,7 @@ export default function App() {
const [isDarkMode, currentThemeMode, updateThemeMode, muiTheme] = useMaterialUITheme() const [isDarkMode, currentThemeMode, updateThemeMode, muiTheme] = useMaterialUITheme()
const [currentLang, changeLang] = useChangeLanguage() const [currentLang, changeLang] = useChangeLanguage()
const [isOffline, setIsOffline] = useState(false) const [isOffline, setIsOffline] = useState(false)
const [globalCategoryFilter, setGlobalFilterCategory] = useState('All')
const { data: torrents, isLoading } = useQuery('torrents', getTorrents, { const { data: torrents, isLoading } = useQuery('torrents', getTorrents, {
retry: 1, retry: 1,
refetchInterval: 1000, refetchInterval: 1000,
@@ -126,9 +127,16 @@ export default function App() {
isLoading={isLoading} isLoading={isLoading}
isDrawerOpen={isDrawerOpen} isDrawerOpen={isDrawerOpen}
setIsDonationDialogOpen={setIsDonationDialogOpen} setIsDonationDialogOpen={setIsDonationDialogOpen}
setGlobalFilterCategory={setGlobalFilterCategory}
/> />
<TorrentList isOffline={isOffline} torrents={torrents} isLoading={isLoading} sortABC={sortABC} /> <TorrentList
isOffline={isOffline}
torrents={torrents}
isLoading={isLoading}
sortABC={sortABC}
sortCategory={globalCategoryFilter}
/>
<PWAFooter <PWAFooter
isOffline={isOffline} isOffline={isOffline}

View File

@@ -0,0 +1,19 @@
import ListItem from '@material-ui/core/ListItem'
import ListItemIcon from '@material-ui/core/ListItemIcon'
import ListItemText from '@material-ui/core/ListItemText'
export default function FilterByCategory({ categoryName, setGlobalFilterCategory, icon }) {
const onClick = () => {
setGlobalFilterCategory(categoryName)
}
return (
<>
<ListItem button key={categoryName} onClick={onClick}>
<ListItemIcon>{icon}</ListItemIcon>
<ListItemText primary={categoryName} />
</ListItem>
</>
)
}

View File

@@ -5,7 +5,7 @@ import { TorrentListWrapper, CenteredGrid } from 'components/App/style'
import NoServerConnection from './NoServerConnection' import NoServerConnection from './NoServerConnection'
import AddFirstTorrent from './AddFirstTorrent' import AddFirstTorrent from './AddFirstTorrent'
export default function TorrentList({ isOffline, isLoading, sortABC, torrents }) { export default function TorrentList({ isOffline, isLoading, sortABC, torrents, sortCategory }) {
if (isLoading || isOffline || !torrents.length) { if (isLoading || isOffline || !torrents.length) {
return ( return (
<CenteredGrid> <CenteredGrid>
@@ -20,9 +20,11 @@ export default function TorrentList({ isOffline, isLoading, sortABC, torrents })
) )
} }
const filteredTorrents = torrents.filter(torrent => sortCategory === 'All' || torrent.category === sortCategory)
return sortABC ? ( return sortABC ? (
<TorrentListWrapper> <TorrentListWrapper>
{torrents {filteredTorrents
.sort((a, b) => a.title > b.title) .sort((a, b) => a.title > b.title)
.map(torrent => ( .map(torrent => (
<TorrentCard key={torrent.hash} torrent={torrent} /> <TorrentCard key={torrent.hash} torrent={torrent} />
@@ -30,7 +32,7 @@ export default function TorrentList({ isOffline, isLoading, sortABC, torrents })
</TorrentListWrapper> </TorrentListWrapper>
) : ( ) : (
<TorrentListWrapper> <TorrentListWrapper>
{torrents.map(torrent => ( {filteredTorrents.map(torrent => (
<TorrentCard key={torrent.hash} torrent={torrent} /> <TorrentCard key={torrent.hash} torrent={torrent} />
))} ))}
</TorrentListWrapper> </TorrentListWrapper>

View File

@@ -0,0 +1,13 @@
import MovieCreationIcon from '@material-ui/icons/MovieCreation'
import LiveTvIcon from '@material-ui/icons/LiveTv'
import MusicNoteIcon from '@material-ui/icons/MusicNote'
import MoreHorizIcon from '@material-ui/icons/MoreHoriz'
import HelpIcon from '@material-ui/icons/Help'
export const TORRENT_CATEGORIES = [
{ name: 'Movies', icon: <MovieCreationIcon /> },
{ name: 'Series', icon: <LiveTvIcon /> },
{ name: 'Music', icon: <MusicNoteIcon /> },
{ name: 'Other', icon: <MoreHorizIcon /> },
{ name: 'Unknown', icon: <HelpIcon /> },
]