Skip to content

Commit

Permalink
[frontend] Fixed to call notFound function instead of throwing Error …
Browse files Browse the repository at this point in the history
…object (#307)
  • Loading branch information
lim396 authored Mar 9, 2024
1 parent 13f8e71 commit b426f7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 12 additions & 1 deletion frontend/app/room/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Separator } from "@/components/ui/separator";
import { notFound } from "next/navigation";
import MessageArea from "./message-area";
import RoomDetail from "./room-detail";
import { getCurrentUserId } from "@/app/lib/session";

export default async function Page({
params: { id },
Expand All @@ -18,12 +19,22 @@ export default async function Page({
}
const messages = await getMessages(roomId);
const allUsers = await getUsers();
const currentUserId = await getCurrentUserId();
const me = room.users.find((u) => u.userId === currentUserId);
if (!me) {
notFound();
}
return (
<>
<div className="overflow-auto flex-grow flex gap-4 pb-4">
<MessageArea roomId={roomId} messages={messages} />
<Separator orientation="vertical" />
<RoomDetail room={room} users={room.users} allUsers={allUsers} />
<RoomDetail
room={room}
users={room.users}
allUsers={allUsers}
me={me}
/>
</div>
</>
);
Expand Down
8 changes: 2 additions & 6 deletions frontend/app/room/[id]/room-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ interface Props {
room: RoomEntity;
users: UserOnRoomEntity[];
allUsers: PublicUserEntity[];
me: UserOnRoomEntity;
}

export default async function RoomDetail({ room, users, allUsers }: Props) {
const currentUserId = await getCurrentUserId();
const me = users.find((u) => u.userId === currentUserId);
if (!me) {
throw new Error("User not found");
}
export default async function RoomDetail({ room, users, allUsers, me }: Props) {
const bannedUsers = (await getBannedUsers(room.id)) ?? [];
const blockingUsers = (await getBlockingUsers()) ?? [];
const mutedUsers = (await getMutedUsers(room.id)) ?? [];
Expand Down

0 comments on commit b426f7e

Please sign in to comment.