Skip to content

Commit

Permalink
fix: now discussion sidebar modal appears above the fold (#563)
Browse files Browse the repository at this point in the history
Co-authored-by: SundasNoreen <[email protected]>
  • Loading branch information
sundasnoreen12 and SundasNoreen authored Sep 15, 2023
1 parent fb2be35 commit af5b10a
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/components/TinyMCEEditor.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';

import { Editor } from '@tinymce/tinymce-react';
import { useParams } from 'react-router';
import { useLocation, useParams } from 'react-router';
// TinyMCE so the global var exists
// eslint-disable-next-line no-unused-vars,import/no-extraneous-dependencies
import tinymce from 'tinymce/tinymce';
Expand Down Expand Up @@ -45,10 +45,11 @@ import contentUiCss from '!!raw-loader!tinymce/skins/ui/oxide/content.min.css';
const TinyMCEEditor = (props) => {
// note that skin and content_css is disabled to avoid the normal
// loading process and is instead loaded as a string via content_style

const locationObj = useLocation();
const { courseId, postId } = useParams();
const [showImageWarning, setShowImageWarning] = useState(false);
const intl = useIntl();
const enableInContextSidebar = Boolean(new URLSearchParams(locationObj.search).get('inContextSidebar') !== null);

/* istanbul ignore next */
const setup = useCallback((editor) => {
Expand Down Expand Up @@ -99,6 +100,29 @@ const TinyMCEEditor = (props) => {
contentStyle = '';
}

// eslint-disable-next-line consistent-return
useEffect(() => {
if (enableInContextSidebar) {
const checkToxDialogVisibility = () => {
const toxDialog = document.querySelector('.tox-dialog');
if (toxDialog) {
toxDialog.style.alignSelf = 'start';
toxDialog.style.marginTop = '50px';
}
};

const observer = new MutationObserver(checkToxDialogVisibility);

// Observe changes to the entire document
observer.observe(document, { childList: true, subtree: true });

// Clean up the observer when the component unmounts
return () => {
observer.disconnect();
};
}
}, [enableInContextSidebar]);

return (
<>
<Editor
Expand Down

0 comments on commit af5b10a

Please sign in to comment.