All files / src/components Panel.tsx

72.72% Statements 24/33
50% Branches 2/4
56.25% Functions 9/16
72.72% Lines 24/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194                                                                                                      14x   14x         14x       14x 2x       14x 12x 12x 9x       14x                                                                                                                 13x 13x   13x     13x     13x     13x       13x 2x         13x 11x 11x 9x       13x                                               2x                  
import React, {useState, useEffect} from 'react';
import {Menu, Dropdown} from 'antd';
import {UpOutlined} from '@ant-design/icons';
import {CopyToClipboard} from 'react-copy-to-clipboard';
import '../pages/spacePage/space.css';
import {UserInfo, UserList} from './UserList';
import {DataDtoType} from '../utils/RTCGameUtils';
import {ProfileDropdownOnOff} from './Navigation';
import Options from './Options';
 
export interface PanelProps {
  profileDropdownOnOff: ProfileDropdownOnOff;
  getMyNickname: () => string;
  getUsers: () => UserInfo[];
  roomId: string;
  onCopy: () => void;
  sendMessage: (message: string) => void;
  setDataChannelEventHandler: (
    arg0: DataDtoType,
    // eslint-disable-next-line
    arg1: (data: any) => void,
  ) => void;
  exit: () => void;
  // Options props
  changeEachAudio: (deviceId: string) => void;
  changeInputStream: (stream: MediaStream) => void;
  seletedOutputDevice: string;
  seletedInputDevice: string;
}
 
interface MenuItemProps {
  key: string;
}
 
export interface PanelDropDownProps {
  roomId: string;
  onCopy: () => void;
  onClickSubMenu: (e: MenuItemProps) => void;
  onClickPrevious: () => void;
  onChangeVolume: (changedVolume: number) => void;
  getUsers: () => UserInfo[];
  hidePanel: () => void;
  exit: () => void;
  // Options props
  changeEachAudio: (deviceId: string) => void;
  changeInputStream: (stream: MediaStream) => void;
  seletedOutputDevice: string;
  seletedInputDevice: string;
}
 
export function PanelDropDown(props: PanelDropDownProps): JSX.Element {
  const [userListVisible, setUserListVisible] = useState(false);
 
  const onClickUserList = () => {
    // props.hidePanel();
    setUserListVisible(true);
  };
 
  const onClickOption = () => {
    // add
  };
 
  const onESCKeyDown = (e: KeyboardEvent) => {
    Iif (e.key === 'Escape') {
      setUserListVisible(false);
    }
  };
  useEffect(() => {
    window.addEventListener('keydown', onESCKeyDown);
    return () => {
      window.removeEventListener('keydown', onESCKeyDown);
    };
  }, []);
 
  return (
    <Menu className="dropdown_menu">
      <Menu.Item key="0">
        <CopyToClipboard
          text={`https://giggleforest.com/space?roomId=${props.roomId}`}
          onCopy={props.onCopy}
        >
          <a>참여 링크 복사</a>
        </CopyToClipboard>
      </Menu.Item>
      <Menu.Item key="1" onClick={onClickUserList}>
        <Dropdown
          placement={'topCenter'}
          visible={userListVisible}
          onVisibleChange={setUserListVisible}
          overlay={UserList({
            getUsers: props.getUsers,
            onClickPrevious: props.onClickPrevious,
            onChangeVolume: props.onChangeVolume,
          })}
          trigger={['click']}
        >
          <a
            role="button"
            className="ant-dropdown-link"
            onClick={e => e.preventDefault()}
          >
            사용자
          </a>
        </Dropdown>
      </Menu.Item>
      <Menu.Item key="2" onClick={onClickOption}>
        <Options
          onClickOption={onClickOption}
          changeEachAudio={props.changeEachAudio}
          changeInputStream={props.changeInputStream}
          seletedInputDevice={props.seletedInputDevice}
          seletedOutputDevice={props.seletedOutputDevice}
        />
      </Menu.Item>
      <Menu.Item key="3">
        <a
          rel="noreferrer"
          href="https://github.com/VoiceSpaceUnder5/VoiceSpace/issues"
          target="_blank"
        >
          버그 리포트
        </a>
      </Menu.Item>
      <Menu.Item key="4" onClick={props.exit}>
        나가기
      </Menu.Item>
    </Menu>
  );
}
 
function Panel(props: PanelProps): JSX.Element {
  const [visible, setVisible] = useState(false);
  const [volume, setVolume] = useState(0);
 
  const onClickSubMenu = () => {
    setVisible(true);
  };
  const onClickPrevious = () => {
    setVisible(true);
  };
  const hidePanel = () => {
    setVisible(false);
  };
  const onChangeVolume = (changedVolume: number) => {
    volume;
    setVolume(changedVolume);
  };
  const onESCKeyDown = (e: KeyboardEvent) => {
    Iif (e.key === 'Escape') {
      setVisible(false);
    }
  };
 
  useEffect(() => {
    window.addEventListener('keydown', onESCKeyDown);
    return () => {
      window.removeEventListener('keydown', onESCKeyDown);
    };
  }, []);
 
  return (
    <Dropdown
      placement={'topRight'}
      visible={visible}
      onVisibleChange={setVisible}
      overlay={PanelDropDown({
        roomId: props.roomId,
        getUsers: props.getUsers,
        onCopy: props.onCopy,
        onClickSubMenu: onClickSubMenu,
        onClickPrevious: onClickPrevious,
        onChangeVolume: onChangeVolume,
        hidePanel: hidePanel,
        exit: props.exit,
        changeEachAudio: props.changeEachAudio,
        changeInputStream: props.changeInputStream,
        seletedOutputDevice: props.seletedOutputDevice,
        seletedInputDevice: props.seletedInputDevice,
      })}
      trigger={['click']}
    >
      <a
        role="button"
        className="ant-dropdown-link"
        onClick={e => e.preventDefault()}
      >
        <UpOutlined className="navbar_button" />
      </a>
    </Dropdown>
  );
}
 
export default Panel;