-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added filter by filesystem loc+overflow filt ttip
- Loading branch information
Showing
10 changed files
with
294 additions
and
22 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
client/src/javascript/components/sidebar/LocationFilters.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import {FC, KeyboardEvent, MouseEvent, ReactNode, TouchEvent} from 'react'; | ||
import {observer} from 'mobx-react'; | ||
import {useLingui} from '@lingui/react'; | ||
import {LocationTreeNode} from '@shared/types/Taxonomy'; | ||
|
||
import SidebarFilter from './SidebarFilter'; | ||
import TorrentFilterStore from '../../stores/TorrentFilterStore'; | ||
|
||
const LocationFilters: FC = observer(() => { | ||
const {i18n} = useLingui(); | ||
|
||
const locations = Object.keys(TorrentFilterStore.taxonomy.locationCounts); | ||
|
||
if (locations.length === 1 && locations[0] === '') { | ||
return null; | ||
} | ||
|
||
const buildLocationFilterTree = (location: LocationTreeNode): ReactNode => { | ||
if ( | ||
location.children.length === 1 && | ||
TorrentFilterStore.taxonomy.locationCounts[location.fullPath] === | ||
TorrentFilterStore.taxonomy.locationCounts[location.children[0].fullPath] | ||
) { | ||
const onlyChild = location.children[0]; | ||
const separator = onlyChild.fullPath.includes('/') ? '/' : '\\'; | ||
return buildLocationFilterTree({ | ||
...onlyChild, | ||
directoryName: location.directoryName + separator + onlyChild.directoryName, | ||
}); | ||
} | ||
|
||
const children = location.children.map(buildLocationFilterTree); | ||
|
||
return ( | ||
<SidebarFilter | ||
handleClick={(filter: string | '', event: KeyboardEvent | MouseEvent | TouchEvent) => | ||
TorrentFilterStore.setLocationFilters(filter, event) | ||
} | ||
count={TorrentFilterStore.taxonomy.locationCounts[location.fullPath] || 0} | ||
key={location.fullPath} | ||
isActive={ | ||
(location.fullPath === '' && !TorrentFilterStore.locationFilter.length) || | ||
TorrentFilterStore.locationFilter.includes(location.fullPath) | ||
} | ||
name={location.directoryName} | ||
slug={location.fullPath} | ||
size={TorrentFilterStore.taxonomy.locationSizes[location.fullPath]} | ||
> | ||
{(children.length && children) || undefined} | ||
</SidebarFilter> | ||
); | ||
}; | ||
|
||
const filterElements = TorrentFilterStore.taxonomy.locationTree.map(buildLocationFilterTree); | ||
|
||
const title = i18n._('filter.location.title'); | ||
|
||
return ( | ||
<ul aria-label={title} className="sidebar-filter sidebar__item" role="menu"> | ||
<li className="sidebar-filter__item sidebar-filter__item--heading" role="none"> | ||
{title} | ||
</li> | ||
{filterElements} | ||
</ul> | ||
); | ||
}); | ||
|
||
export default LocationFilters; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.