import {Registry} from "tc-shared/events"; import { AwayState, Bookmark, ControlBarEvents, ConnectionState, ControlBarMode, HostButtonInfo, MicrophoneState } from "tc-shared/ui/frames/control-bar/Definitions"; import * as React from "react"; import {useContext, useRef, useState} from "react"; import {DropdownEntry} from "tc-shared/ui/frames/control-bar/DropDown"; import {Translatable} from "tc-shared/ui/react-elements/i18n"; import {Button} from "tc-shared/ui/frames/control-bar/Button"; import {spawnContextMenu} from "tc-shared/ui/context-menu"; import {ClientIcon} from "svg-sprites/client-icons"; const cssStyle = require("./Renderer.scss"); const cssButtonStyle = require("./Button.scss"); const Events = React.createContext>(undefined); const ModeContext = React.createContext(undefined); const ConnectButton = () => { const events = useContext(Events); const [ state, setState ] = useState(() => { events.fire("query_connection_state"); return undefined; }); events.reactUse("notify_connection_state", event => setState(event.state)); let subentries = []; if(state?.multisession) { if(!state.currentlyConnected) { subentries.push( Connect to a server} onClick={() => events.fire("action_connection_connect", { newTab: false })} /> ); } else { subentries.push( Disconnect from current server} onClick={() => events.fire("action_connection_disconnect", { generally: false })} /> ); } if(state.generallyConnected) { subentries.push( Disconnect from all servers} onClick={() => events.fire("action_connection_disconnect", { generally: true })}/> ); } subentries.push( Connect to a server in another tab} onClick={() => events.fire("action_connection_connect", { newTab: true })} /> ); } if(state?.currentlyConnected) { return ( ); } else { return ( ); } }; const BookmarkRenderer = (props: { bookmark: Bookmark, refButton: React.RefObject ) }; const AwayButton = () => { const events = useContext(Events); const [ state, setState ] = useState(() => { events.fire("query_away_state"); return undefined; }); events.on("notify_away_state", event => setState(event.state)); let dropdowns = []; if(state?.locallyAway) { dropdowns.push(Go online} onClick={() => events.fire("action_toggle_away", { away: false, globally: false })} />); } else { dropdowns.push(Set away on this server} onClick={() => events.fire("action_toggle_away", { away: true, globally: false })} />); } dropdowns.push(Set away message on this server} onClick={() => events.fire("action_toggle_away", { away: true, globally: false, promptMessage: true })} />); dropdowns.push(
); if(state?.globallyAway !== "none") { dropdowns.push(Go online for all servers} onClick={() => events.fire("action_toggle_away", { away: false, globally: true })} />); } if(state?.globallyAway !== "full") { dropdowns.push(Set away on all servers} onClick={() => events.fire("action_toggle_away", { away: true, globally: true })} />); } dropdowns.push(Set away message for all servers} onClick={() => events.fire("action_toggle_away", { away: true, globally: true, promptMessage: true })} />); return ( ); }; const MicrophoneButton = () => { const events = useContext(Events); const [ state, setState ] = useState(() => { events.fire("query_microphone_state"); return undefined; }); events.on("notify_microphone_state", event => setState(event.state)); if(state === "muted") { return ); } }; const HostButton = () => { const events = useContext(Events); const [ hostButton, setHostButton ] = useState(() => { events.fire("query_host_button"); return undefined; }); events.reactUse("notify_host_button", event => setHostButton(event.button)); if(!hostButton) { return null; } else { return ( { window.open(hostButton.target || hostButton.url, '_blank'); event.preventDefault(); }} > {tr("Hostbutton")} ); } }; export const ControlBar2 = (props: { events: Registry, className?: string }) => { const [ mode, setMode ] = useState(() => { props.events.fire("query_mode"); return undefined; }); props.events.reactUse("notify_mode", event => setMode(event.mode)); const items = []; if(mode !== "channel-popout") { items.push(); } items.push(); items.push(
); items.push(); items.push(); items.push(); items.push(
); items.push(); items.push(); items.push(
); items.push(); return (
{items}
) };