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