-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: iframe rendering optimization
- Loading branch information
1 parent
ea4da9f
commit 61f957e
Showing
11 changed files
with
64 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.DS_Store | ||
.eslintcache | ||
.idea | ||
.run | ||
node_modules | ||
npm-debug.log | ||
coverage | ||
|
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
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
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
19 changes: 3 additions & 16 deletions
19
src/course-unit/xblock-container-iframe/hooks/useIframeContent.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,33 +1,20 @@ | ||
import { useEffect, useCallback, RefObject } from 'react'; | ||
|
||
import { messageTypes } from '../../constants'; | ||
import { useEffect, RefObject } from 'react'; | ||
|
||
/** | ||
* Hook for managing iframe content and providing utilities to interact with the iframe. | ||
* | ||
* @param {React.RefObject<HTMLIFrameElement>} iframeRef - A React ref for the iframe element. | ||
* @param {(ref: React.RefObject<HTMLIFrameElement>) => void} setIframeRef - | ||
* A function to associate the iframeRef with the parent context. | ||
* @param {(type: string, payload: any) => void} sendMessageToIframe - A function to send messages to the iframe. | ||
* | ||
* @returns {Object} - An object containing utility functions. | ||
* @returns {() => void} return.refreshIframeContent - | ||
* A function to refresh the iframe content by sending a specific message. | ||
* @returns {() => void} | ||
*/ | ||
export const useIframeContent = ( | ||
iframeRef: RefObject<HTMLIFrameElement>, | ||
setIframeRef: (ref: RefObject<HTMLIFrameElement>) => void, | ||
sendMessageToIframe: (type: string, payload: any) => void, | ||
): { refreshIframeContent: () => void } => { | ||
): void => { | ||
useEffect(() => { | ||
setIframeRef(iframeRef); | ||
}, [setIframeRef, iframeRef]); | ||
|
||
// TODO: this artificial delay is a temporary solution | ||
// to ensure the iframe content is properly refreshed. | ||
const refreshIframeContent = useCallback(() => { | ||
setTimeout(() => sendMessageToIframe(messageTypes.refreshXBlock, null), 1000); | ||
}, [sendMessageToIframe]); | ||
|
||
return { refreshIframeContent }; | ||
}; |
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
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