generated from bigbluebutton/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from GuiLeme/new-set-state-function
feat: Add new setCurrentState flow to live-updates logic
- Loading branch information
Showing
12 changed files
with
250 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
...eneric-content-area/presenter-view/page-container/live-update/h5p-state-renderer/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { LatestH5pStateItem } from '../live-update-player/types'; | ||
|
||
export interface H5pPresenterComponentProps { | ||
isResetH5pComponentFlow: boolean; | ||
contentAsJson: string; | ||
h5pAsJson: string; | ||
indexOfCurrentStateInList: number; | ||
stateListLength: number; | ||
indexOfCurrentStateInList?: number; | ||
currentH5pStateToBeApplied: string; | ||
setLatestH5pStates: React.Dispatch<React.SetStateAction<LatestH5pStateItem[]>>; | ||
idOfCurrentState: string; | ||
setH5pDomElement?: React.Dispatch<React.SetStateAction<HTMLIFrameElement>>; | ||
setLatestH5pStates?: React.Dispatch<React.SetStateAction<LatestH5pStateItem[]>>; | ||
idOfCurrentState?: string; | ||
} |
70 changes: 70 additions & 0 deletions
70
...rea/presenter-view/page-container/live-update/iterative-reset-h5p-component/component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as React from 'react'; | ||
import { DataChannelTypes } from 'bigbluebutton-html-plugin-sdk'; | ||
import * as uuidLib from 'uuid'; | ||
import { useEffect, useState } from 'react'; | ||
import { LatestH5pStateItem } from '../live-update-player/types'; | ||
import { IterativeResetH5PComponentProps } from './types'; | ||
import H5pStateRendererComponent from '../h5p-state-renderer/component'; | ||
import { UserH5pCurrentState } from '../../../../types'; | ||
import { LiveUpdateCommonWrapper } from '../live-update-common-wrapper/component'; | ||
|
||
export function IterativeResetH5PComponent(props: IterativeResetH5PComponentProps) { | ||
const { | ||
contentAsJson, h5pAsJson, isFullscreen, numberOfItemsPerPage, | ||
pluginApi, userId, userName, setFullscreenItem, | ||
} = props; | ||
|
||
const { | ||
data: responseUserH5pCurrentStateList, | ||
} = pluginApi.useDataChannel<UserH5pCurrentState>('testResult', DataChannelTypes.All_ITEMS, 'userH5pCurrentState'); | ||
|
||
const dataToRender = responseUserH5pCurrentStateList?.data?.filter( | ||
(h5pState) => h5pState.payloadJson.userId === userId, | ||
).map((h5pState) => ( | ||
{ entryId: h5pState.entryId, payloadJson: h5pState.payloadJson }))[0]?.payloadJson; | ||
|
||
const [latestH5pStates, setLatestH5pStates] = useState<LatestH5pStateItem[]>([]); | ||
|
||
useEffect(() => { | ||
const currentH5pStateToBeApplied = dataToRender?.currentState; | ||
if ( | ||
currentH5pStateToBeApplied && currentH5pStateToBeApplied !== '' | ||
&& (latestH5pStates.length === 0 | ||
|| currentH5pStateToBeApplied !== latestH5pStates[latestH5pStates.length - 1].state) | ||
) { | ||
setLatestH5pStates((list) => { | ||
const resultList = [...list, { | ||
state: currentH5pStateToBeApplied, rendered: false, id: uuidLib.v4(), | ||
}]; | ||
return resultList; | ||
}); | ||
} | ||
}, [responseUserH5pCurrentStateList]); | ||
|
||
return ( | ||
<LiveUpdateCommonWrapper | ||
isFullscreen={isFullscreen} | ||
numberOfItemsPerPage={numberOfItemsPerPage} | ||
userId={userId} | ||
userName={userName} | ||
setFullscreenItem={setFullscreenItem} | ||
> | ||
{latestH5pStates.filter( | ||
(state, index) => !state.rendered | ||
|| index === latestH5pStates.length - 1 | ||
|| !latestH5pStates[index + 1]?.rendered, | ||
).map((state, index) => ( | ||
<H5pStateRendererComponent | ||
key={state.id} | ||
indexOfCurrentStateInList={index} | ||
setLatestH5pStates={setLatestH5pStates} | ||
currentH5pStateToBeApplied={state.state} | ||
idOfCurrentState={state.id} | ||
contentAsJson={contentAsJson} | ||
isResetH5pComponentFlow | ||
h5pAsJson={h5pAsJson} | ||
/> | ||
))} | ||
</LiveUpdateCommonWrapper> | ||
); | ||
} |
13 changes: 13 additions & 0 deletions
13
...ent-area/presenter-view/page-container/live-update/iterative-reset-h5p-component/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { PluginApi } from 'bigbluebutton-html-plugin-sdk'; | ||
import { UserToBeRendered } from '../../../types'; | ||
|
||
export interface IterativeResetH5PComponentProps { | ||
userName: string; | ||
contentAsJson: string; | ||
pluginApi: PluginApi; | ||
h5pAsJson: string; | ||
userId: string; | ||
isFullscreen: boolean; | ||
numberOfItemsPerPage: number; | ||
setFullscreenItem?: React.Dispatch<React.SetStateAction<UserToBeRendered>>; | ||
} |
61 changes: 61 additions & 0 deletions
61
...area/presenter-view/page-container/live-update/iterative-sync-current-state/component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as React from 'react'; | ||
import { DataChannelTypes } from 'bigbluebutton-html-plugin-sdk'; | ||
import { useEffect, useState } from 'react'; | ||
import { IterativeSyncCurrentStateProps, WindowWithH5p } from './types'; | ||
import H5pStateRendererComponent from '../h5p-state-renderer/component'; | ||
import { UserH5pCurrentState } from '../../../../types'; | ||
import { LiveUpdateCommonWrapper } from '../live-update-common-wrapper/component'; | ||
|
||
export function IterativeSyncCurrentState(props: IterativeSyncCurrentStateProps) { | ||
const { | ||
contentAsJson, h5pAsJson, isFullscreen, numberOfItemsPerPage, | ||
pluginApi, userId, userName, setFullscreenItem, setHasSyncCurentStateFlow, | ||
} = props; | ||
|
||
const [h5pDomElement, setH5pDomElement] = useState<HTMLIFrameElement>(null); | ||
const h5pStateController = h5pDomElement?.contentWindow as WindowWithH5p; | ||
|
||
const { | ||
data: responseUserH5pCurrentStateList, | ||
} = pluginApi.useDataChannel<UserH5pCurrentState>('testResult', DataChannelTypes.All_ITEMS, 'userH5pCurrentState'); | ||
|
||
const dataToRender = responseUserH5pCurrentStateList?.data?.filter( | ||
(h5pState) => h5pState.payloadJson.userId === userId, | ||
).map((h5pState) => ( | ||
{ entryId: h5pState.entryId, payloadJson: h5pState.payloadJson }))[0]?.payloadJson; | ||
|
||
useEffect(() => { | ||
const currentH5pStateToBeApplied = dataToRender?.currentState; | ||
if ( | ||
currentH5pStateToBeApplied && currentH5pStateToBeApplied !== '' | ||
) { | ||
h5pStateController?.H5P?.instances[0].setCurrentState(JSON.parse(currentH5pStateToBeApplied)); | ||
} | ||
}, [responseUserH5pCurrentStateList]); | ||
|
||
useEffect(() => { | ||
if (h5pDomElement | ||
&& !(h5pDomElement?.contentWindow as WindowWithH5p)?.H5P?.instances[0].setCurrentState) { | ||
setHasSyncCurentStateFlow(false); | ||
} | ||
}, [h5pDomElement]); | ||
|
||
if (responseUserH5pCurrentStateList.loading) return null; | ||
return ( | ||
<LiveUpdateCommonWrapper | ||
isFullscreen={isFullscreen} | ||
numberOfItemsPerPage={numberOfItemsPerPage} | ||
userId={userId} | ||
userName={userName} | ||
setFullscreenItem={setFullscreenItem} | ||
> | ||
<H5pStateRendererComponent | ||
setH5pDomElement={setH5pDomElement} | ||
isResetH5pComponentFlow={false} | ||
currentH5pStateToBeApplied={dataToRender?.currentState} | ||
contentAsJson={contentAsJson} | ||
h5pAsJson={h5pAsJson} | ||
/> | ||
</LiveUpdateCommonWrapper> | ||
); | ||
} |
22 changes: 22 additions & 0 deletions
22
...tent-area/presenter-view/page-container/live-update/iterative-sync-current-state/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { PluginApi } from 'bigbluebutton-html-plugin-sdk'; | ||
import { UserToBeRendered } from '../../../types'; | ||
|
||
export interface IterativeSyncCurrentStateProps { | ||
userName: string; | ||
contentAsJson: string; | ||
pluginApi: PluginApi; | ||
h5pAsJson: string; | ||
userId: string; | ||
isFullscreen: boolean; | ||
numberOfItemsPerPage: number; | ||
setFullscreenItem?: React.Dispatch<React.SetStateAction<UserToBeRendered>>; | ||
setHasSyncCurentStateFlow: React.Dispatch<React.SetStateAction<boolean>>; | ||
} | ||
|
||
export interface WindowWithH5p extends Window { | ||
H5P: { | ||
instances: { | ||
setCurrentState?: (args: object) => void | ||
}[] | ||
}; | ||
} |
32 changes: 32 additions & 0 deletions
32
...t-area/presenter-view/page-container/live-update/live-update-common-wrapper/component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as React from 'react'; | ||
import * as Styled from './styles'; | ||
import { LiveUpdateCommonWrapperProps } from './types'; | ||
|
||
export function LiveUpdateCommonWrapper(props: LiveUpdateCommonWrapperProps) { | ||
const { | ||
isFullscreen, numberOfItemsPerPage, children, | ||
userId, userName, setFullscreenItem, | ||
} = props; | ||
const setFullscreen = (!isFullscreen) ? () => { | ||
if (numberOfItemsPerPage > 1) setFullscreenItem({ userId, userName }); | ||
} : null; | ||
return ( | ||
<Styled.LiveUpdatePlayerWrapper | ||
key={userId} | ||
> | ||
<Styled.UserNameTitle> | ||
{userName} | ||
</Styled.UserNameTitle> | ||
<Styled.UserLiveUpdatePlayerWrapper> | ||
<Styled.LockedDiv | ||
numberOfItemsPerPage={numberOfItemsPerPage} | ||
onClick={() => { | ||
if (setFullscreen) setFullscreen(); | ||
}} | ||
/> | ||
{children} | ||
|
||
</Styled.UserLiveUpdatePlayerWrapper> | ||
</Styled.LiveUpdatePlayerWrapper> | ||
); | ||
} |
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
...ontent-area/presenter-view/page-container/live-update/live-update-common-wrapper/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { UserToBeRendered } from '../../types'; | ||
|
||
export interface LiveUpdateCommonWrapperProps extends React.PropsWithChildren { | ||
userName: string; | ||
userId: string; | ||
isFullscreen: boolean; | ||
numberOfItemsPerPage: number; | ||
setFullscreenItem?: React.Dispatch<React.SetStateAction<UserToBeRendered>>; | ||
} |
98 changes: 28 additions & 70 deletions
98
...c-content-area/presenter-view/page-container/live-update/live-update-player/component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,37 @@ | ||
import { useState } from 'react'; | ||
import * as React from 'react'; | ||
import { DataChannelTypes } from 'bigbluebutton-html-plugin-sdk'; | ||
import * as uuidLib from 'uuid'; | ||
import { useEffect, useState } from 'react'; | ||
import { LiveUpdatePlayerComponentProps, LatestH5pStateItem } from './types'; | ||
import H5pStateRendererComponent from '../h5p-state-renderer/component'; | ||
import * as Styled from './styles'; | ||
import { UserH5pCurrentState } from '../../../../types'; | ||
import { LiveUpdatePlayerComponentProps } from './types'; | ||
import { IterativeSyncCurrentState } from '../iterative-sync-current-state/component'; | ||
import { IterativeResetH5PComponent } from '../iterative-reset-h5p-component/component'; | ||
|
||
export function LiveUpdatePlayerComponent(props: LiveUpdatePlayerComponentProps) { | ||
const { | ||
contentAsJson, h5pAsJson, isFullscreen, numberOfItemsPerPage, | ||
pluginApi, userId, userName, setFullscreenItem, | ||
} = props; | ||
|
||
const { | ||
data: responseUserH5pCurrentStateList, | ||
} = pluginApi.useDataChannel<UserH5pCurrentState>('testResult', DataChannelTypes.All_ITEMS, 'userH5pCurrentState'); | ||
|
||
const dataToRender = responseUserH5pCurrentStateList?.data?.filter( | ||
(h5pState) => h5pState.payloadJson.userId === userId, | ||
).map((h5pState) => ( | ||
{ entryId: h5pState.entryId, payloadJson: h5pState.payloadJson }))[0]?.payloadJson; | ||
|
||
const [latestH5pStates, setLatestH5pStates] = useState<LatestH5pStateItem[]>([]); | ||
|
||
useEffect(() => { | ||
const currentH5pStateToBeApplied = dataToRender?.currentState; | ||
if ( | ||
currentH5pStateToBeApplied && currentH5pStateToBeApplied !== '' | ||
&& (latestH5pStates.length === 0 | ||
|| currentH5pStateToBeApplied !== latestH5pStates[latestH5pStates.length - 1].state) | ||
) { | ||
setLatestH5pStates((list) => { | ||
const resultList = [...list, { | ||
state: currentH5pStateToBeApplied, rendered: false, id: uuidLib.v4(), | ||
}]; | ||
return resultList; | ||
}); | ||
} | ||
}, [responseUserH5pCurrentStateList]); | ||
|
||
const setFullscreen = (!isFullscreen) ? () => { | ||
if (numberOfItemsPerPage > 1) setFullscreenItem({ userId, userName }); | ||
} : null; | ||
return ( | ||
<Styled.LiveUpdatePlayerWrapper | ||
key={userId} | ||
> | ||
<Styled.UserNameTitle> | ||
{userName} | ||
</Styled.UserNameTitle> | ||
<Styled.UserLiveUpdatePlayerWrapper> | ||
<Styled.LockedDiv | ||
numberOfItemsPerPage={numberOfItemsPerPage} | ||
onClick={() => { | ||
if (setFullscreen) setFullscreen(); | ||
}} | ||
/> | ||
{latestH5pStates.filter( | ||
(state, index) => !state.rendered | ||
|| index === latestH5pStates.length - 1 | ||
|| !latestH5pStates[index + 1]?.rendered, | ||
).map((state, index) => ( | ||
<H5pStateRendererComponent | ||
key={state.id} | ||
indexOfCurrentStateInList={index} | ||
stateListLength={latestH5pStates.length} | ||
setLatestH5pStates={setLatestH5pStates} | ||
currentH5pStateToBeApplied={state.state} | ||
idOfCurrentState={state.id} | ||
contentAsJson={contentAsJson} | ||
h5pAsJson={h5pAsJson} | ||
/> | ||
))} | ||
</Styled.UserLiveUpdatePlayerWrapper> | ||
</Styled.LiveUpdatePlayerWrapper> | ||
const [hasSyncCurentStateFlow, setHasSyncCurentStateFlow] = useState<boolean>(true); | ||
return (hasSyncCurentStateFlow) ? ( | ||
<IterativeSyncCurrentState | ||
contentAsJson={contentAsJson} | ||
h5pAsJson={h5pAsJson} | ||
isFullscreen={isFullscreen} | ||
numberOfItemsPerPage={numberOfItemsPerPage} | ||
pluginApi={pluginApi} | ||
userId={userId} | ||
userName={userName} | ||
setHasSyncCurentStateFlow={setHasSyncCurentStateFlow} | ||
setFullscreenItem={setFullscreenItem} | ||
/> | ||
) : ( | ||
<IterativeResetH5PComponent | ||
contentAsJson={contentAsJson} | ||
h5pAsJson={h5pAsJson} | ||
isFullscreen={isFullscreen} | ||
numberOfItemsPerPage={numberOfItemsPerPage} | ||
pluginApi={pluginApi} | ||
userId={userId} | ||
userName={userName} | ||
setFullscreenItem={setFullscreenItem} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters