-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscordWidget.astro
More file actions
184 lines (174 loc) · 6.71 KB
/
Copy pathDiscordWidget.astro
File metadata and controls
184 lines (174 loc) · 6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
---
import {
countMembersByStatus,
formatPresenceCount,
sortMembersByStatus,
} from "../../lib/discordWidget";
import type { DiscordWidgetData } from "../../schemas/discordWidget";
import DiscordCTA from "./DiscordCTA.astro";
interface Props {
widget: DiscordWidgetData | null;
inviteUrl: string;
}
const { widget, inviteUrl } = Astro.props;
const statusDot = {
online: "bg-mod",
idle: "bg-admin",
dnd: "bg-red-500",
offline: "bg-ink-muted",
} as const;
const displayedMembers = widget
? sortMembersByStatus(widget.members).slice(0, 12)
: [];
const statusCounts = widget ? countMembersByStatus(widget.members) : null;
const joinUrl = widget?.instant_invite ?? inviteUrl;
const sortedChannels = widget
? [...widget.channels].sort((a, b) => a.position - b.position)
: [];
console.log(sortedChannels);
---
<section
class="border-b border-border bg-surface py-16 sm:py-20"
aria-labelledby="discord-widget-heading"
>
<div class="mx-auto max-w-6xl px-4 sm:px-6">
<div class="mx-auto max-w-3xl text-center">
<h2
id="discord-widget-heading"
class="text-2xl font-bold tracking-tight text-ink sm:text-3xl"
>
See who's online
</h2>
<p class="mt-3 text-ink-muted">
Live from the server — members hanging out right now.
</p>
</div>
{
widget ? (
<div class="mx-auto mt-10 max-w-2xl overflow-hidden rounded-xl border border-border bg-surface-elevated shadow-lg">
<div class="h-1 w-full pride-border" aria-hidden="true" />
<div class="border-b border-border px-5 py-4 sm:px-6">
<div class="flex flex-wrap items-center justify-between gap-4">
<div class="text-left">
<p class="text-xs font-semibold uppercase tracking-wider text-admin">
{widget.name}
</p>
<p class="mt-1 flex items-center gap-2 text-2xl font-bold text-ink">
<span class="relative flex h-3 w-3" aria-hidden="true">
<span class="absolute inline-flex h-full w-full animate-ping rounded-full bg-mod opacity-40" />
<span class="relative inline-flex h-3 w-3 rounded-full bg-mod" />
</span>
{formatPresenceCount(widget.presence_count)} online
</p>
</div>
{statusCounts && (
<dl class="flex flex-wrap gap-3 text-xs text-ink-muted">
<div class="flex items-center gap-1.5">
<span
class={`h-2 w-2 rounded-full ${statusDot.online}`}
aria-hidden="true"
/>
<dt class="sr-only">Online</dt>
<dd>{statusCounts.online} active</dd>
</div>
<div class="flex items-center gap-1.5">
<span
class={`h-2 w-2 rounded-full ${statusDot.idle}`}
aria-hidden="true"
/>
<dt class="sr-only">Idle</dt>
<dd>{statusCounts.idle} idle</dd>
</div>
<div class="flex items-center gap-1.5">
<span
class={`h-2 w-2 rounded-full ${statusDot.dnd}`}
aria-hidden="true"
/>
<dt class="sr-only">Do not disturb</dt>
<dd>{statusCounts.dnd} busy</dd>
</div>
</dl>
)}
</div>
</div>
{sortedChannels.length > 0 && (
<div class="border-b border-border px-5 py-4 sm:px-6">
<h3 class="text-left text-xs font-semibold uppercase tracking-wider text-ink-muted">
Open channels
</h3>
<ul class="mt-3 flex flex-wrap gap-2">
{sortedChannels.map((channel) => (
<li>
<span class="inline-flex items-center gap-1.5 rounded-full border border-border bg-surface px-3 py-1 text-sm text-ink-muted">
<span aria-hidden="true">🔊</span>
{channel.name}
</span>
</li>
))}
</ul>
</div>
)}
<div class="px-5 py-4 sm:px-6">
<h3 class="text-left text-xs font-semibold uppercase tracking-wider text-ink-muted">
Members in the lounge
</h3>
<ul class="mt-3 grid gap-2 sm:grid-cols-2">
{displayedMembers.map((member) => {
const status = member.status ?? "offline";
return (
<li class="flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2">
<span class="relative shrink-0">
<img
src={member.avatar_url}
alt=""
width="36"
height="36"
class="h-9 w-9 rounded-full"
loading="lazy"
/>
<span
class:list={[
"absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full border-2 border-surface",
statusDot[status],
]}
aria-hidden="true"
/>
</span>
<div class="min-w-0 text-left">
<p class="truncate text-sm font-medium text-ink">
{member.username}
</p>
{member.game && (
<p class="truncate text-xs text-ink-muted">
Playing {member.game.name}
</p>
)}
</div>
</li>
);
})}
</ul>
{widget.members.length > displayedMembers.length && (
<p class="mt-3 text-center text-sm text-ink-muted">
+{widget.members.length - displayedMembers.length} more in the
lounge
</p>
)}
</div>
<div class="border-t border-border bg-surface px-5 py-4 text-center sm:px-6">
<DiscordCTA href={joinUrl} />
</div>
</div>
) : (
<div class="mx-auto mt-10 max-w-md rounded-xl border border-border bg-surface-elevated px-6 py-8 text-center">
<p class="text-ink-muted">
Couldn't load live server data right now.
</p>
<div class="mt-4">
<DiscordCTA href={inviteUrl} />
</div>
</div>
)
}
</div>
</section>