mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
Add right-click context menu on channel tree clients
Works for both other clients (private chat, poke, copy name, plus disabled placeholders for group assignment/kick/ban) and the own client (copy name and group placeholders only, since you can't poke or private-message yourself).
This commit is contained in:
1 parent
af3a7c97cf
commit
0529ab72f1
3 files changed
+146
No files matched your search
@@ -190,6 +190,29 @@
|
||||
background: var(--border-soft);
|
||||
}
|
||||
|
||||
.ts-context-menu {
|
||||
position: fixed;
|
||||
z-index: 30;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 200px;
|
||||
padding: 0.25rem;
|
||||
background: var(--bg-toolbar-1);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.ts-context-menu-title {
|
||||
padding: 0.35rem 0.5rem;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: var(--text-muted);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.ts-toolbar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
+105
@@ -218,6 +218,7 @@ function ChannelTree({
|
||||
onSwitchChannel,
|
||||
onOpenPrivateChat,
|
||||
onPokeClient,
|
||||
onClientContextMenu,
|
||||
}: {
|
||||
channels: ChannelInfo[];
|
||||
clients: ClientInfo[];
|
||||
@@ -229,6 +230,7 @@ function ChannelTree({
|
||||
onSwitchChannel: (channelId: number) => void;
|
||||
onOpenPrivateChat: (clientId: number, clientName: string) => void;
|
||||
onPokeClient: (clientId: number, clientName: string) => void;
|
||||
onClientContextMenu: (e: React.MouseEvent, clientId: number, clientName: string, isSelf: boolean) => void;
|
||||
}) {
|
||||
const t = useT();
|
||||
const children = channels.filter((c) => c.parent === parent).sort((a, b) => a.order - b.order);
|
||||
@@ -260,6 +262,7 @@ function ChannelTree({
|
||||
talkers.has(c.id) ? " ts-talking" : ""
|
||||
}`}
|
||||
onClick={c.id === ownClientId ? undefined : () => onOpenPrivateChat(c.id, c.name)}
|
||||
onContextMenu={(e) => onClientContextMenu(e, c.id, c.name, c.id === ownClientId)}
|
||||
title={c.id === ownClientId ? undefined : `${t("tree.privateChatWith")} ${c.name}`}
|
||||
>
|
||||
<ClientIcon />
|
||||
@@ -295,6 +298,7 @@ function ChannelTree({
|
||||
onSwitchChannel={onSwitchChannel}
|
||||
onOpenPrivateChat={onOpenPrivateChat}
|
||||
onPokeClient={onPokeClient}
|
||||
onClientContextMenu={onClientContextMenu}
|
||||
/>
|
||||
</li>
|
||||
))}
|
||||
@@ -1406,6 +1410,14 @@ function AppInner() {
|
||||
const [pokeMessage, setPokeMessage] = useState("");
|
||||
const pokeBackdrop = useBackdropDismiss(() => setPokeTarget(null));
|
||||
const [demoForceMobile, setDemoForceMobile] = useState(false);
|
||||
const [clientContextMenu, setClientContextMenu] = useState<{
|
||||
x: number;
|
||||
y: number;
|
||||
clientId: number;
|
||||
clientName: string;
|
||||
isSelf: boolean;
|
||||
} | null>(null);
|
||||
const clientContextMenuRef = useRef<HTMLDivElement>(null);
|
||||
const [activeTab, setActiveTab] = useState<ActiveTab>("channel");
|
||||
const [theme, setTheme] = useState<"light" | "dark">(() =>
|
||||
window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light"
|
||||
@@ -1944,6 +1956,22 @@ function AppInner() {
|
||||
};
|
||||
}, [awayMenuOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!clientContextMenu) return;
|
||||
const onPointerDown = (e: MouseEvent) => {
|
||||
if (!clientContextMenuRef.current?.contains(e.target as Node)) setClientContextMenu(null);
|
||||
};
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") setClientContextMenu(null);
|
||||
};
|
||||
window.addEventListener("mousedown", onPointerDown);
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => {
|
||||
window.removeEventListener("mousedown", onPointerDown);
|
||||
window.removeEventListener("keydown", onKeyDown);
|
||||
};
|
||||
}, [clientContextMenu]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!extrasMenuOpen) return;
|
||||
const onPointerDown = (e: MouseEvent) => {
|
||||
@@ -2126,6 +2154,18 @@ function AppInner() {
|
||||
setPokeMessage("");
|
||||
};
|
||||
|
||||
const handleClientContextMenu = (
|
||||
e: React.MouseEvent,
|
||||
clientId: number,
|
||||
clientName: string,
|
||||
isSelf: boolean
|
||||
) => {
|
||||
e.preventDefault();
|
||||
const x = Math.min(e.clientX, window.innerWidth - 220);
|
||||
const y = Math.min(e.clientY, window.innerHeight - 300);
|
||||
setClientContextMenu({ x, y, clientId, clientName, isSelf });
|
||||
};
|
||||
|
||||
const handleSendPoke = () => {
|
||||
if (!pokeTarget) return;
|
||||
socketRef.current?.send(
|
||||
@@ -2582,6 +2622,70 @@ function AppInner() {
|
||||
</div>
|
||||
))}
|
||||
|
||||
{clientContextMenu && (
|
||||
<div
|
||||
ref={clientContextMenuRef}
|
||||
className="ts-context-menu"
|
||||
style={{ top: clientContextMenu.y, left: clientContextMenu.x }}
|
||||
>
|
||||
<div className="ts-context-menu-title">{clientContextMenu.clientName}</div>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
disabled={clientContextMenu.isSelf}
|
||||
onClick={() => {
|
||||
handleOpenPrivateChat(clientContextMenu.clientId, clientContextMenu.clientName);
|
||||
setClientContextMenu(null);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">💬</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.privateChat")}</span>
|
||||
</button>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
disabled={clientContextMenu.isSelf}
|
||||
onClick={() => {
|
||||
handlePokeClient(clientContextMenu.clientId, clientContextMenu.clientName);
|
||||
setClientContextMenu(null);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">👉</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.poke")}</span>
|
||||
</button>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
onClick={() => {
|
||||
void navigator.clipboard?.writeText(clientContextMenu.clientName);
|
||||
setClientContextMenu(null);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">📋</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.copyName")}</span>
|
||||
</button>
|
||||
<div className="ts-menu-separator" />
|
||||
<button className="ts-menu-item" disabled title={t("clientContext.notSupported")}>
|
||||
<span className="ts-menu-item-icon">🏷️</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.assignChannelGroup")}</span>
|
||||
</button>
|
||||
<button className="ts-menu-item" disabled title={t("clientContext.notSupported")}>
|
||||
<span className="ts-menu-item-icon">🎖️</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.assignServerGroup")}</span>
|
||||
</button>
|
||||
{!clientContextMenu.isSelf && (
|
||||
<>
|
||||
<div className="ts-menu-separator" />
|
||||
<button className="ts-menu-item" disabled title={t("clientContext.notSupported")}>
|
||||
<span className="ts-menu-item-icon">👢</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.kick")}</span>
|
||||
</button>
|
||||
<button className="ts-menu-item" disabled title={t("clientContext.notSupported")}>
|
||||
<span className="ts-menu-item-icon">🚫</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.ban")}</span>
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="ts-body">
|
||||
<div className="ts-upper" style={{ height: upperHeight }}>
|
||||
<div className="ts-tree-panel" style={{ width: treeWidth }}>
|
||||
@@ -2605,6 +2709,7 @@ function AppInner() {
|
||||
onSwitchChannel={handleSwitchChannel}
|
||||
onOpenPrivateChat={handleOpenPrivateChat}
|
||||
onPokeClient={handlePokeClient}
|
||||
onClientContextMenu={handleClientContextMenu}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
|
||||
@@ -206,6 +206,15 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"poke.pokedYou": "hat dich angestupst",
|
||||
"poke.dismiss": "Schließen",
|
||||
|
||||
"clientContext.privateChat": "Privater Chat",
|
||||
"clientContext.poke": "Anstupsen",
|
||||
"clientContext.copyName": "Namen kopieren",
|
||||
"clientContext.assignChannelGroup": "Channel-Gruppe zuweisen",
|
||||
"clientContext.assignServerGroup": "Server-Gruppe zuweisen",
|
||||
"clientContext.kick": "Vom Server kicken",
|
||||
"clientContext.ban": "Bannen",
|
||||
"clientContext.notSupported": "Im Web-Client noch nicht unterstützt",
|
||||
|
||||
"connectError.dismiss": "Schließen",
|
||||
"dialog.close": "Schließen",
|
||||
|
||||
@@ -434,6 +443,15 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"poke.pokedYou": "poked you",
|
||||
"poke.dismiss": "Dismiss",
|
||||
|
||||
"clientContext.privateChat": "Private chat",
|
||||
"clientContext.poke": "Poke",
|
||||
"clientContext.copyName": "Copy name",
|
||||
"clientContext.assignChannelGroup": "Assign channel group",
|
||||
"clientContext.assignServerGroup": "Assign server group",
|
||||
"clientContext.kick": "Kick from server",
|
||||
"clientContext.ban": "Ban",
|
||||
"clientContext.notSupported": "Not yet supported in the web client",
|
||||
|
||||
"connectError.dismiss": "Dismiss",
|
||||
"dialog.close": "Close",
|
||||
|
||||
|
||||
Reference in new issue
Block a user