Introduce isPublic prop in Shell (#2437)

Co-authored-by: zomars <zomars@me.com>
This commit is contained in:
Afzal Sayed 2022-04-12 10:08:10 +05:30 committed by GitHub
parent a3e0d0aec9
commit 4c5ae567e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 8 deletions

View file

@ -53,14 +53,14 @@ export function useMeQuery() {
return meQuery; return meQuery;
} }
function useRedirectToLoginIfUnauthenticated() { function useRedirectToLoginIfUnauthenticated(isPublic = false) {
const { data: session, status } = useSession(); const { data: session, status } = useSession();
const loading = status === "loading"; const loading = status === "loading";
const router = useRouter(); const router = useRouter();
const shouldDisplayUnauthed = router.pathname.startsWith("/apps"); const shouldDisplayUnauthed = router.pathname.startsWith("/apps");
useEffect(() => { useEffect(() => {
if (shouldDisplayUnauthed) { if (isPublic) {
return; return;
} }
@ -73,7 +73,7 @@ function useRedirectToLoginIfUnauthenticated() {
}); });
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [loading, session]); }, [loading, session, isPublic]);
return { return {
loading: loading && !session, loading: loading && !session,
@ -133,10 +133,11 @@ export default function Shell(props: {
backPath?: string; // renders back button to specified path backPath?: string; // renders back button to specified path
// use when content needs to expand with flex // use when content needs to expand with flex
flexChildrenContainer?: boolean; flexChildrenContainer?: boolean;
isPublic?: boolean;
}) { }) {
const { t } = useLocale(); const { t } = useLocale();
const router = useRouter(); const router = useRouter();
const { loading, shouldDisplayUnauthed, session } = useRedirectToLoginIfUnauthenticated(); const { loading, session } = useRedirectToLoginIfUnauthenticated(props.isPublic);
const { isRedirectingToOnboarding } = useRedirectToOnboardingIfNeeded(); const { isRedirectingToOnboarding } = useRedirectToOnboardingIfNeeded();
const telemetry = useTelemetry(); const telemetry = useTelemetry();
@ -209,7 +210,7 @@ export default function Shell(props: {
); );
} }
if (!session && !shouldDisplayUnauthed) return null; if (!session && !props.isPublic) return null;
return ( return (
<> <>

View file

@ -15,7 +15,7 @@ export default function Apps({ appStore }: InferGetStaticPropsType<typeof getSta
return ( return (
<> <>
<Shell large> <Shell isPublic large>
<div className="-mx-4 md:-mx-8"> <div className="-mx-4 md:-mx-8">
<div className="mb-10 bg-gray-50 px-4 pb-2"> <div className="mb-10 bg-gray-50 px-4 pb-2">
<Link href="/apps"> <Link href="/apps">

View file

@ -12,7 +12,7 @@ export default function Apps({ categories }: InferGetStaticPropsType<typeof getS
const { t } = useLocale(); const { t } = useLocale();
return ( return (
<Shell large> <Shell isPublic large>
<div className="-mx-4 md:-mx-8"> <div className="-mx-4 md:-mx-8">
<div className="mb-10 bg-gray-50 px-4 pb-2"> <div className="mb-10 bg-gray-50 px-4 pb-2">
<Link href="/apps"> <Link href="/apps">

View file

@ -13,7 +13,7 @@ export default function Apps({ appStore, categories }: InferGetStaticPropsType<t
const { t } = useLocale(); const { t } = useLocale();
return ( return (
<Shell heading={t("app_store")} subtitle={t("app_store_description")} large> <Shell heading={t("app_store")} subtitle={t("app_store_description")} large isPublic>
<AppsShell> <AppsShell>
<AppStoreCategories categories={categories} /> <AppStoreCategories categories={categories} />
<TrendingAppsSlider items={appStore} /> <TrendingAppsSlider items={appStore} />