mirror of
https://github.com/Radarr/Radarr
synced 2026-01-26 01:12:11 +01:00
(cherry picked from commit e1cbc4a78249881de96160739a50c0a399ea4313) Closes #10378 Fixed: Links tooltip closing too quickly (cherry picked from commit 0b9a212f33381d07ff67e2453753aaab64cc8041) Closes #10400 Fixed: Movie links not opening on iOS (cherry picked from commit f20ac9dc348e1f5ded635f12ab925d982b1b8957) Closes #10425
38 lines
914 B
TypeScript
38 lines
914 B
TypeScript
import React, { Children, ReactElement, ReactNode } from 'react';
|
|
import { Switch as RouterSwitch } from 'react-router-dom';
|
|
import getPathWithUrlBase from 'Utilities/getPathWithUrlBase';
|
|
|
|
interface ExtendedRoute {
|
|
path: string;
|
|
addUrlBase?: boolean;
|
|
}
|
|
|
|
interface SwitchProps {
|
|
children: ReactNode;
|
|
}
|
|
|
|
function Switch({ children }: SwitchProps) {
|
|
return (
|
|
<RouterSwitch>
|
|
{Children.map(children, (child) => {
|
|
if (!React.isValidElement<ExtendedRoute>(child)) {
|
|
return child;
|
|
}
|
|
|
|
const elementChild: ReactElement<ExtendedRoute> = child;
|
|
|
|
const { path: childPath, addUrlBase = true } = elementChild.props;
|
|
|
|
if (!childPath) {
|
|
return child;
|
|
}
|
|
|
|
const path = addUrlBase ? getPathWithUrlBase(childPath) : childPath;
|
|
|
|
return React.cloneElement(child, { path });
|
|
})}
|
|
</RouterSwitch>
|
|
);
|
|
}
|
|
|
|
export default Switch;
|