From f7ffc873cac46f7823e42598f03c054fc646f2e9 Mon Sep 17 00:00:00 2001 From: Julian Early Date: Thu, 11 Jul 2024 13:23:46 -0700 Subject: [PATCH] feat: tab space resolution --- .../[[...tabName]].tsx} | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) rename src/pages/s/{[handle].tsx => [handle]/[[...tabName]].tsx} (73%) diff --git a/src/pages/s/[handle].tsx b/src/pages/s/[handle]/[[...tabName]].tsx similarity index 73% rename from src/pages/s/[handle].tsx rename to src/pages/s/[handle]/[[...tabName]].tsx index ec2c53ca..30c5b16d 100644 --- a/src/pages/s/[handle].tsx +++ b/src/pages/s/[handle]/[[...tabName]].tsx @@ -5,7 +5,7 @@ import { useAppStore } from "@/common/data/stores/app"; import { first, isArray, isNil, isNull, isUndefined } from "lodash"; import { GetServerSideProps, GetServerSidePropsContext } from "next"; import { useEffect } from "react"; -import { NextPageWithLayout } from "../_app"; +import { NextPageWithLayout } from "@/pages/_app"; import UserDefinedSpace from "@/common/components/pages/UserDefinedSpace"; import SpaceNotFound from "@/common/components/pages/SpaceNotFound"; @@ -13,6 +13,7 @@ type SpacePageProps = { spaceId: string | null; fid: number | null; handle: string | string[] | undefined; + tabName: string | string[] | undefined; }; export const getServerSideProps = (async ({ @@ -22,16 +23,35 @@ export const getServerSideProps = (async ({ isUndefined(params) || isUndefined(params.handle) || isArray(params.handle) ? null : params.handle; + + const tabNameParam = isUndefined(params) + ? undefined + : (params.tabName as string[]); + if (isNull(handle)) { return { props: { spaceId: null, fid: null, handle: isUndefined(params) ? params : params.handle, + tabName: isUndefined(params) ? params : params.tabName, }, }; } + if (isArray(tabNameParam) && tabNameParam.length > 1) { + return { + props: { + spaceId: null, + fid: null, + handle: isUndefined(params) ? params : params.handle, + tabName: tabNameParam, + }, + }; + } + + const tabName = isUndefined(tabNameParam) ? "profile" : tabNameParam[0]; + try { const { result: { user }, @@ -41,7 +61,7 @@ export const getServerSideProps = (async ({ .from("spaceRegistrations") .select("spaceId") .eq("fid", user.fid) - .eq("isDefault", true); + .eq("spaceName", tabName); if (data) { const spaceRegistration = first(data); @@ -51,6 +71,7 @@ export const getServerSideProps = (async ({ spaceId: spaceRegistration.spaceId, fid: user.fid, handle, + tabName: tabName, }, }; } @@ -61,6 +82,7 @@ export const getServerSideProps = (async ({ spaceId: null, fid: user.fid, handle, + tabName: tabName, }, }; } catch (e) { @@ -70,6 +92,7 @@ export const getServerSideProps = (async ({ spaceId: null, fid: null, handle, + tabName: tabName, }, }; } @@ -78,6 +101,7 @@ export const getServerSideProps = (async ({ const UserPrimarySpace: NextPageWithLayout = ({ spaceId, fid, + tabName, }: SpacePageProps) => { const { loadEditableSpaces } = useAppStore((state) => ({ loadEditableSpaces: state.space.loadEditableSpaces, @@ -87,8 +111,11 @@ const UserPrimarySpace: NextPageWithLayout = ({ loadEditableSpaces(); }, []); + console.log(spaceId, fid, tabName); + if (!isNil(fid)) { - return ; + if ((isNil(spaceId) && tabName === "profile") || !isNil(spaceId)) + return ; } return ;