Introduce isPublic prop in Shell (#2437)

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

View File

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

View File

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

View File

@ -13,7 +13,7 @@ export default function Apps({ appStore, categories }: InferGetStaticPropsType<t
const { t } = useLocale();
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>
<AppStoreCategories categories={categories} />
<TrendingAppsSlider items={appStore} />