fix shapes missing on previous slides for late joiners

This commit is contained in:
KDSBrowne 2024-05-09 15:29:17 +00:00
parent 4b91675658
commit 3c08786dcc

View File

@ -4,7 +4,7 @@ import React, {
useState,
useMemo,
} from 'react';
import { useSubscription, useMutation } from '@apollo/client';
import { useSubscription, useMutation, useQuery } from '@apollo/client';
import {
AssetRecordType,
} from '@tldraw/tldraw';
@ -12,6 +12,7 @@ import { throttle } from 'radash';
import {
CURRENT_PRESENTATION_PAGE_SUBSCRIPTION,
CURRENT_PAGE_ANNOTATIONS_STREAM,
CURRENT_PAGE_ANNOTATIONS_QUERY,
CURRENT_PAGE_WRITERS_SUBSCRIPTION,
CURSOR_SUBSCRIPTION,
} from './queries';
@ -175,23 +176,48 @@ const WhiteboardContainer = (props) => {
},
);
const { data: initialPageAnnotations, refetch: refetchInitialPageAnnotations } = useQuery(
CURRENT_PAGE_ANNOTATIONS_QUERY,
{
skip: !curPageId,
}
);
React.useEffect(() => {
if (curPageIdRef.current) {
refetchInitialPageAnnotations();
}
}, [curPageIdRef.current]);
const processAnnotations = (data) => {
const newAnnotations = [];
const annotationsToBeRemoved = [];
data.forEach((item) => {
if (item.annotationInfo === '') {
annotationsToBeRemoved.push(item.annotationId);
} else {
newAnnotations.push(item);
}
});
const currentAnnotations = annotations.filter(
(annotation) => !annotationsToBeRemoved.includes(annotation.annotationId),
);
setAnnotations([...currentAnnotations, ...newAnnotations]);
}
React.useEffect(() => {
if (initialPageAnnotations && initialPageAnnotations.pres_annotation_curr) {
processAnnotations(initialPageAnnotations.pres_annotation_curr);
}
}, [initialPageAnnotations]);
useEffect(() => {
const { pres_annotation_curr_stream: annotationStream } = annotationStreamData || {};
if (annotationStream) {
const newAnnotations = [];
const annotationsToBeRemoved = [];
annotationStream.forEach((item) => {
if (item.annotationInfo === '') {
annotationsToBeRemoved.push(item.annotationId);
} else {
newAnnotations.push(item);
}
});
const currentAnnotations = annotations.filter(
(annotation) => !annotationsToBeRemoved.includes(annotation.annotationId),
);
setAnnotations([...currentAnnotations, ...newAnnotations]);
processAnnotations(annotationStream);
}
}, [annotationStreamData]);