xonecas.io
8058
Ir

irvc / commit 4587245

feat: themes, fontsizes and mentions

xonecas2026-10-12 4587245e552ef5fa690bf06bf28f9ae360f4fa63 parent 6f94343

8 files changed

web/index.html+3−1
@@ -10,7 +10,9 @@
1010 if (t !== "light" && t !== "dark") {
1111 t = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1212 }
13- document.documentElement.classList.toggle("dark", t === "dark");
13+ var c = document.documentElement.classList;
14+ c.toggle("dark", t === "dark");
15+ c.toggle("theme-tuxedo", localStorage.getItem("irvc.theme") === "tuxedo");
1416 })();
1517 </script>
1618 <link
web/src/components/ChatPane.tsx+102−4
@@ -10,11 +10,18 @@ import {
1010 } from "react";
1111 import { Paperclip, SendHorizontal } from "lucide-react";
1212 import { Button } from "@/components/ui/button";
13+import { cn } from "cn";
1314 import { api, upload } from "../lib/api";
14-import type { Channel, Message } from "../lib/types";
15+import type { Channel, Message, UserSummary } from "../lib/types";
1516 import Markdown from "./Markdown";
1617
1718 const maxInputHeight = 200;
19+const maxSuggestions = 8;
20+
21+// isMentioned reports whether body contains "@username" as a whole word.
22+function isMentioned(body: string, username: string) {
23+ return new RegExp(`(^|[^\\w-])@${username}(?![\\w-])`, "i").test(body);
24+}
1825
1926 // prose supplies the block-level markdown styling; the CSS vars retune its
2027 // palette to the sepia theme.
@@ -28,11 +35,18 @@ function clock(ts: number) {
2835 export default function ChatPane({
2936 channel,
3037 messages,
38+ users,
39+ username,
3140 }: {
3241 channel: Channel | null;
3342 messages: Message[];
43+ users: UserSummary[];
44+ username: string;
3445 }) {
3546 const [body, setBody] = useState("");
47+ const [mention, setMention] = useState<{ query: string; start: number; index: number } | null>(
48+ null,
49+ );
3650 const listRef = useRef<HTMLDivElement>(null);
3751 const contentRef = useRef<HTMLDivElement>(null);
3852 const stickRef = useRef(true);
@@ -90,6 +104,35 @@ export default function ChatPane({
90104 setBody((b) => b.slice(0, start) + text + b.slice(end));
91105 }
92106
107+ function suggest(query: string) {
108+ const q = query.toLowerCase();
109+ return users.filter((u) => u.username.toLowerCase().startsWith(q)).slice(0, maxSuggestions);
110+ }
111+
112+ // detectMention looks for an "@partial" token ending at the caret.
113+ function detectMention(value: string, caret: number) {
114+ const m = /(?:^|\s)@([\w-]*)$/.exec(value.slice(0, caret));
115+ const query = m?.[1];
116+ setMention(
117+ query !== undefined && suggest(query).length > 0
118+ ? { query, start: caret - query.length, index: 0 }
119+ : null,
120+ );
121+ }
122+
123+ function chooseMention(name: string) {
124+ const el = textareaRef.current;
125+ if (!el || !mention) return;
126+ const caret = el.selectionStart ?? body.length;
127+ setBody(body.slice(0, mention.start) + name + " " + body.slice(caret));
128+ setMention(null);
129+ const pos = mention.start + name.length + 1;
130+ requestAnimationFrame(() => {
131+ el.focus();
132+ el.setSelectionRange(pos, pos);
133+ });
134+ }
135+
93136 async function attach(files: File[]) {
94137 for (const file of files) {
95138 if (!file.type.startsWith("image/")) continue;
@@ -113,6 +156,7 @@ export default function ChatPane({
113156 const text = body.trim();
114157 if (!text || !channel) return;
115158 setBody("");
159+ setMention(null);
116160 try {
117161 await api(`/channels/${channel.id}/messages`, {
118162 method: "POST",
@@ -129,6 +173,29 @@ export default function ChatPane({
129173 }
130174
131175 function onKeyDown(e: KeyboardEvent<HTMLTextAreaElement>) {
176+ const matches = mention ? suggest(mention.query) : [];
177+ if (mention && matches.length > 0) {
178+ if (e.key === "ArrowDown") {
179+ e.preventDefault();
180+ setMention({ ...mention, index: (mention.index + 1) % matches.length });
181+ return;
182+ }
183+ if (e.key === "ArrowUp") {
184+ e.preventDefault();
185+ setMention({ ...mention, index: (mention.index - 1 + matches.length) % matches.length });
186+ return;
187+ }
188+ if (e.key === "Enter" || e.key === "Tab") {
189+ e.preventDefault();
190+ chooseMention(matches[mention.index].username);
191+ return;
192+ }
193+ if (e.key === "Escape") {
194+ e.preventDefault();
195+ setMention(null);
196+ return;
197+ }
198+ }
132199 if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
133200 e.preventDefault();
134201 send();
@@ -145,8 +212,15 @@ export default function ChatPane({
145212 <div ref={contentRef}>
146213 {messages.map((m) => {
147214 const action = m.body.startsWith("/me ") ? m.body.slice(4) : null;
215+ const hit = !action && isMentioned(m.body, username);
148216 return (
149- <div key={m.id} className="flex gap-1.5 py-0.5 text-sm leading-6">
217+ <div
218+ key={m.id}
219+ className={cn(
220+ "-mx-1.5 flex gap-1.5 rounded px-1.5 py-0.5 text-sm leading-6",
221+ hit && "bg-[color-mix(in_srgb,var(--gold)_14%,transparent)]",
222+ )}
223+ >
150224 <span className="shrink-0">
151225 <span className="text-sepia/40">{clock(m.createdAt)}</span>{" "}
152226 {!action && <span className="text-gold/90">{m.username}</span>}
@@ -165,7 +239,28 @@ export default function ChatPane({
165239 })}
166240 </div>
167241 </div>
168- <form onSubmit={submit} className="flex items-end gap-2 border-t border-sepia/15 p-3">
242+ <form
243+ onSubmit={submit}
244+ className="relative flex items-end gap-2 border-t border-sepia/15 p-3"
245+ >
246+ {mention && suggest(mention.query).length > 0 && (
247+ <div className="absolute bottom-full left-2 mb-1 w-56 overflow-hidden rounded-lg border border-border bg-panel shadow-lg">
248+ {suggest(mention.query).map((u, i) => (
249+ <button
250+ key={u.id}
251+ type="button"
252+ onMouseDown={(e) => e.preventDefault()}
253+ onClick={() => chooseMention(u.username)}
254+ className={cn(
255+ "block w-full px-3 py-1.5 text-left text-sm",
256+ i === mention.index ? "bg-accent text-accent-foreground" : "text-sepia",
257+ )}
258+ >
259+ {u.username}
260+ </button>
261+ ))}
262+ </div>
263+ )}
169264 <input
170265 ref={fileRef}
171266 type="file"
@@ -191,7 +286,10 @@ export default function ChatPane({
191286 rows={1}
192287 placeholder={`message #${channel.name}`}
193288 value={body}
194- onChange={(e) => setBody(e.target.value)}
289+ onChange={(e) => {
290+ setBody(e.target.value);
291+ detectMention(e.target.value, e.target.selectionStart ?? e.target.value.length);
292+ }}
195293 onKeyDown={onKeyDown}
196294 onPaste={onPaste}
197295 className="max-h-[200px] w-full resize-none rounded-lg border border-input bg-transparent px-2.5 py-1 text-base leading-6 outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 dark:bg-input/30 md:text-sm"
web/src/components/SettingsPanel.tsx+29−1
@@ -3,7 +3,8 @@ import { HeadphoneOff, Headphones } from "lucide-react";
33 import { Room } from "livekit-client";
44 import { Button } from "@/components/ui/button";
55 import { cn } from "cn";
6-import type { AudioPresetName, Settings } from "../lib/settings";
6+import type { AudioPresetName, FontSize, Settings } from "../lib/settings";
7+import type { Theme } from "../lib/theme";
78 import { useMicPreview, type Voice } from "../lib/voice";
89
910 const minDb = -60;
@@ -49,10 +50,14 @@ export default function SettingsPanel({
4950 settings,
5051 update,
5152 voice,
53+ theme,
54+ onThemeChange,
5255 }: {
5356 settings: Settings;
5457 update: (patch: Partial<Settings>) => void;
5558 voice: Voice;
59+ theme: Theme;
60+ onThemeChange: (theme: Theme) => void;
5661 }) {
5762 const mics = useDevices("audioinput");
5863 const speakers = useDevices("audiooutput");
@@ -64,6 +69,29 @@ export default function SettingsPanel({
6469 return (
6570 <div className="flex-1 overflow-y-auto">
6671 <div className="mx-auto max-w-2xl space-y-4 p-6">
72+ <Group label="Appearance">
73+ <Field label="theme">
74+ <Select
75+ value={theme}
76+ onChange={(v) => onThemeChange(v as Theme)}
77+ options={[
78+ { value: "80s-nicotine", label: "80s nicotine" },
79+ { value: "tuxedo", label: "tuxedo" },
80+ ]}
81+ />
82+ </Field>
83+ <Field label="font size">
84+ <Select
85+ value={settings.fontSize}
86+ onChange={(v) => update({ fontSize: v as FontSize })}
87+ options={[
88+ { value: "default", label: "default" },
89+ { value: "large", label: "Help, I'm old" },
90+ ]}
91+ />
92+ </Field>
93+ </Group>
94+
6795 <Group label="Voice">
6896 <Button
6997 variant={settings.deafened ? "secondary" : "ghost"}
web/src/components/Sidebar.tsx+8−8
@@ -16,7 +16,7 @@ import {
1616 import { Button } from "@/components/ui/button";
1717 import { api } from "../lib/api";
1818 import type { Channel, UserSummary } from "../lib/types";
19-import type { Theme } from "../lib/theme";
19+import type { Mode } from "../lib/theme";
2020 import type { Voice } from "../lib/voice";
2121 import UserList from "./UserList";
2222 import VoicePeers from "./VoicePeers";
@@ -35,8 +35,8 @@ export default function Sidebar({
3535 username,
3636 users,
3737 online,
38- theme,
39- onToggleTheme,
38+ mode,
39+ onToggleMode,
4040 settingsOpen,
4141 onToggleSettings,
4242 onLogout,
@@ -49,8 +49,8 @@ export default function Sidebar({
4949 username: string;
5050 users: UserSummary[];
5151 online: Set<string>;
52- theme: Theme;
53- onToggleTheme: () => void;
52+ mode: Mode;
53+ onToggleMode: () => void;
5454 settingsOpen: boolean;
5555 onToggleSettings: () => void;
5656 onLogout: () => void;
@@ -120,10 +120,10 @@ export default function Sidebar({
120120 <Button
121121 variant="ghost"
122122 size="icon-sm"
123- onClick={onToggleTheme}
124- title={theme === "dark" ? "light mode" : "dark mode"}
123+ onClick={onToggleMode}
124+ title={mode === "dark" ? "light mode" : "dark mode"}
125125 >
126- {theme === "dark" ? <Sun /> : <Moon />}
126+ {mode === "dark" ? <Sun /> : <Moon />}
127127 </Button>
128128 <Button
129129 variant={settingsOpen ? "secondary" : "ghost"}
web/src/index.css+77−0
@@ -155,6 +155,83 @@ body {
155155 --sidebar-ring: #ffcc55;
156156 }
157157
158+/* tuxedo: grayscale white-to-black, same scale as the default. */
159+.theme-tuxedo {
160+ --bg: #ffffff;
161+ --panel: #f2f2f2;
162+ --sepia: #1a1a1a;
163+ --gold: #4d4d4d;
164+ --background: #ffffff;
165+ --foreground: #1a1a1a;
166+ --card: #f2f2f2;
167+ --card-foreground: #1a1a1a;
168+ --popover: #f2f2f2;
169+ --popover-foreground: #1a1a1a;
170+ --primary: #4d4d4d;
171+ --primary-foreground: #ffffff;
172+ --secondary: #e6e6e6;
173+ --secondary-foreground: #1a1a1a;
174+ --muted: #e6e6e6;
175+ --muted-foreground: #6b6b6b;
176+ --accent: #d9d9d9;
177+ --accent-foreground: #0d0d0d;
178+ --destructive: #404040;
179+ --border: #d9d9d9;
180+ --input: #d9d9d9;
181+ --ring: #4d4d4d;
182+ --chart-1: #4d4d4d;
183+ --chart-2: #737373;
184+ --chart-3: #1a1a1a;
185+ --chart-4: #b3b3b3;
186+ --chart-5: #d9d9d9;
187+ --sidebar: #f7f7f7;
188+ --sidebar-foreground: #1a1a1a;
189+ --sidebar-primary: #4d4d4d;
190+ --sidebar-primary-foreground: #ffffff;
191+ --sidebar-accent: #e6e6e6;
192+ --sidebar-accent-foreground: #1a1a1a;
193+ --sidebar-border: #d9d9d9;
194+ --sidebar-ring: #4d4d4d;
195+}
196+
197+.dark.theme-tuxedo {
198+ --bg: #000000;
199+ --panel: #0d0d0d;
200+ --sepia: #e6e6e6;
201+ --gold: #bfbfbf;
202+ --background: #000000;
203+ --foreground: #e6e6e6;
204+ --card: #0d0d0d;
205+ --card-foreground: #e6e6e6;
206+ --popover: #0d0d0d;
207+ --popover-foreground: #e6e6e6;
208+ --primary: #bfbfbf;
209+ --primary-foreground: #000000;
210+ --secondary: #1a1a1a;
211+ --secondary-foreground: #e6e6e6;
212+ --muted: #1a1a1a;
213+ --muted-foreground: #808080;
214+ --accent: #262626;
215+ --accent-foreground: #cccccc;
216+ --destructive: #8c8c8c;
217+ --border: #262626;
218+ --input: #262626;
219+ --ring: #bfbfbf;
220+ --chart-1: #bfbfbf;
221+ --chart-2: #999999;
222+ --chart-3: #737373;
223+ --chart-4: #4d4d4d;
224+ --chart-5: #262626;
225+ --sidebar: #050505;
226+ --sidebar-foreground: #e6e6e6;
227+ --sidebar-primary: #bfbfbf;
228+ --sidebar-primary-foreground: #000000;
229+ --sidebar-accent: #1a1a1a;
230+ --sidebar-accent-foreground: #e6e6e6;
231+ --sidebar-border: #262626;
232+ --sidebar-ring: #bfbfbf;
233+}
234+
158235 @layer base {
159236 * {
160237 @apply border-border outline-ring/50;
web/src/lib/settings.ts+4−0
@@ -1,5 +1,7 @@
11 import { useCallback, useEffect, useState } from "react";
22
3+export type FontSize = "default" | "large";
4+
35 export type AudioPresetName =
46 | "telephone"
57 | "speech"
@@ -18,6 +20,7 @@ export interface Settings {
1820 speakerDeviceId: string;
1921 deafened: boolean;
2022 gateThreshold: number;
23+ fontSize: FontSize;
2124 }
2225
2326 export const defaultSettings: Settings = {
@@ -30,6 +33,7 @@ export const defaultSettings: Settings = {
3033 speakerDeviceId: "",
3134 deafened: false,
3235 gateThreshold: -60,
36+ fontSize: "default",
3337 };
3438
3539 const key = "irvc.settings";
web/src/lib/theme.ts+21−9
@@ -1,23 +1,35 @@
11 import { useCallback, useEffect, useState } from "react";
22
3-export type Theme = "light" | "dark";
3+export type Mode = "light" | "dark";
4+export type Theme = "80s-nicotine" | "tuxedo";
45
5-function initial(): Theme {
6+function initialMode(): Mode {
67 const saved = localStorage.getItem("theme");
78 if (saved === "light" || saved === "dark") return saved;
89 return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
910 }
1011
11-// useTheme keeps the `dark` class on <html> in sync, seeding from the OS on
12-// first visit. index.html applies the same choice before paint.
12+function initialTheme(): Theme {
13+ return localStorage.getItem("irvc.theme") === "tuxedo" ? "tuxedo" : "80s-nicotine";
14+}
15+
16+// useTheme keeps the `dark` class (light/dark mode) and the palette class
17+// (`theme-tuxedo`) on <html> in sync, seeding from the OS on first visit.
18+// index.html applies the same choices before paint.
1319 export function useTheme() {
14- const [theme, setTheme] = useState<Theme>(initial);
20+ const [mode, setMode] = useState<Mode>(initialMode);
21+ const [theme, setTheme] = useState<Theme>(initialTheme);
22+
23+ useEffect(() => {
24+ document.documentElement.classList.toggle("dark", mode === "dark");
25+ localStorage.setItem("theme", mode);
26+ }, [mode]);
1527
1628 useEffect(() => {
17- document.documentElement.classList.toggle("dark", theme === "dark");
18- localStorage.setItem("theme", theme);
29+ document.documentElement.classList.toggle("theme-tuxedo", theme === "tuxedo");
30+ localStorage.setItem("irvc.theme", theme);
1931 }, [theme]);
2032
21- const toggle = useCallback(() => setTheme((t) => (t === "dark" ? "light" : "dark")), []);
22- return { theme, toggle };
33+ const toggleMode = useCallback(() => setMode((m) => (m === "dark" ? "light" : "dark")), []);
34+ return { mode, toggleMode, theme, setTheme };
2335 }
web/src/views/Chat.tsx+15−5
@@ -29,7 +29,11 @@ export default function Chat({ user, onLogout }: { user: User; onLogout: () => v
2929 }
3030 });
3131 const [voiceRooms, setVoiceRooms] = useState<Record<string, string[]>>({});
32- const { theme, toggle } = useTheme();
32+ const { mode, toggleMode, theme, setTheme } = useTheme();
33+
34+ useEffect(() => {
35+ document.documentElement.style.fontSize = settings.fontSize === "large" ? "18px" : "";
36+ }, [settings.fontSize]);
3337
3438 useEffect(() => {
3539 selectedId.current = selected?.id ?? null;
@@ -111,8 +115,8 @@ export default function Chat({ user, onLogout }: { user: User; onLogout: () => v
111115 username={user.username}
112116 users={users}
113117 online={online}
114- theme={theme}
115- onToggleTheme={toggle}
118+ mode={mode}
119+ onToggleMode={toggleMode}
116120 settingsOpen={settingsOpen}
117121 onToggleSettings={toggleSettings}
118122 onLogout={logout}
@@ -143,9 +147,15 @@ export default function Chat({ user, onLogout }: { user: User; onLogout: () => v
143147 </span>
144148 </header>
145149 {settingsOpen ? (
146- <SettingsPanel settings={settings} update={update} voice={voice} />
150+ <SettingsPanel
151+ settings={settings}
152+ update={update}
153+ voice={voice}
154+ theme={theme}
155+ onThemeChange={setTheme}
156+ />
147157 ) : (
148- <ChatPane channel={selected} messages={messages} />
158+ <ChatPane channel={selected} messages={messages} users={users} username={user.username} />
149159 )}
150160 </main>
151161 </div>