prevent reload on moderator status change

This commit is contained in:
KDSBrowne 2024-02-28 16:50:14 +00:00
parent b68416249a
commit c70f116cd5

View File

@ -158,6 +158,7 @@ export default Whiteboard = React.memo(function Whiteboard(props) {
const whiteboardIdRef = React.useRef(whiteboardId);
const curPageIdRef = React.useRef(curPageId);
const hasWBAccessRef = React.useRef(hasWBAccess);
const isModeratorRef = React.useRef(isModerator);
const THRESHOLD = 0.1;
const lastKnownHeight = React.useRef(presentationAreaHeight);
@ -169,6 +170,10 @@ export default Whiteboard = React.memo(function Whiteboard(props) {
curPageIdRef.current = curPageId;
}, [curPageId]);
React.useEffect(() => {
isModeratorRef.current = isModerator;
}, [isModerator]);
React.useEffect(() => {
whiteboardIdRef.current = whiteboardId;
}, [whiteboardId]);
@ -271,7 +276,7 @@ export default Whiteboard = React.memo(function Whiteboard(props) {
if (
(prevShape?.meta?.updatedBy !== currentUser?.userId && !selectedShapeIds.includes(remoteShape.id)) ||
(prevShape?.meta?.createdBy === currentUser?.userId) ||
(prevShape?.meta?.createdBy !== currentUser?.userId && selectedShapeIds.includes(remoteShape.id) && (isPresenter || isModerator))
(prevShape?.meta?.createdBy !== currentUser?.userId && selectedShapeIds.includes(remoteShape.id) && (isPresenter || isModeratorRef.current))
) {
Object.keys(remoteShape).forEach((key) => {
if (key !== "isModerator" && !isEqual(remoteShape[key], localShape[key])) {
@ -859,7 +864,7 @@ export default Whiteboard = React.memo(function Whiteboard(props) {
createdBy: currentUser?.userId,
},
};
persistShapeWrapper(updatedRecord, whiteboardIdRef.current, isModerator);
persistShapeWrapper(updatedRecord, whiteboardIdRef.current, isModeratorRef.current);
});
Object.values(updated).forEach(([_, record]) => {
@ -871,7 +876,7 @@ export default Whiteboard = React.memo(function Whiteboard(props) {
updatedBy: currentUser?.userId,
},
};
persistShapeWrapper(updatedRecord, whiteboardIdRef.current, isModerator);
persistShapeWrapper(updatedRecord, whiteboardIdRef.current, isModeratorRef.current);
});
Object.values(removed).forEach((record) => {
@ -976,7 +981,7 @@ export default Whiteboard = React.memo(function Whiteboard(props) {
editor.store.onBeforeChange = (prev, next, source) => {
if (next?.typeName === "instance_page_state") {
if ((isPresenter || isModerator)) return next;
if (isPresenter || isModeratorRef.current) return next;
// Filter selectedShapeIds based on shape owner
if (next.selectedShapeIds.length > 0 && !isEqual(prev.selectedShapeIds, next.selectedShapeIds)) {
@ -1037,7 +1042,7 @@ export default Whiteboard = React.memo(function Whiteboard(props) {
<div
ref={whiteboardRef}
id={"whiteboard-element"}
key={`animations=-${animations}-${isPresenter}-${isModerator}-${whiteboardToolbarAutoHide}-${language}`}
key={`animations=-${animations}-${whiteboardToolbarAutoHide}-${language}`}
>
<Tldraw
key={`tldrawv2-${presentationId}-${animations}`}