diff --git a/app/api/channels/[channelId]/route.ts b/app/api/channels/[channelId]/route.ts index 8e3fee5..c32d57a 100644 --- a/app/api/channels/[channelId]/route.ts +++ b/app/api/channels/[channelId]/route.ts @@ -32,13 +32,21 @@ export async function PATCH( return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } - if (!name || !name.trim()) { + if (!name) { return NextResponse.json( { error: "Channel name cannot be empty" }, { status: 400 }, ); } + // Validate maximum length for channel name + if (name.length > 32) { + return NextResponse.json( + { error: "Channel name cannot exceed 32 characters" }, + { status: 400 }, + ); + } + const [existingChannel] = await db .select() .from(channels) diff --git a/app/api/channels/route.ts b/app/api/channels/route.ts index 57698dd..2aa4114 100644 --- a/app/api/channels/route.ts +++ b/app/api/channels/route.ts @@ -27,13 +27,21 @@ export async function POST(req: Request) { const { name, serverId } = await req.json(); - if (!name?.trim() || !serverId) { + if (!name || !serverId) { return NextResponse.json( { error: "Name and server ID are required" }, { status: 400 }, ); } + // Validate maximum length for channel name + if (name.length > 32) { + return NextResponse.json( + { error: "Channel name cannot exceed 32 characters" }, + { status: 400 }, + ); + } + // Check if the user is a member of the server const [member] = await db .select() diff --git a/components/modals/CreateChannelModal.tsx b/components/modals/CreateChannelModal.tsx index 4eb1fd3..248c5d9 100644 --- a/components/modals/CreateChannelModal.tsx +++ b/components/modals/CreateChannelModal.tsx @@ -124,6 +124,7 @@ export function CreateChannelModal({ type="text" required value={name} + maxLength={32} onChange={(e) => setName(e.target.value)} placeholder="new-channel" disabled={isLoading} diff --git a/components/modals/EditChannelModal.tsx b/components/modals/EditChannelModal.tsx index a7b9593..2dd4bcf 100644 --- a/components/modals/EditChannelModal.tsx +++ b/components/modals/EditChannelModal.tsx @@ -82,16 +82,15 @@ export function EditChannelModal({ }); if (!response.ok) { - throw new Error("Fehler beim Aktualisieren des Channels."); + throw new Error("Error updating the channel."); } const updated = await response.json(); updateChannel(updated); + router.refresh(); onClose(); } catch (err: unknown) { - setError( - err instanceof Error ? err.message : "Etwas ist schiefgelaufen.", - ); + setError(err instanceof Error ? err.message : "Something went wrong."); } finally { setIsLoading(false); } @@ -116,7 +115,7 @@ export function EditChannelModal({ }); if (!response.ok) { - throw new Error("Fehler beim Löschen des Channels."); + throw new Error("Error deleting the channel."); } removeChannel(channel.id); @@ -135,9 +134,7 @@ export function EditChannelModal({ } } } catch (err: unknown) { - setError( - err instanceof Error ? err.message : "Etwas ist schiefgelaufen.", - ); + setError(err instanceof Error ? err.message : "Something went wrong."); } finally { setIsDeleting(false); } @@ -179,6 +176,7 @@ export function EditChannelModal({ type="text" required value={name} + maxLength={32} onChange={(e) => setName(e.target.value)} placeholder="channel-name" disabled={isLoading || isDeleting} diff --git a/components/sidebar/ChannelSidebar.tsx b/components/sidebar/ChannelSidebar.tsx index 3dedb8e..faedd61 100644 --- a/components/sidebar/ChannelSidebar.tsx +++ b/components/sidebar/ChannelSidebar.tsx @@ -62,22 +62,22 @@ export function ChannelSidebar() { return ( <> -
+
{/* Server Header */} -
+
{activeServer.name}
{/* Channel List */} -
+
Text Channels
-
+
{activeServer.channels.map((channel) => { const isActive = currentChannelId === channel.id; @@ -100,14 +100,15 @@ export function ChannelSidebar() { href={`/servers/${activeServer.id}/channels/${channel.id}`} onClick={handleChannelClick} prefetch={false} - className={`flex items-center justify-between px-2 py-1.5 rounded-md text-sm transition-all group ${ + className={`flex items-center justify-between w-full px-2 py-1.5 rounded-md text-sm transition-all group min-w-0 overflow-hidden ${ isActive ? "bg-accent/50 text-white font-medium" : "text-muted hover:bg-surface hover:text-white" }`} > -
- + {/* Text Area */} +
+ # {channel.name} @@ -118,7 +119,7 @@ export function ChannelSidebar() {