mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-26 06:31:53 +01:00
30 lines
753 B
TypeScript
30 lines
753 B
TypeScript
import { getProviderMetadata, MWPortableMedia } from "providers";
|
|
import { ReactElement } from "react";
|
|
import { NotFoundMedia, NotFoundProvider } from "./NotFoundView";
|
|
|
|
export interface NotFoundChecksProps {
|
|
portable: MWPortableMedia | undefined;
|
|
children?: ReactElement;
|
|
}
|
|
|
|
/*
|
|
** Component that only renders children if the passed-in portable is fully correct
|
|
*/
|
|
export function NotFoundChecks(
|
|
props: NotFoundChecksProps
|
|
): ReactElement | null {
|
|
const providerMeta = props.portable
|
|
? getProviderMetadata(props.portable.providerId)
|
|
: undefined;
|
|
|
|
if (!providerMeta || !providerMeta.exists) {
|
|
return <NotFoundMedia />;
|
|
}
|
|
|
|
if (!providerMeta.enabled) {
|
|
return <NotFoundProvider />;
|
|
}
|
|
|
|
return props.children || null;
|
|
}
|