Skip to content

Commit c0569d6

Browse files
committed
feat: functional guild cards
1 parent 484331d commit c0569d6

3 files changed

Lines changed: 45 additions & 32 deletions

File tree

apps/website/src/app/dashboard/_components/GuildCard.tsx

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
'use client';
2-
31
import type { MeGuild } from '@chatsift/api';
4-
import Image from 'next/image';
2+
import { GuildIcon } from '@/components/common/GuildIcon';
53
import { SvgAutoModerator } from '@/components/icons/SvgAutoModerator';
64
import { cn } from '@/utils/util';
75

86
interface GuildCardProps {
97
readonly data: MeGuild;
108
}
119

12-
function getGuildAcronym(guildName: string) {
13-
return guildName
14-
.replaceAll("'s ", ' ')
15-
.replaceAll(/\w+/g, (substring) => substring[0]!)
16-
.replaceAll(/\s/g, '');
17-
}
18-
1910
export default function GuildCard({ data }: GuildCardProps) {
2011
const hasBots = data.bots.length > 0;
21-
const icon = data?.icon ? `https://cdn.discordapp.com/icons/${data.id}/${data.icon}.png` : null;
2212
const url = hasBots ? `/dashboard/${data.id}` : undefined;
2313

2414
return (
@@ -28,24 +18,7 @@ export default function GuildCard({ data }: GuildCardProps) {
2818
hasBots ? 'bg-[#FFFFFF] dark:bg-[#1C1C21]' : 'group',
2919
)}
3020
>
31-
<div className="flex flex-row items-center">
32-
{icon ? (
33-
<a href={url}>
34-
{/* TODO: GuildIcon component */}
35-
<Image
36-
alt="Guild icon"
37-
className="flex h-12 w-12 items-center justify-center rounded-full border-on-secondary bg-on-tertiary dark:border-on-secondary-dark dark:bg-on-tertiary-dark"
38-
height={48}
39-
src={icon}
40-
width={48}
41-
/>
42-
</a>
43-
) : (
44-
<p className="flex h-12 w-12 items-center justify-center overflow-hidden text-ellipsis whitespace-nowrap rounded-full border-on-secondary bg-on-tertiary after:max-w-[70%] dark:border-on-secondary-dark dark:bg-on-tertiary-dark">
45-
{getGuildAcronym(data.name)}
46-
</p>
47-
)}
48-
</div>
21+
<GuildIcon data={data} hasBots={hasBots} />
4922
<div className="flex flex-col gap-1">
5023
<p className="w-full overflow-hidden overflow-ellipsis whitespace-nowrap text-lg font-medium text-primary group-hover:hidden dark:text-primary-dark">
5124
<a href={url}>{data.name}</a>

apps/website/src/app/dashboard/_components/GuildList.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ export function GuildList() {
1111

1212
const searchQuery = searchParams.get('search') ?? '';
1313

14+
const manageable = useMemo(() => me?.guilds.filter((g) => g.meCanManage) ?? [], [me]);
1415
const sorted = useMemo(() => {
1516
const lower = searchQuery.toLowerCase();
1617

17-
if (!me) {
18+
if (!manageable.length) {
1819
return [];
1920
}
2021

21-
const filtered = me.guilds.filter((guild) => guild.name.toLowerCase().includes(lower));
22+
const filtered = manageable.filter((guild) => guild.name.toLowerCase().includes(lower));
2223
return filtered.reverse().sort((a, b) => b.bots.length - a.bots.length);
23-
}, [me, searchQuery]);
24+
}, [manageable, searchQuery]);
2425

2526
return (
2627
<ul className="grid grid-cols-1 gap-4 md:grid-cols-4">
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { MeGuild } from '@chatsift/api';
2+
import Image from 'next/image';
3+
4+
function getGuildAcronym(guildName: string) {
5+
return guildName
6+
.replaceAll("'s ", ' ')
7+
.replaceAll(/\w+/g, (substring) => substring[0]!)
8+
.replaceAll(/\s/g, '');
9+
}
10+
11+
export interface GuildIconProps {
12+
readonly data: MeGuild;
13+
readonly hasBots: boolean;
14+
}
15+
16+
export function GuildIcon({ data, hasBots }: GuildIconProps) {
17+
const icon = data?.icon ? `https://cdn.discordapp.com/icons/${data.id}/${data.icon}.png` : null;
18+
const url = hasBots ? `/dashboard/${data.id}` : undefined;
19+
20+
return (
21+
<div className="flex flex-row items-center">
22+
{icon ? (
23+
<a href={url}>
24+
<Image
25+
alt="Guild icon"
26+
className="flex h-12 w-12 items-center justify-center rounded-full border-on-secondary bg-on-tertiary dark:border-on-secondary-dark dark:bg-on-tertiary-dark"
27+
height={48}
28+
src={icon}
29+
width={48}
30+
/>
31+
</a>
32+
) : (
33+
<p className="flex h-12 w-12 items-center justify-center overflow-hidden text-ellipsis whitespace-nowrap rounded-full border-on-secondary bg-on-tertiary after:max-w-[70%] dark:border-on-secondary-dark dark:bg-on-tertiary-dark">
34+
{getGuildAcronym(data.name)}
35+
</p>
36+
)}
37+
</div>
38+
);
39+
}

0 commit comments

Comments
 (0)