Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 18 | import { Box, Card, Grid, Stack, Typography } from '@mui/material'; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 19 | import { |
| 20 | ComponentType, |
| 21 | Fragment, |
| 22 | ReactNode, |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 23 | RefObject, |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 24 | useCallback, |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 25 | useEffect, |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 26 | useLayoutEffect, |
| 27 | useMemo, |
| 28 | useRef, |
| 29 | useState, |
| 30 | } from 'react'; |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 31 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 32 | import { ExpandableButtonProps } from '../components/Button'; |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 33 | import { |
| 34 | CallingChatButton, |
| 35 | CallingEndButton, |
| 36 | CallingExtensionButton, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 37 | CallingFullScreenButton, |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 38 | CallingGroupButton, |
| 39 | CallingMicButton, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 40 | CallingMoreVerticalButton, |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 41 | CallingRecordButton, |
| 42 | CallingScreenShareButton, |
| 43 | CallingVideoCameraButton, |
| 44 | CallingVolumeButton, |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 45 | } from '../components/CallButtons'; |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 46 | import CallChatDrawer from '../components/CallChatDrawer'; |
simon | daae910 | 2022-12-02 16:51:31 -0500 | [diff] [blame] | 47 | import VideoOverlay from '../components/VideoOverlay'; |
| 48 | import VideoStream from '../components/VideoStream'; |
simon | 5c67796 | 2022-12-02 16:51:54 -0500 | [diff] [blame] | 49 | import { CallStatus, useCallContext, VideoStatus } from '../contexts/CallProvider'; |
simon | 09fe482 | 2022-11-30 23:36:25 -0500 | [diff] [blame] | 50 | import { useConversationContext } from '../contexts/ConversationProvider'; |
simon | 5c67796 | 2022-12-02 16:51:54 -0500 | [diff] [blame] | 51 | import { useWebRtcContext } from '../contexts/WebRtcProvider'; |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 52 | import { VideoElementWithSinkId } from '../utils/utils'; |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 53 | import { CallPending } from './CallPending'; |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 54 | import CallPermissionDenied from './CallPermissionDenied'; |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 55 | |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 56 | export default () => { |
simon | 5c67796 | 2022-12-02 16:51:54 -0500 | [diff] [blame] | 57 | const { callStatus, isChatShown, isFullscreen } = useCallContext(); |
simon | 2a5cf14 | 2022-11-25 15:47:35 -0500 | [diff] [blame] | 58 | const callInterfaceRef = useRef<HTMLDivElement>(); |
| 59 | |
| 60 | useEffect(() => { |
| 61 | if (!callInterfaceRef.current) { |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | if (isFullscreen && document.fullscreenElement === null) { |
| 66 | callInterfaceRef.current.requestFullscreen(); |
simon | 09fe482 | 2022-11-30 23:36:25 -0500 | [diff] [blame] | 67 | } else if (!isFullscreen && document.fullscreenElement !== null) { |
simon | 2a5cf14 | 2022-11-25 15:47:35 -0500 | [diff] [blame] | 68 | document.exitFullscreen(); |
| 69 | } |
| 70 | }, [isFullscreen]); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 71 | |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 72 | if (callStatus === CallStatus.PermissionsDenied) { |
| 73 | return <CallPermissionDenied />; |
| 74 | } |
simon | 9f814a3 | 2022-11-22 21:40:53 -0500 | [diff] [blame] | 75 | if (callStatus !== CallStatus.InCall) { |
simon | 9076a9a | 2022-11-29 17:13:01 -0500 | [diff] [blame] | 76 | return <CallPending />; |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 77 | } |
simon | 9f814a3 | 2022-11-22 21:40:53 -0500 | [diff] [blame] | 78 | |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 79 | return ( |
simon | 2a5cf14 | 2022-11-25 15:47:35 -0500 | [diff] [blame] | 80 | <Box ref={callInterfaceRef} flexGrow={1} display="flex"> |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 81 | <CallInterface /> |
| 82 | {isChatShown && <CallChatDrawer />} |
| 83 | </Box> |
| 84 | ); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 85 | }; |
| 86 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 87 | interface Props { |
| 88 | children?: ReactNode; |
| 89 | } |
| 90 | |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 91 | const CallInterface = () => { |
simon | 5c67796 | 2022-12-02 16:51:54 -0500 | [diff] [blame] | 92 | const { localStream, screenShareLocalStream, remoteStreams } = useWebRtcContext(); |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 93 | const { |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 94 | currentMediaDeviceIds: { |
| 95 | audiooutput: { id: audioOutDeviceId }, |
| 96 | }, |
simon | daae910 | 2022-12-02 16:51:31 -0500 | [diff] [blame] | 97 | videoStatus, |
simon | 5c67796 | 2022-12-02 16:51:54 -0500 | [diff] [blame] | 98 | } = useCallContext(); |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 99 | const remoteVideoRef = useRef<VideoElementWithSinkId | null>(null); |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 100 | const gridItemRef = useRef<HTMLDivElement | null>(null); |
simon | daae910 | 2022-12-02 16:51:31 -0500 | [diff] [blame] | 101 | const [isLocalVideoZoomed, setIsLocalVideoZoomed] = useState(false); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 102 | |
simon | daae910 | 2022-12-02 16:51:31 -0500 | [diff] [blame] | 103 | const stream = useMemo(() => { |
| 104 | switch (videoStatus) { |
| 105 | case VideoStatus.Camera: |
| 106 | return localStream; |
| 107 | case VideoStatus.ScreenShare: |
| 108 | return screenShareLocalStream; |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 109 | } |
simon | daae910 | 2022-12-02 16:51:31 -0500 | [diff] [blame] | 110 | }, [videoStatus, localStream, screenShareLocalStream]); |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 111 | |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 112 | const hasSetSinkId = remoteVideoRef.current?.setSinkId != null; |
| 113 | |
simon | daae910 | 2022-12-02 16:51:31 -0500 | [diff] [blame] | 114 | // TODO: For now, `remoteStream` is the first remote stream in the array. |
| 115 | // There should only be one in the array, but we should make sure this is right. |
| 116 | const remoteStream = remoteStreams?.at(0); |
| 117 | |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 118 | return ( |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 119 | <Box display="flex" flexGrow={1}> |
simon | daae910 | 2022-12-02 16:51:31 -0500 | [diff] [blame] | 120 | <VideoStream |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 121 | ref={remoteVideoRef} |
simon | daae910 | 2022-12-02 16:51:31 -0500 | [diff] [blame] | 122 | stream={remoteStream} |
| 123 | audioOutDeviceId={audioOutDeviceId} |
simon | 9f814a3 | 2022-11-22 21:40:53 -0500 | [diff] [blame] | 124 | style={{ zIndex: -1, backgroundColor: 'black', position: 'absolute', height: '100%', width: '100%' }} |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 125 | /> |
simon | 9f814a3 | 2022-11-22 21:40:53 -0500 | [diff] [blame] | 126 | <Box flexGrow={1} margin={2} display="flex" flexDirection="column"> |
| 127 | {/* Guest video, takes the whole screen */} |
simon | 8b496b0 | 2022-11-29 01:46:46 -0500 | [diff] [blame] | 128 | <CallInterfaceInformation /> |
simon | 9f814a3 | 2022-11-22 21:40:53 -0500 | [diff] [blame] | 129 | <Box flexGrow={1} marginY={2} position="relative"> |
simon | daae910 | 2022-12-02 16:51:31 -0500 | [diff] [blame] | 130 | <VideoOverlay |
| 131 | stream={stream} |
| 132 | hidden={!stream} |
| 133 | muted |
| 134 | size={isLocalVideoZoomed ? 'large' : 'medium'} |
| 135 | onClick={() => setIsLocalVideoZoomed((v) => !v)} |
| 136 | /> |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 137 | </Box> |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 138 | <Grid container> |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 139 | <Grid item xs /> |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 140 | <Grid item sx={{ display: 'flex', justifyContent: 'center' }}> |
| 141 | <div> |
| 142 | <CallInterfacePrimaryButtons /> |
| 143 | </div> |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 144 | </Grid> |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 145 | <Grid item xs sx={{ display: 'flex', justifyContent: 'flex-end' }} ref={gridItemRef}> |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 146 | <CallInterfaceSecondaryButtons showVolumeButton={hasSetSinkId} gridItemRef={gridItemRef} /> |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 147 | </Grid> |
| 148 | </Grid> |
simon | 9f814a3 | 2022-11-22 21:40:53 -0500 | [diff] [blame] | 149 | </Box> |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 150 | </Box> |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 151 | ); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 152 | }; |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 153 | |
Gabriel Rochon | e382a30 | 2022-11-23 12:37:04 -0500 | [diff] [blame] | 154 | const formatElapsedSeconds = (elapsedSeconds: number): string => { |
| 155 | const seconds = Math.floor(elapsedSeconds % 60); |
| 156 | elapsedSeconds = Math.floor(elapsedSeconds / 60); |
| 157 | const minutes = elapsedSeconds % 60; |
| 158 | elapsedSeconds = Math.floor(elapsedSeconds / 60); |
| 159 | const hours = elapsedSeconds % 24; |
| 160 | |
| 161 | const times: string[] = []; |
| 162 | if (hours > 0) { |
| 163 | times.push(hours.toString().padStart(2, '0')); |
| 164 | } |
| 165 | times.push(minutes.toString().padStart(2, '0')); |
| 166 | times.push(seconds.toString().padStart(2, '0')); |
| 167 | |
| 168 | return times.join(':'); |
| 169 | }; |
| 170 | |
simon | 8b496b0 | 2022-11-29 01:46:46 -0500 | [diff] [blame] | 171 | const CallInterfaceInformation = () => { |
simon | 5c67796 | 2022-12-02 16:51:54 -0500 | [diff] [blame] | 172 | const { callStartTime } = useCallContext(); |
simon | 09fe482 | 2022-11-30 23:36:25 -0500 | [diff] [blame] | 173 | const { conversation } = useConversationContext(); |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 174 | const [elapsedTime, setElapsedTime] = useState(callStartTime ? (Date.now() - callStartTime) / 1000 : 0); |
Misha Krieger-Raynauld | cfa4430 | 2022-11-30 18:36:36 -0500 | [diff] [blame] | 175 | const memberName = useMemo(() => conversation.getFirstMember().contact.registeredName, [conversation]); |
simon | 8b496b0 | 2022-11-29 01:46:46 -0500 | [diff] [blame] | 176 | |
| 177 | useEffect(() => { |
| 178 | if (callStartTime) { |
| 179 | const interval = setInterval(() => { |
Misha Krieger-Raynauld | d0cc3e3 | 2022-11-29 19:59:31 -0500 | [diff] [blame] | 180 | setElapsedTime((Date.now() - callStartTime) / 1000); |
simon | 8b496b0 | 2022-11-29 01:46:46 -0500 | [diff] [blame] | 181 | }, 1000); |
| 182 | return () => clearInterval(interval); |
| 183 | } |
| 184 | }, [callStartTime]); |
| 185 | |
Gabriel Rochon | e382a30 | 2022-11-23 12:37:04 -0500 | [diff] [blame] | 186 | const elapsedTimerString = formatElapsedSeconds(elapsedTime); |
| 187 | |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 188 | return ( |
| 189 | <Stack direction="row" justifyContent="space-between" alignItems="center"> |
| 190 | <Typography color="white" component="p"> |
Gabriel Rochon | 15a5fb2 | 2022-11-27 19:25:14 -0500 | [diff] [blame] | 191 | {memberName} |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 192 | </Typography> |
| 193 | <Typography color="white" component="p"> |
Gabriel Rochon | e382a30 | 2022-11-23 12:37:04 -0500 | [diff] [blame] | 194 | {elapsedTimerString} |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 195 | </Typography> |
| 196 | </Stack> |
| 197 | ); |
| 198 | }; |
| 199 | |
| 200 | const CallInterfacePrimaryButtons = () => { |
| 201 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 202 | <Card sx={{ backgroundColor: '#00000088', overflow: 'visible' }}> |
| 203 | <Stack direction="row" justifyContent="center" alignItems="center"> |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 204 | <CallingMicButton /> |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 205 | <CallingEndButton /> |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 206 | <CallingVideoCameraButton /> |
| 207 | </Stack> |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 208 | </Card> |
| 209 | ); |
| 210 | }; |
| 211 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 212 | const SECONDARY_BUTTONS = [ |
| 213 | CallingVolumeButton, |
| 214 | CallingGroupButton, |
| 215 | CallingChatButton, |
| 216 | CallingScreenShareButton, |
| 217 | CallingRecordButton, |
| 218 | CallingExtensionButton, |
| 219 | CallingFullScreenButton, |
| 220 | ]; |
| 221 | |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 222 | const CallInterfaceSecondaryButtons = ({ |
| 223 | gridItemRef, |
| 224 | showVolumeButton, |
| 225 | }: Props & { showVolumeButton: boolean; gridItemRef: RefObject<HTMLElement> }) => { |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 226 | const stackRef = useRef<HTMLElement>(null); |
| 227 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 228 | const [initialMeasurementDone, setInitialMeasurementDone] = useState(false); |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 229 | const [hiddenStackCount, setHiddenStackCount] = useState(0); |
| 230 | const [hiddenMenuVisible, setHiddenMenuVisible] = useState(false); |
| 231 | |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 232 | // Audio out options are only available on Chrome and other browsers that support `setSinkId`. |
| 233 | // This removes the `CallingVolumeButton` if `setSinkId` is not defined. |
| 234 | // https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId#browser_compatibility |
| 235 | const secondaryButtons = useMemo(() => { |
| 236 | return showVolumeButton ? SECONDARY_BUTTONS : SECONDARY_BUTTONS.slice(1); |
| 237 | }, [showVolumeButton]); |
| 238 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 239 | const calculateStackCount = useCallback(() => { |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 240 | if (stackRef?.current && gridItemRef?.current) { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 241 | const buttonWidth = stackRef.current.children[0].clientWidth; |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 242 | const availableSpace = gridItemRef.current.clientWidth; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 243 | let availableButtons = Math.floor((availableSpace - 1) / buttonWidth); |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 244 | if (availableButtons < secondaryButtons.length) { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 245 | availableButtons -= 1; // Leave room for CallingMoreVerticalButton |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 246 | } |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 247 | setHiddenStackCount(secondaryButtons.length - availableButtons); |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 248 | } |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 249 | }, [gridItemRef, secondaryButtons]); |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 250 | |
| 251 | useLayoutEffect(() => { |
| 252 | // Run once, at the beginning, for initial measurements |
| 253 | if (!initialMeasurementDone) { |
| 254 | calculateStackCount(); |
| 255 | setInitialMeasurementDone(true); |
| 256 | } |
| 257 | |
| 258 | const onResize = () => { |
| 259 | calculateStackCount(); |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 260 | }; |
| 261 | window.addEventListener('resize', onResize); |
| 262 | return () => { |
| 263 | window.removeEventListener('resize', onResize); |
| 264 | }; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 265 | }, [calculateStackCount, initialMeasurementDone]); |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 266 | |
| 267 | const { displayedButtons, hiddenButtons } = useMemo(() => { |
| 268 | const displayedButtons: ComponentType<ExpandableButtonProps>[] = []; |
| 269 | const hiddenButtons: ComponentType<ExpandableButtonProps>[] = []; |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 270 | for (let i = 0; i < secondaryButtons.length; i++) { |
| 271 | const button = secondaryButtons[i]; |
| 272 | if (i < secondaryButtons.length - hiddenStackCount) { |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 273 | displayedButtons.push(button); |
| 274 | } else { |
| 275 | hiddenButtons.push(button); |
| 276 | } |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 277 | } |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 278 | |
| 279 | return { |
| 280 | displayedButtons, |
| 281 | hiddenButtons, |
| 282 | }; |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 283 | }, [hiddenStackCount, secondaryButtons]); |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 284 | |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 285 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 286 | <Card sx={{ backgroundColor: '#00000088', overflow: 'visible', height: '100%' }}> |
| 287 | <Stack direction="row" justifyContent="center" alignItems="center" height="100%" ref={stackRef}> |
| 288 | {initialMeasurementDone && |
| 289 | displayedButtons.map((SecondaryButton, i) => ( |
| 290 | <Fragment key={i}> |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 291 | <SecondaryButton /> |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 292 | </Fragment> |
| 293 | ))} |
| 294 | {(!!hiddenButtons.length || !initialMeasurementDone) && ( |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 295 | <CallingMoreVerticalButton isVertical onClick={() => setHiddenMenuVisible(!hiddenMenuVisible)} /> |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 296 | )} |
| 297 | </Stack> |
| 298 | |
| 299 | {!!hiddenButtons.length && hiddenMenuVisible && ( |
| 300 | <Box sx={{ position: 'absolute', right: 0, bottom: '50px' }}> |
| 301 | <Card sx={{ backgroundColor: '#00000088', overflow: 'visible', justifyContent: 'flex-end' }}> |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 302 | <Stack |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 303 | direction="column" |
| 304 | justifyContent="flex-end" |
| 305 | alignItems="flex-end" |
| 306 | sx={{ bottom: 0, right: 0, height: '100%' }} |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 307 | > |
| 308 | {hiddenButtons.map((SecondaryButton, i) => ( |
| 309 | <Fragment key={i}> |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 310 | <SecondaryButton isVertical /> |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 311 | </Fragment> |
| 312 | ))} |
| 313 | </Stack> |
| 314 | </Card> |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 315 | </Box> |
| 316 | )} |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 317 | </Card> |
| 318 | ); |
| 319 | }; |