From 236e91d30217b5a4766ceef3fc89928f213af6c5 Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 22 Jul 2021 12:14:17 +0100 Subject: [PATCH] added view mode to UIState --- dailyjs/live-fitness/components/App/App.js | 15 +++++--- .../context/ClassStateProvider.js | 37 +++++++++++++++++++ dailyjs/shared/contexts/UIStateProvider.js | 24 +++++++++++- dailyjs/shared/hooks/useCallUI.js | 6 --- 4 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 dailyjs/live-fitness/context/ClassStateProvider.js diff --git a/dailyjs/live-fitness/components/App/App.js b/dailyjs/live-fitness/components/App/App.js index 5bce06e..c7fecb6 100644 --- a/dailyjs/live-fitness/components/App/App.js +++ b/dailyjs/live-fitness/components/App/App.js @@ -5,6 +5,7 @@ import FlyingEmojiOverlay from '@dailyjs/flying-emojis/components/FlyingEmojis'; import { LiveStreamingProvider } from '@dailyjs/live-streaming/contexts/LiveStreamingProvider'; import { RecordingProvider } from '@dailyjs/recording/contexts/RecordingProvider'; import { ChatProvider } from '@dailyjs/text-chat/contexts/ChatProvider'; +import { ClassStateProvider } from '../../context/ClassStateProvider'; import Room from '../Room'; /** @@ -15,12 +16,14 @@ export const LiveFitnessApp = () => ( - - , - }} - /> + + + , + }} + /> + diff --git a/dailyjs/live-fitness/context/ClassStateProvider.js b/dailyjs/live-fitness/context/ClassStateProvider.js new file mode 100644 index 0000000..e0a0ad9 --- /dev/null +++ b/dailyjs/live-fitness/context/ClassStateProvider.js @@ -0,0 +1,37 @@ +import React, { createContext, useContext, useEffect, useState } from 'react'; + +import { useParticipants } from '@dailyjs/shared/contexts/ParticipantsProvider'; +import PropTypes from 'prop-types'; + +export const CLASS_STATE_PRE_LOBBY = 'pre-lobby'; +export const CLASS_STATE_IN_SESSION = 'in_session'; +export const CLASS_STATE_POST_LOBBY = 'post-lobby'; + +const ClassStateContext = createContext(); + +export const ClassStateProvider = ({ children }) => { + const [classState, setClassState] = useState(CLASS_STATE_PRE_LOBBY); + + const { isOwner } = useParticipants(); + + useEffect(() => { + console.log('🧘 Class provider initialised'); + }, []); + + return ( + + {children} + + ); +}; + +ClassStateProvider.propTypes = { + children: PropTypes.node, +}; + +export const useClassState = () => useContext(ClassStateContext); diff --git a/dailyjs/shared/contexts/UIStateProvider.js b/dailyjs/shared/contexts/UIStateProvider.js index bb6d2a8..2e5bab5 100644 --- a/dailyjs/shared/contexts/UIStateProvider.js +++ b/dailyjs/shared/contexts/UIStateProvider.js @@ -1,15 +1,28 @@ -import React, { useCallback, createContext, useContext, useState } from 'react'; +import React, { + useCallback, + createContext, + useContext, + useState, + useEffect, +} from 'react'; import PropTypes from 'prop-types'; import { useDeepCompareMemo } from 'use-deep-compare'; export const UIStateContext = createContext(); +export const VIEW_MODE_GRID = 'grid'; +export const VIEW_MODE_SPEAKER = 'speaker'; +export const VIEW_MODE_MOBILE = 'mobile'; + export const UIStateProvider = ({ asides = [], modals = [], customTrayComponent, children, }) => { + const [preferredViewMode, setPreferredViewMode] = useState(VIEW_MODE_SPEAKER); + const [viewMode, setViewMode] = useState(preferredViewMode); + const [isShowingScreenshare, setIsShowingScreenshare] = useState(false); const [showAside, setShowAside] = useState(); const [activeModals, setActiveModals] = useState({}); const [customCapsule, setCustomCapsule] = useState(); @@ -42,6 +55,13 @@ export const UIStateProvider = ({ setShowAside(null); }, []); + useEffect(() => { + if (isShowingScreenshare) { + setViewMode(VIEW_MODE_SPEAKER); + } + setViewMode(preferredViewMode); + }, [isShowingScreenshare, preferredViewMode]); + return ( { const router = useRouter(); - const { closeAside, closeModal } = useUIState(); useEffect(() => { console.log(`%c🔀 App state changed: ${state}`, `color: gray;`); @@ -38,10 +36,6 @@ export const useCallUI = ({ return ; } - // Make sure we hide any active asides or modals when the state changes - closeAside(); - closeModal(); - // Update the UI based on the state of our call switch (state) { case CALL_STATE_NOT_FOUND: