mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Merge pull request #5789 from thornbill/update-plugin-headings
Add headings and links to plugin pages
This commit is contained in:
commit
845d237200
5 changed files with 30 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue