Finer chat hub

This commit is contained in:
2025-10-26 21:06:02 +01:00
parent 07ba104edd
commit 903d0d2fa6
+62 -31
View File
@@ -13,32 +13,46 @@ import { motion } from "framer-motion";
import { import {
ChevronLeft, ChevronLeft,
ChevronRight, ChevronRight,
MessageCircle,
Users, Users,
Settings, Settings,
PlusCircle, TrendingUp,
NetworkIcon,
MessagesSquare,
} from "lucide-react"; } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import StartNewDM from "./StartNewDM"; import StartNewDM from "./StartNewDM";
import AsyncValue from "@/components/AsyncValue"; import AsyncValue from "@/components/AsyncValue";
import { useRouter } from "next/navigation";
import Cookies from "js-cookie";
import { toast } from "sonner";
export default function ChatHub() { export default function ChatHub() {
const router = useRouter();
const app = useApp(); const app = useApp();
const recentPeople = app.dms.slice(0, 3);
const recentDMs = app.dms?.slice(0, 5) || []; const activeServers: Server[] = Object.values(app.servers).slice(0, 3);
const activeServers: Server[] = Object.values(app.servers).slice(0, 5) || []; const trendingServers: Server[] = [
const suggestedServers: Server[] = [ {
{ id: "1", name: "Frontend Devs", icon_url: "", channels: [] }, id: "cee6b20f-7e6a-4071-8df1-aab37f52bbb9",
{ id: "2", name: "Gamers Lounge", icon_url: "", channels: [] }, name: "ORUS",
{ id: "3", name: "Music Hub", icon_url: "", channels: [] }, icon_url: "https://github.com/orus-dev.png",
channels: [],
},
{
id: "cee6b20f-7e6a-4071-8df1-aab37f52bbb9",
name: "Saturn Client",
icon_url: "https://github.com/saturnclientmc.png",
channels: [],
},
{
id: "cee6b20f-7e6a-4071-8df1-aab37f52bbb9",
name: "OSUI Rust Hub",
icon_url: "https://github.com/osui-rs.png",
channels: [],
},
]; ];
const recentActivity = app.messages.slice(0, 5); const recentActivity = app.messages.slice(0, 3);
const stats = {
dms: app.dms?.length || 0,
servers: app.servers?.length || 0,
// friends: app.friends?.length || 0,
};
return ( return (
<AppLayout app={app}> <AppLayout app={app}>
@@ -56,7 +70,7 @@ export default function ChatHub() {
Hey {app.profile?.display_name || "there"}! Hey {app.profile?.display_name || "there"}!
</h1> </h1>
<p className="text-muted-foreground"> <p className="text-muted-foreground">
Here’s what’s happening in your network today. Here's what's happening in your network today.
</p> </p>
</div> </div>
@@ -66,13 +80,13 @@ export default function ChatHub() {
<Card> <Card>
<CardHeader> <CardHeader>
<CardTitle className="flex items-center gap-2"> <CardTitle className="flex items-center gap-2">
<MessageCircle className="w-5 h-5" /> <Users className="w-5 h-5" />
Recent DMs Recently chatted with
</CardTitle> </CardTitle>
</CardHeader> </CardHeader>
<CardContent className="space-y-3"> <CardContent className="space-y-3">
{recentDMs.length ? ( {recentPeople.length ? (
recentDMs.map((dm) => ( recentPeople.map((dm) => (
<Link <Link
href={`/chat/${dm.id}`} href={`/chat/${dm.id}`}
key={dm.id} key={dm.id}
@@ -102,7 +116,7 @@ export default function ChatHub() {
<Card> <Card>
<CardHeader> <CardHeader>
<CardTitle className="flex items-center gap-2"> <CardTitle className="flex items-center gap-2">
<Users className="w-5 h-5" /> <NetworkIcon className="w-5 h-5" />
Active Servers Active Servers
</CardTitle> </CardTitle>
</CardHeader> </CardHeader>
@@ -137,7 +151,7 @@ export default function ChatHub() {
<Card> <Card>
<CardHeader> <CardHeader>
<CardTitle className="flex items-center gap-2"> <CardTitle className="flex items-center gap-2">
<MessageCircle className="w-5 h-5" /> <MessagesSquare className="w-5 h-5" />
Recent Activity Recent Activity
</CardTitle> </CardTitle>
</CardHeader> </CardHeader>
@@ -184,26 +198,43 @@ export default function ChatHub() {
<Card> <Card>
<CardHeader> <CardHeader>
<CardTitle className="flex items-center gap-2"> <CardTitle className="flex items-center gap-2">
<Users className="w-5 h-5" /> <TrendingUp className="w-5 h-5" />
Discover Servers Trending Servers
</CardTitle> </CardTitle>
</CardHeader> </CardHeader>
<CardContent> <CardContent>
<div className="grid sm:grid-cols-2 lg:grid-cols-3 gap-4"> <div className="grid sm:grid-cols-2 lg:grid-cols-3 gap-4">
{suggestedServers.map((srv) => ( {trendingServers.map((srv) => (
<motion.div <motion.div
key={srv.id} key={srv.id}
whileHover={{ scale: 1.03 }} whileHover={{ scale: 1.03 }}
transition={{ type: "spring", stiffness: 300 }} transition={{ type: "spring", stiffness: 300 }}
> >
<Card className="hover:bg-accent transition"> <Card
className="hover:bg-accent transition"
onClick={async () => {
try {
Cookies.set(
"servers",
Object.keys({
...app.servers,
[srv.id]: srv,
}).join(",")
);
app.setServers((prev) => ({
...prev,
[srv.id]: srv,
}));
router.push(`/server/${srv.id}`);
} catch (e: any) {
toast.error(e);
}
}}
>
<CardContent className="p-4 flex flex-col items-center text-center gap-2"> <CardContent className="p-4 flex flex-col items-center text-center gap-2">
<ProfilePicture name={srv.name} url={srv.icon_url} /> <ProfilePicture name={srv.name} url={srv.icon_url} />
<h3 className="font-medium truncate">{srv.name}</h3> <h3 className="font-medium truncate">{srv.name}</h3>
<Button size="sm" className="gap-2">
<PlusCircle className="w-4 h-4" />
Join
</Button>
</CardContent> </CardContent>
</Card> </Card>
</motion.div> </motion.div>