session issues
This commit is contained in:
parent
0d2a392b52
commit
13cfd04f87
1 changed files with 140 additions and 142 deletions
|
@ -26,6 +26,7 @@ import { RiVipCrownFill } from "react-icons/ri";
|
||||||
import { env } from "~/env.mjs";
|
import { env } from "~/env.mjs";
|
||||||
import { downloadCSV } from "~/utils/helpers";
|
import { downloadCSV } from "~/utils/helpers";
|
||||||
import type { PresenceItem } from "~/utils/types";
|
import type { PresenceItem } from "~/utils/types";
|
||||||
|
import { Session } from "next-auth";
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||||
const session = await getServerAuthSession(ctx);
|
const session = await getServerAuthSession(ctx);
|
||||||
|
@ -46,7 +47,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const Room: NextPage = () => {
|
const Room: NextPage<{ session: Session }> = ({ session }) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
|
@ -55,7 +56,7 @@ const Room: NextPage = () => {
|
||||||
<meta http-equiv="Cache-control" content="no-cache" />
|
<meta http-equiv="Cache-control" content="no-cache" />
|
||||||
</Head>
|
</Head>
|
||||||
<div className="flex flex-col items-center justify-center text-center gap-2">
|
<div className="flex flex-col items-center justify-center text-center gap-2">
|
||||||
<RoomBody />
|
<RoomBody session={session} />
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -63,8 +64,7 @@ const Room: NextPage = () => {
|
||||||
|
|
||||||
export default Room;
|
export default Room;
|
||||||
|
|
||||||
const RoomBody: React.FC = () => {
|
const RoomBody: React.FC<{ session: Session }> = ({ session }) => {
|
||||||
const { data: sessionData } = useSession();
|
|
||||||
const { query } = useRouter();
|
const { query } = useRouter();
|
||||||
const roomId = z.string().parse(query.id);
|
const roomId = z.string().parse(query.id);
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ const RoomBody: React.FC = () => {
|
||||||
|
|
||||||
configureAbly({
|
configureAbly({
|
||||||
key: env.NEXT_PUBLIC_ABLY_PUBLIC_KEY,
|
key: env.NEXT_PUBLIC_ABLY_PUBLIC_KEY,
|
||||||
clientId: sessionData?.user.id,
|
clientId: session.user.id,
|
||||||
recover: (_, cb) => {
|
recover: (_, cb) => {
|
||||||
cb(true);
|
cb(true);
|
||||||
},
|
},
|
||||||
|
@ -106,10 +106,10 @@ const RoomBody: React.FC = () => {
|
||||||
const [presenceData] = usePresence<PresenceItem>(
|
const [presenceData] = usePresence<PresenceItem>(
|
||||||
`${env.NEXT_PUBLIC_APP_ENV}-${roomId}`,
|
`${env.NEXT_PUBLIC_APP_ENV}-${roomId}`,
|
||||||
{
|
{
|
||||||
name: sessionData?.user.name || "",
|
name: session.user.name || "",
|
||||||
image: sessionData?.user.image || "",
|
image: session.user.image || "",
|
||||||
client_id: sessionData?.user.id || "",
|
client_id: session.user.id || "",
|
||||||
role: sessionData?.user.role || "USER",
|
role: session.user.role || "USER",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -126,18 +126,18 @@ const RoomBody: React.FC = () => {
|
||||||
|
|
||||||
// Init story name
|
// Init story name
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (sessionData && roomFromDb) {
|
if (session && roomFromDb) {
|
||||||
setStoryNameText(roomFromDb.storyName || "");
|
setStoryNameText(roomFromDb.storyName || "");
|
||||||
setRoomScale(roomFromDb.scale || "ERROR");
|
setRoomScale(roomFromDb.scale || "ERROR");
|
||||||
}
|
}
|
||||||
}, [roomFromDb, roomId, sessionData]);
|
}, [roomFromDb, roomId, session]);
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
const getVoteForCurrentUser = () => {
|
const getVoteForCurrentUser = () => {
|
||||||
if (roomFromDb && sessionData) {
|
if (roomFromDb && session) {
|
||||||
return (
|
return (
|
||||||
votesFromDb &&
|
votesFromDb &&
|
||||||
votesFromDb.find((vote) => vote.userId === sessionData.user.id)
|
votesFromDb.find((vote) => vote.userId === session.user.id)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -224,7 +224,7 @@ const RoomBody: React.FC = () => {
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
if (!!matchedVote) {
|
if (!!matchedVote) {
|
||||||
return <p>{ matchedVote.value }</p>;
|
return <p>{matchedVote.value}</p>;
|
||||||
} else {
|
} else {
|
||||||
return <IoHourglassOutline className="text-xl mx-auto text-red-400" />;
|
return <IoHourglassOutline className="text-xl mx-auto text-red-400" />;
|
||||||
}
|
}
|
||||||
|
@ -243,39 +243,39 @@ const RoomBody: React.FC = () => {
|
||||||
if (roomFromDb === undefined) {
|
if (roomFromDb === undefined) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center justify-center text-center">
|
<div className="flex flex-col items-center justify-center text-center">
|
||||||
<span className="loading loading-dots loading-lg"></span>{ " " }
|
<span className="loading loading-dots loading-lg"></span>{" "}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
// Room has been loaded
|
// Room has been loaded
|
||||||
} else if (roomFromDb) {
|
} else if (roomFromDb) {
|
||||||
return (
|
return (
|
||||||
<span className="text-center">
|
<span className="text-center">
|
||||||
<div className="text-2xl">{ roomFromDb.roomName }</div>
|
<div className="text-2xl">{roomFromDb.roomName}</div>
|
||||||
<div className="flex flex-row flex-wrap text-center justify-center items-center gap-1 text-md mx-auto">
|
<div className="flex flex-row flex-wrap text-center justify-center items-center gap-1 text-md mx-auto">
|
||||||
<div>ID:</div>
|
<div>ID:</div>
|
||||||
<div>{ roomFromDb.id }</div>
|
<div>{roomFromDb.id}</div>
|
||||||
|
|
||||||
<button>
|
<button>
|
||||||
{ copied ? (
|
{copied ? (
|
||||||
<IoCheckmarkCircleOutline className="mx-1 text-green-400 animate-bounce" />
|
<IoCheckmarkCircleOutline className="mx-1 text-green-400 animate-bounce" />
|
||||||
) : (
|
) : (
|
||||||
<IoCopyOutline
|
<IoCopyOutline
|
||||||
className="mx-1 hover:text-primary"
|
className="mx-1 hover:text-primary"
|
||||||
onClick={ copyRoomURLHandler }
|
onClick={copyRoomURLHandler}
|
||||||
></IoCopyOutline>
|
></IoCopyOutline>
|
||||||
) }
|
)}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{ roomFromDb && (
|
{roomFromDb && (
|
||||||
<div className="card card-compact bg-neutral shadow-xl mx-auto m-4">
|
<div className="card card-compact bg-neutral shadow-xl mx-auto m-4">
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
<h2 className="card-title mx-auto">
|
<h2 className="card-title mx-auto">
|
||||||
Story: { roomFromDb.storyName }
|
Story: {roomFromDb.storyName}
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<ul className="p-0 mx-auto flex flex-row flex-wrap justify-center items-center text-ceter gap-4">
|
<ul className="p-0 mx-auto flex flex-row flex-wrap justify-center items-center text-ceter gap-4">
|
||||||
{ presenceData &&
|
{presenceData &&
|
||||||
presenceData
|
presenceData
|
||||||
.filter(
|
.filter(
|
||||||
(value, index, self) =>
|
(value, index, self) =>
|
||||||
|
@ -288,176 +288,174 @@ const RoomBody: React.FC = () => {
|
||||||
.map((presenceItem) => {
|
.map((presenceItem) => {
|
||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
key={ presenceItem.clientId }
|
key={presenceItem.clientId}
|
||||||
className="flex flex-row items-center justify-center gap-2"
|
className="flex flex-row items-center justify-center gap-2"
|
||||||
>
|
>
|
||||||
<div className="w-10 rounded-full avatar mx-auto">
|
<div className="w-10 rounded-full avatar mx-auto">
|
||||||
<Image
|
<Image
|
||||||
src={ presenceItem.data.image }
|
src={presenceItem.data.image}
|
||||||
alt={ `${presenceItem.data.name}'s Profile Picture` }
|
alt={`${presenceItem.data.name}'s Profile Picture`}
|
||||||
height={ 32 }
|
height={32}
|
||||||
width={ 32 }
|
width={32}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p className="flex flex-row flex-wrap text-center justify-center items-center gap-1 text-md mx-auto">
|
<p className="flex flex-row flex-wrap text-center justify-center items-center gap-1 text-md mx-auto">
|
||||||
{ presenceItem.data.name }{ " " }
|
{presenceItem.data.name}{" "}
|
||||||
{ presenceItem.data.role === "ADMIN" && (
|
{presenceItem.data.role === "ADMIN" && (
|
||||||
<div
|
<div
|
||||||
className="tooltip tooltip-primary"
|
className="tooltip tooltip-primary"
|
||||||
data-tip="Admin"
|
data-tip="Admin"
|
||||||
>
|
>
|
||||||
<FaShieldAlt className="inline-block text-primary" />
|
<FaShieldAlt className="inline-block text-primary" />
|
||||||
</div>
|
</div>
|
||||||
) }{ " " }
|
)}{" "}
|
||||||
{ presenceItem.clientId === roomFromDb.userId && (
|
{presenceItem.clientId === roomFromDb.userId && (
|
||||||
<div
|
<div
|
||||||
className="tooltip tooltip-warning"
|
className="tooltip tooltip-warning"
|
||||||
data-tip="Room Owner"
|
data-tip="Room Owner"
|
||||||
>
|
>
|
||||||
<RiVipCrownFill className="inline-block text-yellow-500" />
|
<RiVipCrownFill className="inline-block text-yellow-500" />
|
||||||
</div>
|
</div>
|
||||||
) }
|
)}
|
||||||
{ " : " }
|
{" : "}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{ roomFromDb &&
|
{roomFromDb &&
|
||||||
votesFromDb &&
|
votesFromDb &&
|
||||||
voteString(
|
voteString(
|
||||||
roomFromDb.visible,
|
roomFromDb.visible,
|
||||||
votesFromDb,
|
votesFromDb,
|
||||||
presenceItem.data
|
presenceItem.data
|
||||||
) }
|
)}
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
}) }
|
})}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div className="join md:btn-group-horizontal mx-auto">
|
<div className="join md:btn-group-horizontal mx-auto">
|
||||||
{ roomFromDb.scale.split(",").map((scaleItem, index) => {
|
{roomFromDb.scale.split(",").map((scaleItem, index) => {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
key={ index }
|
key={index}
|
||||||
className={ `join-item ${getVoteForCurrentUser()?.value === scaleItem
|
className={`join-item ${
|
||||||
|
getVoteForCurrentUser()?.value === scaleItem
|
||||||
? "btn btn-active btn-primary"
|
? "btn btn-active btn-primary"
|
||||||
: "btn"
|
: "btn"
|
||||||
}` }
|
}`}
|
||||||
onClick={ () => setVote(scaleItem) }
|
onClick={() => setVote(scaleItem)}
|
||||||
>
|
>
|
||||||
{ scaleItem }
|
{scaleItem}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
}) }
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) }
|
)}
|
||||||
|
|
||||||
{ sessionData &&
|
{session && !!roomFromDb && roomFromDb.userId === session.user.id && (
|
||||||
!!roomFromDb &&
|
<>
|
||||||
roomFromDb.userId === sessionData.user.id && (
|
<div className="card card-compact bg-neutral shadow-xl mx-auto m-4">
|
||||||
<>
|
<div className="card-body flex flex-col flex-wrap">
|
||||||
<div className="card card-compact bg-neutral shadow-xl mx-auto m-4">
|
<h2 className="card-title mx-auto">Room Settings</h2>
|
||||||
<div className="card-body flex flex-col flex-wrap">
|
|
||||||
<h2 className="card-title mx-auto">Room Settings</h2>
|
|
||||||
|
|
||||||
<label className="label mx-auto">
|
<label className="label mx-auto">
|
||||||
{ "Vote Scale (Comma Separated):" }{ " " }
|
{"Vote Scale (Comma Separated):"}{" "}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Scale (Comma Separated)"
|
placeholder="Scale (Comma Separated)"
|
||||||
className="input input-bordered m-auto"
|
className="input input-bordered m-auto"
|
||||||
value={ roomScale }
|
value={roomScale}
|
||||||
onChange={ (event) => {
|
onChange={(event) => {
|
||||||
setRoomScale(event.target.value);
|
setRoomScale(event.target.value);
|
||||||
} }
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<label className="label mx-auto">{ "Story Name:" } </label>
|
<label className="label mx-auto">{"Story Name:"} </label>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Story Name"
|
placeholder="Story Name"
|
||||||
className="input input-bordered m-auto"
|
className="input input-bordered m-auto"
|
||||||
value={ storyNameText }
|
value={storyNameText}
|
||||||
onChange={ (event) => {
|
onChange={(event) => {
|
||||||
setStoryNameText(event.target.value);
|
setStoryNameText(event.target.value);
|
||||||
} }
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="flex flex-row flex-wrap text-center items-center justify-center gap-2">
|
<div className="flex flex-row flex-wrap text-center items-center justify-center gap-2">
|
||||||
<div>
|
<div>
|
||||||
<button
|
<button
|
||||||
onClick={ () => saveRoom(!roomFromDb.visible, false) }
|
onClick={() => saveRoom(!roomFromDb.visible, false)}
|
||||||
className="btn btn-primary inline-flex"
|
className="btn btn-primary inline-flex"
|
||||||
>
|
>
|
||||||
{ roomFromDb.visible ? (
|
{roomFromDb.visible ? (
|
||||||
<>
|
<>
|
||||||
<IoEyeOffOutline className="text-xl mr-1" />
|
<IoEyeOffOutline className="text-xl mr-1" />
|
||||||
Hide
|
Hide
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<IoEyeOutline className="text-xl mr-1" />
|
<IoEyeOutline className="text-xl mr-1" />
|
||||||
Show
|
Show
|
||||||
</>
|
</>
|
||||||
) }
|
)}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<button
|
|
||||||
onClick={ () =>
|
|
||||||
saveRoom(
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
roomFromDb.storyName === storyNameText ||
|
|
||||||
votesFromDb?.length === 0
|
|
||||||
? false
|
|
||||||
: true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
className="btn btn-primary inline-flex"
|
|
||||||
disabled={
|
|
||||||
[...new Set(roomScale.split(","))].filter(
|
|
||||||
(item) => item !== ""
|
|
||||||
).length <= 1
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{ roomFromDb.storyName === storyNameText ||
|
|
||||||
votesFromDb?.length === 0 ? (
|
|
||||||
<>
|
|
||||||
<IoReloadOutline className="text-xl mr-1" /> Reset
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<IoSaveOutline className="text-xl mr-1" /> Save
|
|
||||||
</>
|
|
||||||
) }
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{ votesFromDb &&
|
|
||||||
(roomFromDb.logs.length > 0 ||
|
|
||||||
votesFromDb.length > 0) && (
|
|
||||||
<div>
|
|
||||||
<button
|
|
||||||
onClick={ () => downloadLogs() }
|
|
||||||
className="btn btn-primary inline-flex hover:animate-pulse"
|
|
||||||
>
|
|
||||||
<>
|
|
||||||
<IoDownloadOutline className="text-xl" />
|
|
||||||
</>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
) }
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
onClick={() =>
|
||||||
|
saveRoom(
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
roomFromDb.storyName === storyNameText ||
|
||||||
|
votesFromDb?.length === 0
|
||||||
|
? false
|
||||||
|
: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
className="btn btn-primary inline-flex"
|
||||||
|
disabled={
|
||||||
|
[...new Set(roomScale.split(","))].filter(
|
||||||
|
(item) => item !== ""
|
||||||
|
).length <= 1
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{roomFromDb.storyName === storyNameText ||
|
||||||
|
votesFromDb?.length === 0 ? (
|
||||||
|
<>
|
||||||
|
<IoReloadOutline className="text-xl mr-1" /> Reset
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<IoSaveOutline className="text-xl mr-1" /> Save
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{votesFromDb &&
|
||||||
|
(roomFromDb.logs.length > 0 || votesFromDb.length > 0) && (
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
onClick={() => downloadLogs()}
|
||||||
|
className="btn btn-primary inline-flex hover:animate-pulse"
|
||||||
|
>
|
||||||
|
<>
|
||||||
|
<IoDownloadOutline className="text-xl" />
|
||||||
|
</>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</div>
|
||||||
) }
|
</>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
// Room does not exist
|
// Room does not exist
|
||||||
|
|
Loading…
Add table
Reference in a new issue