From 94c544b16199b9c8fa9528aa567b2134896afe54 Mon Sep 17 00:00:00 2001 From: pascalyazid Date: Fri, 15 May 2026 18:37:46 +0200 Subject: [PATCH] Reimplemented rooms with live update --- app/(auth)/rooms/[id]/chat.tsx | 14 +++++++------- app/(auth)/rooms/[id]/members-list.tsx | 4 ++-- app/(auth)/rooms/[id]/page.tsx | 10 +++++----- app/(auth)/rooms/[id]/room-settings.tsx | 6 +++--- app/(auth)/rooms/actions.ts | 10 ++++++---- app/(auth)/rooms/add-member-form.tsx | 2 +- app/(auth)/rooms/rooms-list.tsx | 2 +- 7 files changed, 25 insertions(+), 23 deletions(-) diff --git a/app/(auth)/rooms/[id]/chat.tsx b/app/(auth)/rooms/[id]/chat.tsx index 92b61d4..c44b75e 100644 --- a/app/(auth)/rooms/[id]/chat.tsx +++ b/app/(auth)/rooms/[id]/chat.tsx @@ -28,12 +28,12 @@ export function Chat({ initialMessages, currentUserId, memberMap, -}: { +}: Readonly<{ roomId: string; initialMessages: Message[]; currentUserId: string; memberMap: Map; -}) { +}>) { const boundAction = sendMessageAction.bind(null, roomId); const [state, action, pending] = useActionState(boundAction, initialState); const formRef = useRef(null); @@ -197,16 +197,16 @@ export function Chat({ .subscribe(); return () => { - void supabase.removeChannel(channel); + supabase.removeChannel(channel); }; }, [roomId, memberMap, currentUserId]); const displayMessages = [...messages].reverse(); return ( -
+
{/* Messages area */} -
+
{displayMessages.length === 0 ? (

@@ -296,11 +296,11 @@ function Avatar({ name, avatarUrl, size = "md", -}: { +}: Readonly<{ name: string; avatarUrl: string | null; size?: "sm" | "md"; -}) { +}>) { const sizeClass = size === "sm" ? "size-5" : "size-8"; const textSize = size === "sm" ? "text-[10px]" : "text-xs"; diff --git a/app/(auth)/rooms/[id]/members-list.tsx b/app/(auth)/rooms/[id]/members-list.tsx index 6e15195..efd808b 100644 --- a/app/(auth)/rooms/[id]/members-list.tsx +++ b/app/(auth)/rooms/[id]/members-list.tsx @@ -11,12 +11,12 @@ export function MembersList({ currentUserId, onRemoveMember, disableActions, -}: { +}: Readonly<{ members: MemberEntry[]; currentUserId?: string; onRemoveMember?: (userId: string) => void; disableActions?: boolean; -}) { +}>) { if (members.length === 0) return null; return ( diff --git a/app/(auth)/rooms/[id]/page.tsx b/app/(auth)/rooms/[id]/page.tsx index a2cada5..500bf73 100644 --- a/app/(auth)/rooms/[id]/page.tsx +++ b/app/(auth)/rooms/[id]/page.tsx @@ -9,9 +9,9 @@ import { buildMemberMap } from "./member-map"; export default async function RoomDetailPage({ params, -}: { +}: Readonly<{ params: Promise<{ id: string }>; -}) { +}>) { const { id } = await params; const supabase = await createClient(); @@ -43,9 +43,9 @@ export default async function RoomDetailPage({ ]); return ( -

+
{/* Header */} -
+
{/* Chat */} -
+
) { const [open, setOpen] = useState(false); const [deleting, setDeleting] = useState(false); const [removeError, setRemoveError] = useState(null); @@ -59,7 +59,7 @@ export function RoomSettings({ > diff --git a/app/(auth)/rooms/actions.ts b/app/(auth)/rooms/actions.ts index c060345..752d273 100644 --- a/app/(auth)/rooms/actions.ts +++ b/app/(auth)/rooms/actions.ts @@ -25,7 +25,7 @@ export async function createRoomAction( const result = await createRoom(name.trim()); if (result.error) { - return { error: result.error }; + return { error: "Couldn't create the room." }; } revalidatePath("/rooms"); @@ -54,7 +54,9 @@ export async function addMemberAction( const result = await addMember(roomId, trimmed); if (result.error) { - return { error: result.error }; + return { + error: "Couldn't add the user to the room or they are already a member.", + }; } revalidatePath("/rooms"); @@ -64,7 +66,7 @@ export async function addMemberAction( export async function deleteRoomAction(roomId: string) { const result = await deleteRoom(roomId); if (result.error) { - return { error: result.error }; + return { error: "Couldn't delete the room." }; } revalidatePath("/rooms"); @@ -74,7 +76,7 @@ export async function deleteRoomAction(roomId: string) { export async function removeMemberAction(roomId: string, userId: string) { const result = await removeMember(roomId, userId); if (result.error) { - return { error: result.error }; + return { error: "Couldn't remove the member with the id " + userId }; } revalidatePath(`/rooms/${roomId}`); diff --git a/app/(auth)/rooms/add-member-form.tsx b/app/(auth)/rooms/add-member-form.tsx index b9e8277..a06bdcb 100644 --- a/app/(auth)/rooms/add-member-form.tsx +++ b/app/(auth)/rooms/add-member-form.tsx @@ -5,7 +5,7 @@ import { addMemberAction, type AddMemberState } from "./actions"; const initialState: AddMemberState = null; -export function AddMemberForm({ roomId }: { roomId: string }) { +export function AddMemberForm({ roomId }: Readonly<{ roomId: string }>) { const boundAction = addMemberAction.bind(null, roomId); const [state, action, pending] = useActionState(boundAction, initialState); diff --git a/app/(auth)/rooms/rooms-list.tsx b/app/(auth)/rooms/rooms-list.tsx index 9cc2f5f..64fda97 100644 --- a/app/(auth)/rooms/rooms-list.tsx +++ b/app/(auth)/rooms/rooms-list.tsx @@ -7,7 +7,7 @@ export interface RoomEntry { member_count: number; } -export function RoomsList({ rooms }: { rooms: RoomEntry[] }) { +export function RoomsList({ rooms }: Readonly<{ rooms: RoomEntry[] }>) { if (rooms.length === 0) { return (