Skip to content

Commit

Permalink
feat: tab space resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
hiporox committed Jul 11, 2024
1 parent db1dd29 commit 12d57d8
Showing 1 changed file with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ 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";

type SpacePageProps = {
spaceId: string | null;
fid: number | null;
handle: string | string[] | undefined;
tabName: string | string[] | undefined;
};

export const getServerSideProps = (async ({
Expand All @@ -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 },
Expand All @@ -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);
Expand All @@ -51,6 +71,7 @@ export const getServerSideProps = (async ({
spaceId: spaceRegistration.spaceId,
fid: user.fid,
handle,
tabName: tabName,
},
};
}
Expand All @@ -61,6 +82,7 @@ export const getServerSideProps = (async ({
spaceId: null,
fid: user.fid,
handle,
tabName: tabName,
},
};
} catch (e) {
Expand All @@ -70,6 +92,7 @@ export const getServerSideProps = (async ({
spaceId: null,
fid: null,
handle,
tabName: tabName,
},
};
}
Expand All @@ -78,6 +101,7 @@ export const getServerSideProps = (async ({
const UserPrimarySpace: NextPageWithLayout = ({
spaceId,
fid,
tabName,
}: SpacePageProps) => {
const { loadEditableSpaces } = useAppStore((state) => ({
loadEditableSpaces: state.space.loadEditableSpaces,
Expand All @@ -87,8 +111,11 @@ const UserPrimarySpace: NextPageWithLayout = ({
loadEditableSpaces();
}, []);

console.log(spaceId, fid, tabName);

if (!isNil(fid)) {
return <UserDefinedSpace fid={fid} spaceId={spaceId} />;
if ((isNil(spaceId) && tabName === "profile") || !isNil(spaceId))
return <UserDefinedSpace fid={fid} spaceId={spaceId} />;
}

return <SpaceNotFound />;
Expand Down

0 comments on commit 12d57d8

Please sign in to comment.