chore: delete old context menu components replaced by centralized system
This commit is contained in:
@@ -1,280 +0,0 @@
|
||||
import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { useVoiceStore } from '../../stores/voiceStore';
|
||||
import { getActiveRoom, setStreamSubscription } from '../../hooks/useLiveKit';
|
||||
import { ScreenShareSettingsPopover } from './ScreenShareSettingsPopover';
|
||||
import { stopScreenShare, changeScreenShare } from '../../utils/screenShare';
|
||||
|
||||
interface StreamContextMenuProps {
|
||||
userId: string;
|
||||
identity: string;
|
||||
isLocal: boolean;
|
||||
position: { x: number; y: number };
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export function StreamContextMenu({ userId, identity, isLocal, position, onClose }: StreamContextMenuProps) {
|
||||
const menuRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const [qualityPopoverOpen, setQualityPopoverOpen] = useState(false);
|
||||
const qualityBtnRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
const streamVolumes = useVoiceStore((s) => s.streamVolumes);
|
||||
const streamMutes = useVoiceStore((s) => s.streamMutes);
|
||||
const watchingStreams = useVoiceStore((s) => s.watchingStreams);
|
||||
const streamAttenuationEnabled = useVoiceStore((s) => s.streamAttenuationEnabled);
|
||||
const streamAttenuationStrength = useVoiceStore((s) => s.streamAttenuationStrength);
|
||||
const setStreamVolumeAction = useVoiceStore((s) => s.setStreamVolume);
|
||||
const setStreamMuteAction = useVoiceStore((s) => s.setStreamMute);
|
||||
const setAttenuationEnabled = useVoiceStore((s) => s.setStreamAttenuationEnabled);
|
||||
const setAttenuationStrength = useVoiceStore((s) => s.setStreamAttenuationStrength);
|
||||
|
||||
const isWatching = watchingStreams.has(userId);
|
||||
const streamVolume = streamVolumes.get(userId) ?? 100;
|
||||
const isStreamMuted = streamMutes.get(userId) ?? false;
|
||||
|
||||
const handleWatch = useCallback(() => {
|
||||
useVoiceStore.getState().watchStream(userId);
|
||||
setStreamSubscription(getActiveRoom(), identity, true);
|
||||
}, [userId, identity]);
|
||||
|
||||
const handleUnwatch = useCallback(() => {
|
||||
useVoiceStore.getState().unwatchStream(userId);
|
||||
setStreamSubscription(getActiveRoom(), identity, false);
|
||||
}, [userId, identity]);
|
||||
|
||||
const handleStopStreaming = useCallback(async () => {
|
||||
const room = getActiveRoom();
|
||||
if (room) {
|
||||
await stopScreenShare(room);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleChangeStream = useCallback(async () => {
|
||||
const room = getActiveRoom();
|
||||
if (room) {
|
||||
await changeScreenShare(room);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Click-outside dismissal (guards nested popover)
|
||||
useEffect(() => {
|
||||
const handler = (e: MouseEvent) => {
|
||||
if (qualityPopoverOpen) return;
|
||||
if (menuRef.current && !menuRef.current.contains(e.target as Node)) {
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
document.addEventListener('mousedown', handler);
|
||||
return () => document.removeEventListener('mousedown', handler);
|
||||
}, [onClose, qualityPopoverOpen]);
|
||||
|
||||
// Viewport-aware positioning
|
||||
useLayoutEffect(() => {
|
||||
const el = menuRef.current;
|
||||
if (!el) return;
|
||||
const rect = el.getBoundingClientRect();
|
||||
let x = position.x;
|
||||
let y = position.y;
|
||||
if (rect.right > window.innerWidth) x = window.innerWidth - rect.width - 8;
|
||||
if (rect.bottom > window.innerHeight) y = window.innerHeight - rect.height - 8;
|
||||
if (x < 8) x = 8;
|
||||
if (y < 8) y = 8;
|
||||
el.style.left = `${x}px`;
|
||||
el.style.top = `${y}px`;
|
||||
}, [position]);
|
||||
|
||||
const btnClass = 'w-full text-left px-2 py-1.5 mx-1.5 text-sm rounded-sm flex items-center gap-2 text-txt-secondary hover:bg-accent-primary hover:text-white';
|
||||
const btnStyle: React.CSSProperties = { width: 'calc(100% - 12px)' };
|
||||
|
||||
return ReactDOM.createPortal(
|
||||
<div
|
||||
ref={menuRef}
|
||||
className="fixed z-[200] bg-surface-elevated rounded-md shadow-elevation-high min-w-[220px] max-h-[calc(100vh-16px)] overflow-y-auto scrollbar-thin animate-fade-in"
|
||||
style={{ left: position.x, top: position.y }}
|
||||
onMouseDown={(e) => e.stopPropagation()}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{isLocal ? (
|
||||
<>
|
||||
<div className="py-1.5">
|
||||
<button
|
||||
onClick={() => {
|
||||
handleStopStreaming();
|
||||
onClose();
|
||||
}}
|
||||
className={`${btnClass} text-red-400 hover:text-white`}
|
||||
style={btnStyle}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" className="flex-shrink-0">
|
||||
<path d="M21 3H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h7v2H8v2h8v-2h-2v-2h7c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 14H3V5h18v12z" />
|
||||
<line x1="4" y1="4" x2="20" y2="20" stroke="currentColor" strokeWidth="2" />
|
||||
</svg>
|
||||
Stop Streaming
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
handleChangeStream();
|
||||
onClose();
|
||||
}}
|
||||
className={btnClass}
|
||||
style={btnStyle}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" className="flex-shrink-0">
|
||||
<path d="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z" />
|
||||
</svg>
|
||||
Change Stream
|
||||
</button>
|
||||
</div>
|
||||
<div className="h-px bg-white/[0.06] mx-1.5" />
|
||||
<div className="p-3">
|
||||
<div className="text-xs text-txt-tertiary mb-2 font-medium uppercase tracking-wider">
|
||||
Stream Quality
|
||||
</div>
|
||||
<div className="relative">
|
||||
<button
|
||||
ref={qualityBtnRef}
|
||||
onClick={() => setQualityPopoverOpen(!qualityPopoverOpen)}
|
||||
className="w-full flex items-center justify-between px-2 py-1.5 text-sm text-txt-secondary hover:bg-interactive-hover rounded transition-colors"
|
||||
>
|
||||
<span>{`${useVoiceStore.getState().screenShareConfig.height}p ${useVoiceStore.getState().screenShareConfig.fps}fps`}</span>
|
||||
<svg width="12" height="12" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path d="M7 10l5 5 5-5z" />
|
||||
</svg>
|
||||
</button>
|
||||
{qualityPopoverOpen && (
|
||||
<ScreenShareSettingsPopover
|
||||
open={qualityPopoverOpen}
|
||||
onClose={() => setQualityPopoverOpen(false)}
|
||||
anchorRef={qualityBtnRef}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="py-1.5">
|
||||
{isWatching ? (
|
||||
<button
|
||||
onClick={() => {
|
||||
handleUnwatch();
|
||||
onClose();
|
||||
}}
|
||||
className={btnClass}
|
||||
style={btnStyle}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" className="flex-shrink-0">
|
||||
<path d="M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z" />
|
||||
</svg>
|
||||
Stop Watching
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => {
|
||||
handleWatch();
|
||||
onClose();
|
||||
}}
|
||||
className={btnClass}
|
||||
style={btnStyle}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" className="flex-shrink-0">
|
||||
<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" />
|
||||
</svg>
|
||||
Watch Stream
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="h-px bg-white/[0.06] mx-1.5" />
|
||||
<div className="py-1.5">
|
||||
<button
|
||||
onClick={() => setStreamMuteAction(userId, !isStreamMuted)}
|
||||
className={btnClass}
|
||||
style={btnStyle}
|
||||
>
|
||||
<span className="flex-1">Mute Stream</span>
|
||||
<div
|
||||
className={`w-4 h-4 rounded border flex items-center justify-center transition-colors ${
|
||||
isStreamMuted
|
||||
? 'bg-accent-primary border-accent-primary'
|
||||
: 'border-txt-tertiary'
|
||||
}`}
|
||||
>
|
||||
{isStreamMuted && (
|
||||
<svg width="10" height="10" viewBox="0 0 24 24" fill="white">
|
||||
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
|
||||
</svg>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
<div className="p-3">
|
||||
<div className="text-xs text-txt-tertiary mb-2 font-medium uppercase tracking-wider">
|
||||
Stream Volume
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" className="text-txt-tertiary flex-shrink-0">
|
||||
<path d="M3 9v6h4l5 5V4L7 9H3z" />
|
||||
</svg>
|
||||
<input
|
||||
type="range"
|
||||
min="0"
|
||||
max="200"
|
||||
value={streamVolume}
|
||||
onChange={(e) => setStreamVolumeAction(userId, parseInt(e.target.value))}
|
||||
className="flex-1 accent-accent-primary h-1"
|
||||
/>
|
||||
<span className="text-xs text-txt-secondary min-w-[32px] text-right">
|
||||
{streamVolume}%
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="h-px bg-white/[0.06] mx-1.5" />
|
||||
<div className="py-1.5">
|
||||
<button
|
||||
onClick={() => setAttenuationEnabled(!streamAttenuationEnabled)}
|
||||
className={btnClass}
|
||||
style={btnStyle}
|
||||
>
|
||||
<span className="flex-1">Stream Attenuation</span>
|
||||
<div
|
||||
className={`w-4 h-4 rounded border flex items-center justify-center transition-colors ${
|
||||
streamAttenuationEnabled
|
||||
? 'bg-accent-primary border-accent-primary'
|
||||
: 'border-txt-tertiary'
|
||||
}`}
|
||||
>
|
||||
{streamAttenuationEnabled && (
|
||||
<svg width="10" height="10" viewBox="0 0 24 24" fill="white">
|
||||
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
|
||||
</svg>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
{streamAttenuationEnabled && (
|
||||
<div className="p-3 pt-0">
|
||||
<div className="text-xs text-txt-tertiary mb-2 font-medium uppercase tracking-wider">
|
||||
Attenuation Strength
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
type="range"
|
||||
min="0"
|
||||
max="100"
|
||||
value={streamAttenuationStrength}
|
||||
onChange={(e) => setAttenuationStrength(parseInt(e.target.value))}
|
||||
className="flex-1 accent-accent-primary h-1"
|
||||
/>
|
||||
<span className="text-xs text-txt-secondary min-w-[32px] text-right">
|
||||
{streamAttenuationStrength}%
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>,
|
||||
document.body,
|
||||
);
|
||||
}
|
||||
@@ -1,399 +0,0 @@
|
||||
import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { useVoiceStore } from '../../stores/voiceStore';
|
||||
import { useSpaceStore, getChannelOrigin } from '../../stores/spaceStore';
|
||||
import { wsSend } from '../../hooks/useWebSocket';
|
||||
import { hasPermissionBit, PermissionBits } from '../../utils/permissions';
|
||||
import { getActiveRoom, setCameraSubscription } from '../../hooks/useLiveKit';
|
||||
|
||||
interface VoiceModMenuItemsProps {
|
||||
targetUserId: string;
|
||||
channelId: string;
|
||||
onAction: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Headless moderation menu items (mute/deafen/move buttons).
|
||||
* Renders nothing if the current user has no moderation permissions.
|
||||
* Use inside any container — no portal or positioning logic.
|
||||
*/
|
||||
export function VoiceModMenuItems({ targetUserId, channelId, onAction }: VoiceModMenuItemsProps) {
|
||||
const spaceMutedUserIds = useVoiceStore((s) => s.spaceMutedUserIds);
|
||||
const spaceDeafenedUserIds = useVoiceStore((s) => s.spaceDeafenedUserIds);
|
||||
|
||||
const spacePermissions = useSpaceStore((s) => s.spacePermissions);
|
||||
const currentSpaceId = useSpaceStore((s) => s.currentSpaceId);
|
||||
const channels = useSpaceStore((s) => s.channels);
|
||||
|
||||
const myPerms = currentSpaceId ? spacePermissions.get(currentSpaceId) : undefined;
|
||||
const canMuteMembers = hasPermissionBit(myPerms, PermissionBits.MUTE_MEMBERS);
|
||||
const canDeafenMembers = hasPermissionBit(myPerms, PermissionBits.DEAFEN_MEMBERS);
|
||||
const canMoveMembers = hasPermissionBit(myPerms, PermissionBits.MOVE_MEMBERS);
|
||||
const canDisconnectMembers = hasPermissionBit(myPerms, PermissionBits.DISCONNECT_MEMBERS);
|
||||
|
||||
const otherVoiceChannels = channels.filter(
|
||||
(c) => c.type === 'voice' && c.id !== channelId,
|
||||
);
|
||||
|
||||
const voiceOrigin = getChannelOrigin(channelId);
|
||||
const spaceId = useSpaceStore((s) => s.channelToSpaceMap.get(channelId));
|
||||
|
||||
const isSpaceMuted = spaceMutedUserIds.has(`${spaceId}:${targetUserId}`);
|
||||
const isSpaceDeafened = spaceDeafenedUserIds.has(`${spaceId}:${targetUserId}`);
|
||||
|
||||
if (!canMuteMembers && !canDeafenMembers && !canMoveMembers && !canDisconnectMembers) return null;
|
||||
|
||||
const handleSpaceMute = () => {
|
||||
wsSend({ type: 'voice_space_mute', userId: targetUserId, muted: !isSpaceMuted }, voiceOrigin);
|
||||
onAction();
|
||||
};
|
||||
|
||||
const handleSpaceDeafen = () => {
|
||||
wsSend({ type: 'voice_space_deafen', userId: targetUserId, deafened: !isSpaceDeafened }, voiceOrigin);
|
||||
onAction();
|
||||
};
|
||||
|
||||
const handleMove = (targetChannelId: string) => {
|
||||
wsSend({ type: 'voice_move', userId: targetUserId, targetChannelId }, voiceOrigin);
|
||||
onAction();
|
||||
};
|
||||
|
||||
const handleDisconnect = () => {
|
||||
wsSend({ type: 'voice_disconnect', userId: targetUserId }, voiceOrigin);
|
||||
onAction();
|
||||
};
|
||||
|
||||
const btnClass = 'w-full text-left px-2 py-1.5 mx-1.5 text-sm rounded-sm flex items-center gap-2 text-txt-secondary hover:bg-accent-primary hover:text-white';
|
||||
const btnStyle = { width: 'calc(100% - 12px)' };
|
||||
|
||||
return (
|
||||
<>
|
||||
{canMuteMembers && (
|
||||
<button onClick={handleSpaceMute} className={btnClass} style={btnStyle}>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" className="flex-shrink-0">
|
||||
<path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z" />
|
||||
<path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z" />
|
||||
{isSpaceMuted && (
|
||||
<line x1="3" y1="3" x2="21" y2="21" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" />
|
||||
)}
|
||||
</svg>
|
||||
{isSpaceMuted ? 'Space Unmute' : 'Space Mute'}
|
||||
</button>
|
||||
)}
|
||||
{canDeafenMembers && (
|
||||
<button onClick={handleSpaceDeafen} className={btnClass} style={btnStyle}>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" className="flex-shrink-0">
|
||||
<path d="M12 3c-4.97 0-9 4.03-9 9v7c0 1.1.9 2 2 2h2v-7H5v-2c0-3.87 3.13-7 7-7s7 3.13 7 7v2h-2v7h2c1.1 0 2-.9 2-2v-7c0-4.97-4.03-9-9-9z" />
|
||||
{isSpaceDeafened && (
|
||||
<line x1="3" y1="3" x2="21" y2="21" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" />
|
||||
)}
|
||||
</svg>
|
||||
{isSpaceDeafened ? 'Space Undeafen' : 'Space Deafen'}
|
||||
</button>
|
||||
)}
|
||||
{canDisconnectMembers && (
|
||||
<>
|
||||
<div className="h-px bg-white/[0.06] my-1 mx-1.5" />
|
||||
<button onClick={handleDisconnect} className={`${btnClass} text-red-400 hover:text-white`} style={btnStyle}>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" className="flex-shrink-0">
|
||||
<path d="M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 010-1.36C3.36 8.68 7.42 7 12 7s8.64 1.68 11.71 4.72c.18.18.29.44.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 00-2.67-1.85.996.996 0 01-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z" />
|
||||
</svg>
|
||||
Disconnect
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{canMoveMembers && otherVoiceChannels.length > 0 && (
|
||||
<MoveToSubmenu channels={otherVoiceChannels} onMove={handleMove} btnClass={btnClass} btnStyle={btnStyle} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── "Move to" hover flyout submenu ──────────────────────────────────────────
|
||||
|
||||
interface MoveToSubmenuProps {
|
||||
channels: { id: string; name: string }[];
|
||||
onMove: (channelId: string) => void;
|
||||
btnClass: string;
|
||||
btnStyle: React.CSSProperties;
|
||||
}
|
||||
|
||||
function MoveToSubmenu({ channels, onMove, btnClass, btnStyle }: MoveToSubmenuProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const triggerRef = useRef<HTMLButtonElement>(null);
|
||||
const flyoutRef = useRef<HTMLDivElement>(null);
|
||||
const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
const startCloseTimer = useCallback(() => {
|
||||
closeTimer.current = setTimeout(() => setOpen(false), 150);
|
||||
}, []);
|
||||
|
||||
const cancelCloseTimer = useCallback(() => {
|
||||
if (closeTimer.current) {
|
||||
clearTimeout(closeTimer.current);
|
||||
closeTimer.current = null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (closeTimer.current) clearTimeout(closeTimer.current);
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Position the flyout relative to the trigger
|
||||
useLayoutEffect(() => {
|
||||
const flyout = flyoutRef.current;
|
||||
const trigger = triggerRef.current;
|
||||
if (!open || !flyout || !trigger) return;
|
||||
|
||||
const tRect = trigger.getBoundingClientRect();
|
||||
const fRect = flyout.getBoundingClientRect();
|
||||
const gap = 4;
|
||||
|
||||
// Horizontal: prefer right, flip left if overflowing
|
||||
let left = tRect.right + gap;
|
||||
if (left + fRect.width > window.innerWidth) {
|
||||
left = tRect.left - fRect.width - gap;
|
||||
}
|
||||
if (left < 8) left = 8;
|
||||
|
||||
// Vertical: align top with trigger, clamp to viewport
|
||||
let top = tRect.top;
|
||||
if (top + fRect.height > window.innerHeight - 8) {
|
||||
top = window.innerHeight - fRect.height - 8;
|
||||
}
|
||||
if (top < 8) top = 8;
|
||||
|
||||
flyout.style.left = `${left}px`;
|
||||
flyout.style.top = `${top}px`;
|
||||
|
||||
const availableHeight = window.innerHeight - top - 8;
|
||||
const maxHeight = Math.max(availableHeight, 120);
|
||||
flyout.style.maxHeight = `${maxHeight}px`;
|
||||
}, [open]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="h-px bg-white/[0.06] my-1 mx-1.5" />
|
||||
<button
|
||||
ref={triggerRef}
|
||||
className={btnClass}
|
||||
style={btnStyle}
|
||||
onMouseEnter={() => { cancelCloseTimer(); setOpen(true); }}
|
||||
onMouseLeave={startCloseTimer}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" className="flex-shrink-0">
|
||||
<path d="M14 4l2.29 2.29-2.88 2.88 1.42 1.42 2.88-2.88L20 10V4h-6zM10 4H4v6l2.29-2.29 4.71 4.7V20h2v-8.41l-5.29-5.3L10 4z" />
|
||||
</svg>
|
||||
<span className="flex-1">Move to</span>
|
||||
<span className="text-txt-tertiary text-xs ml-auto">›</span>
|
||||
</button>
|
||||
{open && ReactDOM.createPortal(
|
||||
<div
|
||||
ref={flyoutRef}
|
||||
className="fixed z-[210] glass rounded-md py-1.5 min-w-[160px] overflow-y-auto scrollbar-thin animate-fade-in"
|
||||
style={{ left: -9999, top: -9999 }}
|
||||
onMouseEnter={cancelCloseTimer}
|
||||
onMouseLeave={startCloseTimer}
|
||||
onMouseDown={(e) => e.stopPropagation()}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{channels.map((ch) => (
|
||||
<button
|
||||
key={ch.id}
|
||||
onClick={() => onMove(ch.id)}
|
||||
className={btnClass}
|
||||
style={btnStyle}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" className="flex-shrink-0 text-txt-tertiary">
|
||||
<path d="M11 5L6 9H2V15H6L11 19V5ZM15.54 8.46C16.48 9.4 17 10.67 17 12S16.48 14.6 15.54 15.54L14.12 14.12C14.69 13.55 15 12.79 15 12S14.69 10.45 14.12 9.88L15.54 8.46Z" />
|
||||
</svg>
|
||||
<span className="truncate">{ch.name}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>,
|
||||
document.body,
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Standalone portalled context menu ─────────────────────────────────────────
|
||||
|
||||
interface VoiceUserContextMenuProps {
|
||||
targetUserId: string;
|
||||
channelId: string;
|
||||
position: { x: number; y: number };
|
||||
onClose: () => void;
|
||||
isLocal: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unified voice user context menu rendered via createPortal to document.body.
|
||||
* Shows moderation items (if perms) + volume slider (always, for remote users).
|
||||
* Includes viewport-aware positioning and click-outside dismissal.
|
||||
*/
|
||||
export function VoiceUserContextMenu({ targetUserId, channelId, position, onClose, isLocal }: VoiceUserContextMenuProps) {
|
||||
const menuRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const spacePermissions = useSpaceStore((s) => s.spacePermissions);
|
||||
const currentSpaceId = useSpaceStore((s) => s.currentSpaceId);
|
||||
const myPerms = currentSpaceId ? spacePermissions.get(currentSpaceId) : undefined;
|
||||
const canMuteMembers = hasPermissionBit(myPerms, PermissionBits.MUTE_MEMBERS);
|
||||
const canDeafenMembers = hasPermissionBit(myPerms, PermissionBits.DEAFEN_MEMBERS);
|
||||
const canMoveMembers = hasPermissionBit(myPerms, PermissionBits.MOVE_MEMBERS);
|
||||
const canDisconnectMembers = hasPermissionBit(myPerms, PermissionBits.DISCONNECT_MEMBERS);
|
||||
const hasModPerms = canMuteMembers || canDeafenMembers || canMoveMembers || canDisconnectMembers;
|
||||
|
||||
const participantVolumes = useVoiceStore((s) => s.participantVolumes);
|
||||
const setParticipantVolume = useVoiceStore((s) => s.setParticipantVolume);
|
||||
const perUserVolume = participantVolumes.get(targetUserId) ?? 100;
|
||||
|
||||
const participantMutes = useVoiceStore((s) => s.participantMutes);
|
||||
const setParticipantMute = useVoiceStore((s) => s.setParticipantMute);
|
||||
const isUserMuted = participantMutes.get(targetUserId) ?? false;
|
||||
|
||||
const unwatchedCameras = useVoiceStore((s) => s.unwatchedCameras);
|
||||
const participants = useVoiceStore((s) => s.participants);
|
||||
const targetParticipant = participants.find((p) => p.userId === targetUserId);
|
||||
const targetHasCamera = targetParticipant?.isCameraOn ?? false;
|
||||
const isCameraUnwatched = unwatchedCameras.has(targetUserId);
|
||||
|
||||
// Click-outside dismissal
|
||||
useEffect(() => {
|
||||
const handler = (e: MouseEvent) => {
|
||||
if (menuRef.current && !menuRef.current.contains(e.target as Node)) {
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
document.addEventListener('mousedown', handler);
|
||||
return () => document.removeEventListener('mousedown', handler);
|
||||
}, [onClose]);
|
||||
|
||||
// Viewport-aware positioning — direct DOM mutation, no extra state/render
|
||||
useLayoutEffect(() => {
|
||||
const el = menuRef.current;
|
||||
if (!el) return;
|
||||
const rect = el.getBoundingClientRect();
|
||||
let x = position.x;
|
||||
let y = position.y;
|
||||
if (rect.right > window.innerWidth) x = window.innerWidth - rect.width - 8;
|
||||
if (rect.bottom > window.innerHeight) y = window.innerHeight - rect.height - 8;
|
||||
if (x < 8) x = 8;
|
||||
if (y < 8) y = 8;
|
||||
el.style.left = `${x}px`;
|
||||
el.style.top = `${y}px`;
|
||||
}, [position]);
|
||||
|
||||
if (isLocal) return null;
|
||||
|
||||
return ReactDOM.createPortal(
|
||||
<div
|
||||
ref={menuRef}
|
||||
className="fixed z-[200] glass rounded-md min-w-[200px] max-h-[calc(100vh-16px)] overflow-y-auto scrollbar-thin animate-fade-in"
|
||||
style={{ left: position.x, top: position.y }}
|
||||
onMouseDown={(e) => e.stopPropagation()}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{hasModPerms && (
|
||||
<>
|
||||
<div className="py-1.5">
|
||||
<VoiceModMenuItems
|
||||
targetUserId={targetUserId}
|
||||
channelId={channelId}
|
||||
onAction={onClose}
|
||||
/>
|
||||
</div>
|
||||
<div className="h-px bg-white/[0.06] mx-1.5" />
|
||||
</>
|
||||
)}
|
||||
{targetHasCamera && (
|
||||
<>
|
||||
<div className="py-1.5">
|
||||
<button
|
||||
onClick={() => {
|
||||
const room = getActiveRoom();
|
||||
const identity = targetParticipant?.identity;
|
||||
if (isCameraUnwatched) {
|
||||
useVoiceStore.getState().rewatchCamera(targetUserId);
|
||||
if (identity) setCameraSubscription(room, identity, true);
|
||||
} else {
|
||||
useVoiceStore.getState().unwatchCamera(targetUserId);
|
||||
if (identity) setCameraSubscription(room, identity, false);
|
||||
}
|
||||
onClose();
|
||||
}}
|
||||
className="w-full text-left px-2 py-1.5 mx-1.5 text-sm rounded-sm flex items-center gap-2 text-txt-secondary hover:bg-accent-primary hover:text-white"
|
||||
style={{ width: 'calc(100% - 12px)' }}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" className="flex-shrink-0">
|
||||
{isCameraUnwatched ? (
|
||||
<path d="M17 10.5V7c0-.55-.45-1-1-1H2c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1h14c.55 0 1-.45 1-1v-3.5l4 4v-11l-4 4z" />
|
||||
) : (
|
||||
<>
|
||||
<path d="M17 10.5V7c0-.55-.45-1-1-1H2c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1h14c.55 0 1-.45 1-1v-3.5l4 4v-11l-4 4z" />
|
||||
<line x1="1" y1="1" x2="23" y2="23" stroke="currentColor" strokeWidth="2" strokeLinecap="round" />
|
||||
</>
|
||||
)}
|
||||
</svg>
|
||||
{isCameraUnwatched ? 'Watch Camera' : 'Stop Watching Camera'}
|
||||
</button>
|
||||
</div>
|
||||
<div className="h-px bg-white/[0.06] mx-1.5" />
|
||||
</>
|
||||
)}
|
||||
<div className="py-1.5">
|
||||
<button
|
||||
onClick={() => setParticipantMute(targetUserId, !isUserMuted)}
|
||||
className="w-full text-left px-2 py-1.5 mx-1.5 text-sm rounded-sm flex items-center gap-2 text-txt-secondary hover:bg-accent-primary hover:text-white"
|
||||
style={{ width: 'calc(100% - 12px)' }}
|
||||
>
|
||||
<span className="flex-1">Mute User</span>
|
||||
<div
|
||||
className={`w-4 h-4 rounded border flex items-center justify-center transition-colors ${
|
||||
isUserMuted
|
||||
? 'bg-accent-primary border-accent-primary'
|
||||
: 'border-txt-tertiary'
|
||||
}`}
|
||||
>
|
||||
{isUserMuted && (
|
||||
<svg width="10" height="10" viewBox="0 0 24 24" fill="white">
|
||||
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
|
||||
</svg>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
<div className="h-px bg-white/[0.06] mx-1.5" />
|
||||
<div className="p-3">
|
||||
<div className="text-xs text-txt-tertiary mb-2 font-medium uppercase tracking-wider">
|
||||
User Volume
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="currentColor"
|
||||
className="text-txt-tertiary flex-shrink-0"
|
||||
>
|
||||
<path d="M3 9v6h4l5 5V4L7 9H3z" />
|
||||
</svg>
|
||||
<input
|
||||
type="range"
|
||||
min="0"
|
||||
max="200"
|
||||
value={perUserVolume}
|
||||
onChange={(e) => setParticipantVolume(targetUserId, parseInt(e.target.value))}
|
||||
className="flex-1 accent-accent-primary h-1"
|
||||
/>
|
||||
<span className="text-xs text-txt-secondary min-w-[32px] text-right">
|
||||
{perUserVolume}%
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>,
|
||||
document.body,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user