2024-01-16 03:49:09 +08:00
|
|
|
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';
|
2024-06-04 21:40:54 +08:00
|
|
|
import useDeduplicatedSubscription from '/imports/ui/core/hooks/useDeduplicatedSubscription';
|
2024-01-16 03:49:09 +08:00
|
|
|
|
|
|
|
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('');
|
2024-06-04 21:40:54 +08:00
|
|
|
const { data: contentDiffData } = useDeduplicatedSubscription<GetPadContentDiffStreamResponse>(
|
2024-01-16 03:49:09 +08:00
|
|
|
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;
|