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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
import { type JSX, Show, onMount, onCleanup, createEffect } from "solid-js";
import { For } from "solid-js/web";
import { A, useLocation } from "@solidjs/router";
import Sidebar from "./Sidebar";
import NavSection from "./NavSection";
import { auth } from "../store/auth";
import { stats } from "../store/stats";
import { UserRole } from "../types/roles";
import type { CitizenSummary } from "../types/stats";
interface LayoutProps {
children: JSX.Element;
}
export default function Layout(props: LayoutProps) {
let heartbeatInterval: ReturnType<typeof setInterval> | undefined;
const location = useLocation();
onMount(() => {
auth.initialize();
stats.load();
function handleExternalLinks(event: MouseEvent) {
const anchor = (event.target as HTMLElement).closest("a");
if (!anchor || !anchor.href) return;
try {
const url = new URL(anchor.href);
if (url.hostname !== window.location.hostname) {
anchor.setAttribute("target", "_blank");
anchor.setAttribute("rel", "noopener noreferrer");
}
} catch {}
}
document.addEventListener("click", handleExternalLinks);
onCleanup(() => document.removeEventListener("click", handleExternalLinks));
});
createEffect(() => {
location.pathname;
stats.load();
});
createEffect(() => {
clearInterval(heartbeatInterval);
if (auth.user()) {
auth.heartbeat();
heartbeatInterval = setInterval(() => auth.heartbeat(), 2 * 60 * 1000);
}
});
onCleanup(() => clearInterval(heartbeatInterval));
return (
<>
<header class="site-header">
<h1>Pagoda</h1>
<p>A community for the small web</p>
</header>
<nav class="top-nav">
<A href="/" class="top-nav-link" data-accent="cyan" activeClass="active" end>Home</A>
<A href="/districts" class="top-nav-link" data-accent="green" activeClass="active">Districts</A>
<A href="/forums" class="top-nav-link" data-accent="pink" activeClass="active">Forums</A>
<A href="/tavern" class="top-nav-link" data-accent="yellow" activeClass="active">Tavern</A>
<A href="/bazaar" class="top-nav-link" data-accent="purple" activeClass="active">Bazaar</A>
</nav>
<div class="search-bar">
<input type="text" placeholder="Search citizens, posts, districts..." />
</div>
<div class="site-main">
<Sidebar>
<NavSection title="Account" accent="pink">
<ul>
<Show when={auth.user()} fallback={
<>
<li><A href="/login">Log In</A></li>
<li><A href="/register">Register</A></li>
</>
}>
{((user) => (
<>
<li><A href={`/p/${user.username}`}>My Domain</A></li>
<li><A href="/letters">Letters</A></li>
<li><A href="/account">Account</A></li>
<li><A href="/account/settings">Settings</A></li>
<li><button type="button" class="sidebar-logout" onClick={() => auth.logout()}>Log Out</button></li>
</>
))(auth.user()!)}
</Show>
</ul>
</NavSection>
<NavSection title="Community" accent="cyan">
<ul>
<li><A href="/citizens">Citizens</A></li>
<li><A href="/clubs">Clubs</A></li>
<li><A href="/interests">Interests</A></li>
</ul>
</NavSection>
<NavSection title="Explore" accent="yellow">
<ul>
<li><A href="/online">Who's Online</A></li>
<li><A href="/random">Random Domain</A></li>
</ul>
</NavSection>
<NavSection title="Services" accent="green">
<ul>
<li><A href="/caravan">Caravan</A></li>
<li><A href="/ledger">Ledger</A></li>
<li><A href="/census">Census</A></li>
<li><A href="/pamphlet">Pamphlet</A></li>
</ul>
</NavSection>
<Show when={auth.user()?.role === UserRole.Owner || auth.user()?.role === UserRole.Admin || auth.user()?.role === UserRole.Moderator}>
<NavSection title="Council" accent="red">
<ul>
<Show when={auth.user()?.role === UserRole.Owner || auth.user()?.role === UserRole.Admin}>
<li><A href="/council/announcements">Announcements</A></li>
<li><A href="/council/auditlog">Audit Log</A></li>
<li><A href="/council/bannedips">Banned IPs</A></li>
</Show>
<li><A href="/council/bazaar">Bazaar</A></li>
<li><A href="/council/districts">Districts</A></li>
<li><A href="/council/forums">Forums</A></li>
<li><A href="/council/reports">Reports</A></li>
<li><A href="/council/users">Users</A></li>
</ul>
</NavSection>
</Show>
</Sidebar>
<main class="content">
{props.children}
</main>
<Sidebar>
<NavSection title="Statistics" accent="yellow">
<ul>
<li>Citizens: {stats.data()?.citizens ?? "—"}</li>
<li>Online: {stats.data()?.online ?? "—"}</li>
<li>Posts Today: —</li>
</ul>
</NavSection>
<NavSection title="New Citizens" accent="cyan">
<ul>
<Show when={stats.data()?.newest_citizens?.length} fallback={
<li class="placeholder">Be the first to join!</li>
}>
<For each={stats.data()?.newest_citizens}>
{(citizen: CitizenSummary) => (
<li class="citizen-item">
<A href={`/p/${citizen.username}`}>
<img src={citizen.avatar_url} alt="" class="citizen-avatar" />
{citizen.display_name}
</A>
</li>
)}
</For>
</Show>
</ul>
</NavSection>
<NavSection title="Who's Online" accent="green">
<ul>
<Show when={stats.data()?.online_citizens?.length} fallback={
<li class="placeholder">No one online.</li>
}>
<For each={stats.data()?.online_citizens}>
{(citizen: CitizenSummary) => (
<li class="citizen-item">
<A href={`/p/${citizen.username}`}>
<img src={citizen.avatar_url} alt="" class="citizen-avatar" />
{citizen.display_name}
</A>
</li>
)}
</For>
</Show>
</ul>
</NavSection>
<NavSection title="Birthdays" accent="pink">
<ul>
<li class="placeholder">No birthdays today.</li>
</ul>
</NavSection>
<NavSection title="Top Posters" accent="yellow">
<ul>
<li class="placeholder">No posts yet.</li>
</ul>
</NavSection>
<NavSection title="Staff Online" accent="purple">
<ul>
<li class="placeholder">No staff online.</li>
</ul>
</NavSection>
</Sidebar>
</div>
<footer class="site-footer">
<nav class="footer-links">
<A href="/about">About</A>
<A href="/rules">Rules</A>
<A href="/privacy">Privacy</A>
<A href="/terms">Terms</A>
<A href="/contact">Contact</A>
</nav>
<p>© {new Date().getFullYear()} Pagoda. Brought to you by <a href="https://shi.foo" target="_blank" rel="noopener noreferrer">shi.foo</a>. Powered by <a href="https://nekoweb.org" target="_blank" rel="noopener noreferrer">Nekoweb</a>.</p>
</footer>
</>
);
}
|