bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/pads/pads-graphql/content/component.tsx
Tainan Felipe 3bc40df230
Add: useDeduplicatedSubscription hook (#20376)
* Add: useDeduplicatedSubscription hook

* Fix: TS error

* Add: components using useDeduplicatedSubscription

* Change: Move to useDeduplicatedSubscription

* Change: unsubscribe logic to own useEffect

* Change: remove file import over package

* Fix: TS errors

* Fix: private chat not loading

* Change: revert changes on queries

* Fix: eslint error

* Remove: html-webpack-plugin package

* Fix: external video

* Add: comment about the stringToHash function

* Fix: video player showing tools over presentation
2024-06-04 10:40:54 -03:00

62 lines
1.7 KiB
TypeScript

import React, { useEffect, useState } from 'react';
import { patch } from '@mconf/bbb-diff';
import Styled from './styles';
import { GET_PAD_CONTENT_DIFF_STREAM, GetPadContentDiffStreamResponse } from './queries';
import useDeduplicatedSubscription from '/imports/ui/core/hooks/useDeduplicatedSubscription';
interface PadContentProps {
content: string;
}
interface PadContentContainerProps {
externalId: string;
}
const PadContent: React.FC<PadContentProps> = ({
content,
}) => {
const contentSplit = content.split('<body>');
const contentStyle = `
<body>
<style type="text/css">
body {
${Styled.contentText}
}
</style>
`;
const contentWithStyle = [contentSplit[0], contentStyle, contentSplit[1]].join('');
return (
<Styled.Wrapper>
<Styled.Iframe
title="shared notes viewing mode"
srcDoc={contentWithStyle}
data-test="sharedNotesViewingMode"
/>
</Styled.Wrapper>
);
};
const PadContentContainer: React.FC<PadContentContainerProps> = ({ externalId }) => {
const [content, setContent] = useState('');
const { data: contentDiffData } = useDeduplicatedSubscription<GetPadContentDiffStreamResponse>(
GET_PAD_CONTENT_DIFF_STREAM,
{ variables: { externalId } },
);
useEffect(() => {
if (!contentDiffData) return;
const patches = contentDiffData.sharedNotes_diff_stream;
const patchedContent = patches.reduce((currentContent, attribs) => patch(
currentContent,
{ start: attribs.start, end: attribs.end, text: attribs.diff },
), content);
setContent(patchedContent);
}, [contentDiffData]);
return (
<PadContent content={content} />
);
};
export default PadContentContainer;