movie-web/src3/views/notfound/NotFoundChecks.tsx

30 lines
753 B
TypeScript
Raw Normal View History

2022-03-06 12:56:22 +01:00
import { getProviderMetadata, MWPortableMedia } from "providers";
2022-03-06 13:42:27 +01:00
import { ReactElement } from "react";
2022-03-06 12:56:22 +01:00
import { NotFoundMedia, NotFoundProvider } from "./NotFoundView";
export interface NotFoundChecksProps {
portable: MWPortableMedia | undefined;
2022-03-06 13:42:27 +01:00
children?: ReactElement;
2022-03-06 12:56:22 +01:00
}
/*
** Component that only renders children if the passed-in portable is fully correct
*/
2022-03-06 13:42:27 +01:00
export function NotFoundChecks(
props: NotFoundChecksProps
): ReactElement | null {
2022-03-06 12:56:22 +01:00
const providerMeta = props.portable
? getProviderMetadata(props.portable.providerId)
: undefined;
if (!providerMeta || !providerMeta.exists) {
return <NotFoundMedia />;
}
if (!providerMeta.enabled) {
return <NotFoundProvider />;
}
2022-03-06 13:42:27 +01:00
return props.children || null;
2022-03-06 12:56:22 +01:00
}