From bcb23bc9dcc5eff55b6c7fbaf09b2751224089d6 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Wed, 31 Aug 2022 14:52:49 +0200 Subject: [PATCH] Cleaned up Frame components refs https://github.com/TryGhost/Team/issues/1858 --- apps/comments-ui/src/App.js | 14 +-- apps/comments-ui/src/components/Frame.js | 107 ++++++++++-------- .../src/components/modals/GenericDialog.js | 6 +- 3 files changed, 67 insertions(+), 60 deletions(-) diff --git a/apps/comments-ui/src/App.js b/apps/comments-ui/src/App.js index 7e1140db53..9e1805d0f4 100644 --- a/apps/comments-ui/src/App.js +++ b/apps/comments-ui/src/App.js @@ -1,4 +1,4 @@ -import Frame from './components/Frame'; +import {CommentsFrame} from './components/Frame'; import React from 'react'; import {isSyncAction, ActionHandler, SyncActionHandler} from './actions'; import {createPopupNotification} from './utils/helpers'; @@ -18,14 +18,6 @@ function AuthFrame({adminUrl, onLoad}) { ); } -function CommentsBoxContainer({done, appVersion}) { - return ( - - - - ); -} - function SentryErrorBoundary({dsn, children}) { // todo: add Sentry.ErrorBoundary wrapper if Sentry is enabled return ( @@ -309,7 +301,9 @@ export default class App extends React.Component { return ( - + + + diff --git a/apps/comments-ui/src/components/Frame.js b/apps/comments-ui/src/components/Frame.js index 73736906a5..e72b938902 100644 --- a/apps/comments-ui/src/components/Frame.js +++ b/apps/comments-ui/src/components/Frame.js @@ -2,32 +2,73 @@ import React, {useContext, useState} from 'react'; import AppContext from '../AppContext'; import IFrame from './IFrame'; -const Frame = ({ - children, - type, - ...props -}) => { +/** + * Loads all the CSS styles inside an iFrame. Only shows the visible content as soon as the CSS file with the tailwind classes has loaded. + */ +const TailwindFrame = ({children, onResize, style, title}) => { const {stylesUrl} = useContext(AppContext); + const [cssLoaded, setCssLoaded] = useState(!stylesUrl); - const styles = ` + const initialStyles = ` body, html { overflow: hidden; } `; - // We have two types of frames: - // - A full width + content fitted height one - // - A fixed positioned one for modals - /** - * @type {'dynamic'|'fixed'} - */ - type = type ?? 'dynamic'; + const onLoadCSS = () => { + setCssLoaded(true); + }; - // For now we don't listen for type changes, we could consider adding useEffect, but that won't be used - const defaultStyle = type === 'dynamic' ? { + const head = ( + <> + {stylesUrl ? : null} +