Skip to content

Commit bb42393

Browse files
committed
feat(dashboard): use name for default icon
1 parent 811aa7c commit bb42393

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

web/components/server-icon.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Image } from "@nextui-org/react";
2+
3+
export function ServerIcon({
4+
guild,
5+
}: {
6+
guild: { name: string; icon?: string };
7+
}) {
8+
if (!guild.icon) {
9+
return (
10+
<div className="w-16 h-16 rounded-large bg-default flex items-center justify-center">
11+
{guild.name.match(/[A-Z]/g)?.join("")}
12+
</div>
13+
);
14+
}
15+
16+
return (
17+
<Image
18+
alt={guild.name + " icon"}
19+
className="text-center"
20+
height={64}
21+
src={
22+
guild.icon
23+
? guild.icon + "?size=256"
24+
: "https://cdn.discordapp.com/embed/avatars/0.png"
25+
}
26+
/>
27+
);
28+
}

web/pages/dashboard/index.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { useRouter } from "next/router";
22
import { useQuery } from "@tanstack/react-query";
3-
import { Button, Image } from "@nextui-org/react";
3+
import { Button } from "@nextui-org/react";
44
import Link from "next/link";
55

66
import DefaultLayout from "@/layouts/default";
77
import { API_URL, useUser } from "@/lib/queries";
88
import { subtitle, title } from "@/components/primitives";
99
import { LoaderIcon } from "@/components/icons";
10+
import { ServerIcon } from "@/components/server-icon";
1011

1112
interface Guild {
1213
id: string;
@@ -60,17 +61,7 @@ export default function Dashboard() {
6061
className="bg-gray-800 p-6 rounded-lg flex flex-col justify-center space-y-4 shadow-lg"
6162
>
6263
<div className="flex flex-col space-y-3 items-center justify-center">
63-
<Image
64-
alt={guild.name + " avatar"}
65-
className="text-center"
66-
height={64}
67-
src={
68-
guild.icon
69-
? guild.icon +
70-
"?size=256"
71-
: "https://cdn.discordapp.com/embed/avatars/0.png"
72-
}
73-
/>
64+
<ServerIcon guild={guild} />
7465
<span className="text-white text-2xl font-bold text-center">
7566
{guild.name}
7667
</span>

0 commit comments

Comments
 (0)