Merge branch 'dev'

This commit is contained in:
Atridad Lahiji 2023-09-06 13:00:00 -06:00
commit 4b2a754b44
No known key found for this signature in database
6 changed files with 36 additions and 30 deletions

View file

@ -1,6 +1,4 @@
"use client"; const LoadingIndicator = () => {
const Loading = () => {
return ( return (
<div className="flex items-center justify-center"> <div className="flex items-center justify-center">
<span className="loading loading-dots loading-lg"></span> <span className="loading loading-dots loading-lg"></span>
@ -8,4 +6,4 @@ const Loading = () => {
); );
}; };
export default Loading; export default LoadingIndicator;

View file

@ -6,19 +6,26 @@ import { useState } from "react";
import { IoEnterOutline, IoTrashBinOutline } from "react-icons/io5"; import { IoEnterOutline, IoTrashBinOutline } from "react-icons/io5";
import { env } from "@/env.mjs"; import { env } from "@/env.mjs";
import { trpc } from "../_trpc/client"; import { trpc } from "../_trpc/client";
import Loading from "./Loading"; import LoadingIndicator from "./LoadingIndicator";
import { useUser } from "@clerk/nextjs";
export const dynamic = "force-dynamic";
export const revalidate = 0;
export const fetchCache = "force-no-store";
const RoomList = () => {
const { user } = useUser();
const RoomList = ({ userId }: { userId: string }) => {
configureAbly({ configureAbly({
key: env.NEXT_PUBLIC_ABLY_PUBLIC_KEY, key: env.NEXT_PUBLIC_ABLY_PUBLIC_KEY,
clientId: userId, clientId: user?.id,
recover: (_, cb) => { recover: (_, cb) => {
cb(true); cb(true);
}, },
}); });
useChannel( useChannel(
`${env.NEXT_PUBLIC_APP_ENV}-${userId}`, `${env.NEXT_PUBLIC_APP_ENV}-${user?.id}`,
() => void refetchRoomsFromDb() () => void refetchRoomsFromDb()
); );
@ -130,7 +137,7 @@ const RoomList = ({ userId }: { userId: string }) => {
New Room New Room
</label> </label>
{roomsFromDb === undefined && <Loading />} {roomsFromDb === undefined && <LoadingIndicator />}
</div> </div>
); );
}; };

View file

@ -24,12 +24,17 @@ import { env } from "@/env.mjs";
import { isAdmin, isVIP, jsonToCsv } from "@/utils/helpers"; import { isAdmin, isVIP, jsonToCsv } from "@/utils/helpers";
import type { PresenceItem } from "@/utils/types"; import type { PresenceItem } from "@/utils/types";
import { trpc } from "@/app/_trpc/client"; import { trpc } from "@/app/_trpc/client";
import Loading from "@/app/_components/Loading"; import LoadingIndicator from "@/app/_components/LoadingIndicator";
import { User } from "@clerk/nextjs/dist/types/server"; import { useUser } from "@clerk/nextjs";
const VoteUI = ({ user }: { user: Partial<User> }) => { export const dynamic = "force-dynamic";
export const revalidate = 0;
export const fetchCache = "force-no-store";
const VoteUI = () => {
const params = useParams(); const params = useParams();
const roomId = params?.id as string; const roomId = params?.id as string;
const { user } = useUser();
const [storyNameText, setStoryNameText] = useState<string>(""); const [storyNameText, setStoryNameText] = useState<string>("");
const [roomScale, setRoomScale] = useState<string>(""); const [roomScale, setRoomScale] = useState<string>("");
@ -99,7 +104,9 @@ const VoteUI = ({ user }: { user: Partial<User> }) => {
// Helper functions // Helper functions
const getVoteForCurrentUser = () => { const getVoteForCurrentUser = () => {
if (roomFromDb) { if (roomFromDb) {
return votesFromDb && votesFromDb.find((vote) => vote.userId === user.id); return (
votesFromDb && votesFromDb.find((vote) => vote.userId === user?.id)
);
} else { } else {
return null; return null;
} }
@ -204,7 +211,7 @@ const VoteUI = ({ user }: { user: Partial<User> }) => {
// Room is loading // Room is loading
if (roomFromDb === undefined) { if (roomFromDb === undefined) {
return <Loading />; return <LoadingIndicator />;
// Room has been loaded // Room has been loaded
} else if (roomFromDb) { } else if (roomFromDb) {
return ( return (
@ -322,7 +329,7 @@ const VoteUI = ({ user }: { user: Partial<User> }) => {
)} )}
{!!roomFromDb && {!!roomFromDb &&
(roomFromDb.userId === user.id || isAdmin(user?.publicMetadata)) && ( (roomFromDb.userId === user?.id || isAdmin(user?.publicMetadata)) && (
<> <>
<div className="card card-compact bg-base-100 shadow-xl mx-auto m-4"> <div className="card card-compact bg-base-100 shadow-xl mx-auto m-4">
<div className="card-body flex flex-col flex-wrap"> <div className="card-body flex flex-col flex-wrap">

View file

@ -25,7 +25,7 @@ export default async function Dashboard() {
)} )}
</h1> </h1>
{user && <RoomList userId={user?.id} />} <RoomList />
</div> </div>
); );
} }

View file

@ -0,0 +1,6 @@
import LoadingIndicator from "@/app/_components/LoadingIndicator";
export default function Loading() {
// You can add any UI inside Loading, including a Skeleton.
return <LoadingIndicator />;
}

View file

@ -1,5 +1,3 @@
import { currentUser } from "@clerk/nextjs";
import Loading from "@/app/_components/Loading";
import VoteUI from "@/app/_components/VoteUI"; import VoteUI from "@/app/_components/VoteUI";
export const runtime = "edge"; export const runtime = "edge";
@ -8,20 +6,10 @@ export const dynamic = "force-dynamic";
export const revalidate = 0; export const revalidate = 0;
export const fetchCache = "force-no-store"; export const fetchCache = "force-no-store";
export default async function Room() { export default function Room() {
const user = await currentUser();
const shapedUser = {
id: user?.id,
firstName: user?.firstName,
lastName: user?.lastName,
imageUrl: user?.imageUrl,
publicMetadata: user?.publicMetadata,
};
return ( return (
<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">
{user ? <VoteUI user={shapedUser} /> : <Loading />} <VoteUI />
</div> </div>
); );
} }