1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Add headings and links to plugin pages

This commit is contained in:
Bill Thornton 2024-07-15 10:25:56 -04:00
parent f071ea2a1f
commit f0626465b0
5 changed files with 30 additions and 6 deletions

View file

@ -4,6 +4,8 @@ import { Link, useLocation, useSearchParams } from 'react-router-dom';
interface ListItemLinkProps extends ListItemButtonBaseProps {
to: string
includePaths?: string[]
excludePaths?: string[]
}
const isMatchingParams = (routeParams: URLSearchParams, currentParams: URLSearchParams) => {
@ -19,6 +21,8 @@ const isMatchingParams = (routeParams: URLSearchParams, currentParams: URLSearch
const ListItemLink: FC<ListItemLinkProps> = ({
children,
to,
includePaths = [],
excludePaths = [],
...params
}) => {
const location = useLocation();
@ -27,8 +31,11 @@ const ListItemLink: FC<ListItemLinkProps> = ({
const [ toPath, toParams ] = to.split('?');
// eslint-disable-next-line compat/compat
const toSearchParams = new URLSearchParams(`?${toParams}`);
const selectedPaths = [ toPath, ...includePaths ];
const selected = location.pathname === toPath && (!toParams || isMatchingParams(toSearchParams, searchParams));
const selected = selectedPaths.includes(location.pathname)
&& !excludePaths.includes(location.pathname + location.search)
&& (!toParams || isMatchingParams(toSearchParams, searchParams));
return (
<ListItemButton