From 10f6f3b736edce53fd0c9f78978c73b798d56840 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Thu, 2 Oct 2025 13:14:30 +0200 Subject: [PATCH] Better ui and slight change for settings #3 --- src/app/home/page.tsx | 53 ++---------------------- src/app/layout.tsx | 10 ++++- src/app/server/[id]/page.tsx | 1 + src/app/settings/page.tsx | 76 +++++++++++++++++++++-------------- src/components/MessageBox.tsx | 14 ++++++- src/components/Sidebar.tsx | 19 ++++++++- src/lib/clientSettings.ts | 11 +++-- 7 files changed, 96 insertions(+), 88 deletions(-) diff --git a/src/app/home/page.tsx b/src/app/home/page.tsx index 9b47b86..3554c13 100644 --- a/src/app/home/page.tsx +++ b/src/app/home/page.tsx @@ -1,28 +1,14 @@ "use client"; -import { Button } from "@/components/ui/button"; -import { Avatar, AvatarFallback } from "@/components/ui/avatar"; -import { Card } from "@/components/ui/card"; -import { useState } from "react"; import AppSidebar from "@/components/Sidebar"; import MessageBox from "@/components/MessageBox"; +import useUser from "@/hooks/get-user"; export default function HomePage() { - const [messages, setMessages] = useState([ - { id: 1, user: "Alice", text: "Hey, how are you?" }, - { id: 2, user: "You", text: "Doing good, just working on the chat app!" }, - ]); - - const [input, setInput] = useState(""); - - function sendMessage() { - if (!input.trim()) return; - setMessages([...messages, { id: Date.now(), user: "You", text: input }]); - setInput(""); - } + const { user, loading } = useUser(); return ( - + ); } - -function ServerButton({ - label, - icon, -}: { - label: string; - icon: React.ReactNode; -}) { - return ( - - ); -} - -function DMItem({ name, status }: { name: string; status: string }) { - return ( - - - {name[0]} - -
- {name} - {status} -
-
- ); -} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 11234a9..8642836 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,6 +1,8 @@ import type { Metadata } from "next"; import { Geist, Geist_Mono } from "next/font/google"; import "./globals.css"; +import { cookies } from "next/headers"; +import { parseClientSettings } from "@/lib/clientSettings"; const geistSans = Geist({ variable: "--font-geist-sans", @@ -17,15 +19,19 @@ export const metadata: Metadata = { description: "Generated by create next app", }; -export default function RootLayout({ +export default async function RootLayout({ children, }: Readonly<{ children: React.ReactNode; }>) { + const cookieStore = await cookies(); + + const settings = parseClientSettings(cookieStore.get("settings")?.value); + return ( {children} diff --git a/src/app/server/[id]/page.tsx b/src/app/server/[id]/page.tsx index e370432..0b7a978 100644 --- a/src/app/server/[id]/page.tsx +++ b/src/app/server/[id]/page.tsx @@ -84,6 +84,7 @@ export default function Server() { return ( - - Client Settings - Account Settings - - - - - setClientSettings(settings)} - /> - - - - - - - {}} - /> - - - - +
+ + + + Client Settings + Account Settings + + + + + { + setClientSettings(settings); + router.refresh(); + }} + /> + + + + + + + {}} + /> + + + + +
); } diff --git a/src/components/MessageBox.tsx b/src/components/MessageBox.tsx index d89a05f..264b7c2 100644 --- a/src/components/MessageBox.tsx +++ b/src/components/MessageBox.tsx @@ -18,6 +18,7 @@ import remarkGfm from "remark-gfm"; import { NumberMap, StringMap } from "@/types/typeUtils"; import { User } from "@/hooks/get-user"; import axios from "axios"; +import { Avatar, AvatarFallback, AvatarImage } from "./ui/avatar"; function MessageContainer({ message, @@ -40,7 +41,18 @@ function MessageContainer({ return (
-
+ {/*
*/} + + + + {userList[message.from] + ? userList[message.from].username + : message.from} + +
{userList[message.from] diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index f1bdcde..86e5a29 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -5,6 +5,7 @@ import { MessageCircle, Plus, Search, + SettingsIcon, Volume2Icon, } from "lucide-react"; import Server from "@/types/server"; @@ -24,16 +25,21 @@ import { Input } from "./ui/input"; import { Label } from "./ui/label"; import { Button } from "./ui/button"; import { Card } from "./ui/card"; -import { Avatar, AvatarFallback } from "./ui/avatar"; +import { Avatar, AvatarFallback, AvatarImage } from "./ui/avatar"; import { ScrollArea } from "./ui/scroll-area"; import { useRouter } from "next/navigation"; import Channel from "@/types/channel"; +import Link from "next/link"; +import { NumberMap } from "@/types/typeUtils"; +import { User } from "@/hooks/get-user"; export default function AppSidebar({ + user, server, children, }: Readonly<{ server?: Server; + user: User | null; children: React.ReactNode; }>) { const [servers, setServers] = useState<[string, string][]>([]); @@ -143,6 +149,12 @@ export default function AppSidebar({ + +
+ + + +
{/* Right column */} @@ -177,6 +189,10 @@ export default function AppSidebar({ )}
+ +
+ +
@@ -189,6 +205,7 @@ function DMItem({ name, status }: { name: string; status: string }) { return ( + {name[0]}
diff --git a/src/lib/clientSettings.ts b/src/lib/clientSettings.ts index 4a7e385..484dcdf 100644 --- a/src/lib/clientSettings.ts +++ b/src/lib/clientSettings.ts @@ -5,13 +5,12 @@ export const defaultSettings: ClientSettings = { theme: "dark", }; -export function getClientSettings(): ClientSettings { - const s_cookie = Cookies.get("settings"); +export function parseClientSettings(s?: string): ClientSettings { let parsed: Partial = {}; - if (s_cookie) { + if (s) { try { - parsed = JSON.parse(s_cookie); + parsed = JSON.parse(s); } catch { parsed = {}; } @@ -23,6 +22,10 @@ export function getClientSettings(): ClientSettings { }; } +export function getClientSettings(): ClientSettings { + return parseClientSettings(Cookies.get("settings")); +} + export function setClientSettings(value?: ClientSettings) { Cookies.set("settings", JSON.stringify(value || defaultSettings)); }