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