xonecas.io
8058
Ir

irvc / commit abb713e

feat: UI improvements, per user volumes.

xonecas2026-10-11 abb713eea80499452952d79b1a3e2de82d82d5ce parent 09a04ff

6 files changed

web/src/components/ChatPane.tsx+41−15
@@ -1,5 +1,6 @@
11 import {
22 useEffect,
3+ useLayoutEffect,
34 useRef,
45 useState,
56 type ClipboardEvent,
@@ -31,14 +32,31 @@ export default function ChatPane({
3132 messages: Message[];
3233 }) {
3334 const [body, setBody] = useState("");
34- const endRef = useRef<HTMLDivElement>(null);
35+ const listRef = useRef<HTMLDivElement>(null);
36+ const stickRef = useRef(true);
3537 const textareaRef = useRef<HTMLTextAreaElement>(null);
3638 const fileRef = useRef<HTMLInputElement>(null);
3739
38- useEffect(() => {
39- endRef.current?.scrollIntoView();
40+ // Jump to the bottom on channel switch, regardless of prior position.
41+ useLayoutEffect(() => {
42+ stickRef.current = true;
43+ const el = listRef.current;
44+ if (el) el.scrollTop = el.scrollHeight;
45+ }, [channel]);
46+
47+ // Follow new messages only while the user is pinned to the bottom. Layout
48+ // effect so the initial history scrolls before the browser can unpin us.
49+ useLayoutEffect(() => {
50+ const el = listRef.current;
51+ if (el && stickRef.current) el.scrollTop = el.scrollHeight;
4052 }, [messages]);
4153
54+ function onScroll() {
55+ const el = listRef.current;
56+ if (!el) return;
57+ stickRef.current = el.scrollHeight - el.scrollTop - el.clientHeight < 40;
58+ }
59+
4260 useEffect(() => {
4361 const el = textareaRef.current;
4462 if (!el) return;
@@ -107,19 +125,27 @@ export default function ChatPane({
107125
108126 return (
109127 <>
110- <div className="flex-1 overflow-y-auto px-4 py-3">
111- {messages.map((m) => (
112- <div key={m.id} className="flex gap-1.5 py-0.5 text-sm leading-6">
113- <span className="shrink-0">
114- <span className="text-sepia/40">{clock(m.createdAt)}</span>{" "}
115- <span className="text-gold/90">{m.username}</span>
116- </span>
117- <div className={bodyClass}>
118- <Markdown text={m.body} />
128+ <div ref={listRef} onScroll={onScroll} className="min-h-0 flex-1 overflow-y-auto px-4 py-3">
129+ {messages.map((m) => {
130+ const action = m.body.startsWith("/me ") ? m.body.slice(4) : null;
131+ return (
132+ <div key={m.id} className="flex gap-1.5 py-0.5 text-sm leading-6">
133+ <span className="shrink-0">
134+ <span className="text-sepia/40">{clock(m.createdAt)}</span>{" "}
135+ {!action && <span className="text-gold/90">{m.username}</span>}
136+ </span>
137+ {action ? (
138+ <div className="min-w-0 flex-1 break-words italic text-gold/90">
139+ * {m.username} {action}
140+ </div>
141+ ) : (
142+ <div className={bodyClass}>
143+ <Markdown text={m.body} />
144+ </div>
145+ )}
119146 </div>
120- </div>
121- ))}
122- <div ref={endRef} />
147+ );
148+ })}
123149 </div>
124150 <form onSubmit={submit} className="flex items-end gap-2 border-t border-sepia/15 p-3">
125151 <input
web/src/components/Sidebar.tsx+26−32
@@ -4,6 +4,7 @@ import { Button } from "@/components/ui/button";
44 import { api } from "../lib/api";
55 import type { Channel } from "../lib/types";
66 import type { Voice } from "../lib/voice";
7+import VoicePeers from "./VoicePeers";
78
89 interface Invite {
910 token: string;
@@ -15,11 +16,13 @@ export default function Sidebar({
1516 selected,
1617 onSelect,
1718 voice,
19+ username,
1820 }: {
1921 channels: Channel[];
2022 selected: Channel | null;
2123 onSelect: (c: Channel) => void;
2224 voice: Voice;
25+ username: string;
2326 }) {
2427 const [label, setLabel] = useState("create invite");
2528
@@ -50,13 +53,7 @@ export default function Sidebar({
5053 {channels
5154 .filter((c) => c.type === "voice")
5255 .map((c) => (
53- <VoiceChannel
54- key={c.id}
55- channel={c}
56- selected={selected}
57- onSelect={onSelect}
58- voice={voice}
59- />
56+ <VoiceChannel key={c.id} channel={c} voice={voice} username={username} />
6057 ))}
6158 </div>
6259 </nav>
@@ -108,38 +105,21 @@ function Group({
108105
109106 function VoiceChannel({
110107 channel,
111- selected,
112- onSelect,
113108 voice,
109+ username,
114110 }: {
115111 channel: Channel;
116- selected: Channel | null;
117- onSelect: (c: Channel) => void;
118112 voice: Voice;
113+ username: string;
119114 }) {
120115 const active = voice.channel?.id === channel.id;
121116 return (
122117 <div className="pb-1">
123- <Button
124- variant={selected?.id === channel.id ? "secondary" : "ghost"}
125- onClick={() => onSelect(channel)}
126- className="w-full justify-start gap-2 font-normal"
127- >
118+ <div className="flex items-center gap-2 px-2 py-1.5 text-sm text-sepia/70">
128119 <Volume2 size={14} />
129- {channel.name}
130- </Button>
131- <div className="flex items-center gap-1 px-2 pt-0.5">
132- {active ? (
120+ <span className="flex-1 truncate">{channel.name}</span>
121+ {active && (
133122 <>
134- <span className="min-w-0 flex-1 truncate text-xs text-sepia/50">
135- {voice.status === "connecting"
136- ? "connecting…"
137- : voice.error
138- ? voice.error
139- : voice.muted
140- ? "in voice · muted"
141- : "in voice"}
142- </span>
143123 <Button
144124 size="icon-xs"
145125 variant="ghost"
@@ -152,7 +132,21 @@ function VoiceChannel({
152132 <PhoneOff />
153133 </Button>
154134 </>
155- ) : (
135+ )}
136+ </div>
137+ {active && (
138+ <div className="flex flex-col gap-0.5 px-2 pb-0.5">
139+ {voice.status !== "live" ? (
140+ <span className="truncate text-xs text-sepia/50">
141+ {voice.status === "connecting" ? "connecting…" : voice.error || "disconnected"}
142+ </span>
143+ ) : (
144+ <VoicePeers voice={voice} username={username} />
145+ )}
146+ </div>
147+ )}
148+ {!active && (
149+ <div className="px-2 pt-0.5">
156150 <Button
157151 size="xs"
158152 variant="ghost"
@@ -161,8 +155,8 @@ function VoiceChannel({
161155 >
162156 join
163157 </Button>
164- )}
165- </div>
158+ </div>
159+ )}
166160 </div>
167161 );
168162 }
web/src/components/VoicePeers.tsx+88−0
@@ -0,0 +1,88 @@
1+import { useEffect, useState } from "react";
2+import { MicOff, Volume2, VolumeX } from "lucide-react";
3+import { Button } from "@/components/ui/button";
4+import type { Voice } from "../lib/voice";
5+
6+const storageKey = "irvc.peerVolumes";
7+
8+function load(): Record<string, number> {
9+ try {
10+ return JSON.parse(localStorage.getItem(storageKey) ?? "{}");
11+ } catch {
12+ return {};
13+ }
14+}
15+
16+export default function VoicePeers({ voice, username }: { voice: Voice; username: string }) {
17+ const { peers, muted: selfMuted, setPeerVolume } = voice;
18+ const [volumes, setVolumes] = useState<Record<string, number>>(load);
19+ const [muted, setMuted] = useState<Set<string>>(new Set());
20+ const [open, setOpen] = useState<string | null>(null);
21+
22+ // Re-apply on join and on any volume/mute change: the volume map lives on
23+ // each participant, which is a new object every time someone connects.
24+ useEffect(() => {
25+ peers.forEach((p) => setPeerVolume(p, muted.has(p) ? 0 : (volumes[p] ?? 1)));
26+ }, [peers, volumes, muted, setPeerVolume]);
27+
28+ function setVolume(name: string, v: number) {
29+ setVolumes((prev) => {
30+ const next = { ...prev, [name]: v };
31+ localStorage.setItem(storageKey, JSON.stringify(next));
32+ return next;
33+ });
34+ }
35+
36+ function toggleMute(name: string) {
37+ setMuted((prev) => {
38+ const next = new Set(prev);
39+ if (next.has(name)) next.delete(name);
40+ else next.add(name);
41+ return next;
42+ });
43+ }
44+
45+ return (
46+ <>
47+ <div className="flex items-center gap-1.5 text-xs text-sepia/70">
48+ <span className="h-1.5 w-1.5 rounded-full bg-gold" />
49+ {username} <span className="text-sepia/40">(you)</span>
50+ {selfMuted && <MicOff size={10} className="text-sepia/50" />}
51+ </div>
52+ {peers.map((p) => (
53+ <div key={p}>
54+ <button
55+ onClick={() => setOpen((o) => (o === p ? null : p))}
56+ className="flex w-full items-center gap-1.5 text-left text-xs text-sepia/70 hover:text-sepia"
57+ >
58+ <span className="h-1.5 w-1.5 rounded-full bg-gold" />
59+ {p}
60+ {muted.has(p) && <VolumeX size={10} className="text-sepia/50" />}
61+ </button>
62+ {open === p && (
63+ <div className="flex flex-col gap-1 py-1 pl-3.5">
64+ <input
65+ type="range"
66+ min={0}
67+ max={1}
68+ step={0.01}
69+ value={volumes[p] ?? 1}
70+ onChange={(e) => setVolume(p, Number(e.target.value))}
71+ className="w-full accent-gold"
72+ />
73+ <Button
74+ size="xs"
75+ variant="ghost"
76+ className="w-full justify-start gap-1.5 text-xs text-sepia/50"
77+ onClick={() => toggleMute(p)}
78+ >
79+ {muted.has(p) ? <Volume2 size={12} /> : <VolumeX size={12} />}
80+ {muted.has(p) ? "unmute" : "mute"}
81+ </Button>
82+ </div>
83+ )}
84+ </div>
85+ ))}
86+ </>
87+ );
88+}
web/src/components/VoiceRoom.tsx+0−64
@@ -1,64 +0,0 @@
1-import { Mic, MicOff, PhoneOff, Volume2 } from "lucide-react";
2-import { Button } from "@/components/ui/button";
3-import type { Channel } from "../lib/types";
4-import type { Voice } from "../lib/voice";
5-
6-export default function VoiceRoom({
7- channel,
8- username,
9- voice,
10-}: {
11- channel: Channel;
12- username: string;
13- voice: Voice;
14-}) {
15- const active = voice.channel?.id === channel.id;
16-
17- if (!active) {
18- return (
19- <div className="flex flex-1 flex-col items-center justify-center gap-4 text-sm">
20- <div className="text-sepia/50">not in {channel.name}</div>
21- <Button variant="outline" onClick={() => voice.join(channel)}>
22- <Volume2 />
23- join {channel.name}
24- </Button>
25- </div>
26- );
27- }
28-
29- return (
30- <div className="flex flex-1 flex-col items-center justify-center gap-5 text-sm">
31- <div className="text-sepia/50">
32- {voice.status === "connecting"
33- ? "connecting…"
34- : voice.status === "error"
35- ? "voice error"
36- : `connected to ${channel.name}`}
37- </div>
38- {voice.error && <div className="text-gold">{voice.error}</div>}
39- <div className="flex w-56 flex-col gap-1 rounded border border-sepia/15 p-3">
40- <div className="flex items-center gap-2 text-sepia">
41- <span className="h-2 w-2 rounded-full bg-gold" />
42- {username} <span className="text-sepia/40">(you)</span>
43- {voice.muted && <MicOff size={12} className="text-sepia/50" />}
44- </div>
45- {voice.peers.map((p) => (
46- <div key={p} className="flex items-center gap-2 text-sepia">
47- <span className="h-2 w-2 rounded-full bg-gold" />
48- {p}
49- </div>
50- ))}
51- </div>
52- <div className="flex gap-2">
53- <Button variant="outline" onClick={() => voice.toggleMute()}>
54- {voice.muted ? <MicOff /> : <Mic />}
55- {voice.muted ? "unmute" : "mute"}
56- </Button>
57- <Button variant="ghost" onClick={() => voice.leave()}>
58- <PhoneOff />
59- leave
60- </Button>
61- </div>
62- </div>
63- );
64-}
web/src/lib/voice.ts+10−1
@@ -50,6 +50,7 @@ export interface Voice {
5050 join: (c: Channel) => void;
5151 leave: () => void;
5252 toggleMute: () => void;
53+ setPeerVolume: (name: string, volume: number) => void;
5354 }
5455
5556 // useVoice owns the single LiveKit connection for the session so it survives
@@ -181,6 +182,14 @@ export function useVoice(settings: Settings): Voice {
181182 setMuted(next);
182183 }, [muted]);
183184
185+ const setPeerVolume = useCallback((name: string, volume: number) => {
186+ const room = roomRef.current;
187+ if (!room) return;
188+ for (const p of room.remoteParticipants.values()) {
189+ if ((p.name || p.identity) === name) p.setVolume(volume);
190+ }
191+ }, []);
192+
184193 useEffect(
185194 () => () => {
186195 roomRef.current?.disconnect();
@@ -188,5 +197,5 @@ export function useVoice(settings: Settings): Voice {
188197 [],
189198 );
190199
191- return { channel, status, error, peers, muted, join, leave, toggleMute };
200+ return { channel, status, error, peers, muted, join, leave, toggleMute, setPeerVolume };
192201 }
web/src/views/Chat.tsx+10−16
@@ -1,5 +1,5 @@
11 import { useEffect, useRef, useState } from "react";
2-import { Hash, LogOut, Moon, Settings, Sun, Users, Volume2 } from "lucide-react";
2+import { Hash, LogOut, Moon, Settings, Sun, Users } from "lucide-react";
33 import { Button } from "@/components/ui/button";
44 import { api } from "../lib/api";
55 import { useSettings } from "../lib/settings";
@@ -10,7 +10,6 @@ import ChatPane from "../components/ChatPane";
1010 import SettingsPanel from "../components/SettingsPanel";
1111 import Sidebar from "../components/Sidebar";
1212 import UserList from "../components/UserList";
13-import VoiceRoom from "../components/VoiceRoom";
1413
1514 type Panel = "users" | "settings" | null;
1615
@@ -74,21 +73,20 @@ export default function Chat({ user, onLogout }: { user: User; onLogout: () => v
7473
7574 return (
7675 <div className="flex h-full">
77- <Sidebar channels={channels} selected={selected} onSelect={setSelected} voice={voice} />
76+ <Sidebar
77+ channels={channels}
78+ selected={selected}
79+ onSelect={setSelected}
80+ voice={voice}
81+ username={user.username}
82+ />
7883 <main className="flex min-w-0 flex-1 flex-col">
7984 <header className="flex items-center justify-between border-b border-sepia/15 px-4 py-2">
8085 <span className="flex items-center gap-1.5 text-sm text-sepia/70">
81- {selected && (selected.type === "text" ? <Hash size={14} /> : <Volume2 size={14} />)}
86+ {selected && <Hash size={14} />}
8287 {selected?.name}
8388 </span>
8489 <div className="flex items-center gap-1">
85- {voice.channel && (
86- <span className="flex items-center gap-1 pr-2 text-xs text-sepia/50">
87- <Volume2 size={12} />
88- {voice.channel.name}
89- {voice.muted ? " · muted" : ""}
90- </span>
91- )}
9290 <Button
9391 variant="ghost"
9492 size="icon-sm"
@@ -118,11 +116,7 @@ export default function Chat({ user, onLogout }: { user: User; onLogout: () => v
118116 </Button>
119117 </div>
120118 </header>
121- {selected?.type === "voice" ? (
122- <VoiceRoom channel={selected} username={user.username} voice={voice} />
123- ) : (
124- <ChatPane channel={selected} messages={messages} />
125- )}
119+ <ChatPane channel={selected} messages={messages} />
126120 </main>
127121 {panel === "settings" && <SettingsPanel settings={settings} update={update} />}
128122 {panel === "users" && <UserList users={users} online={online} />}