From 363e05d58065939b647ad199deeab44f677a7213 Mon Sep 17 00:00:00 2001 From: Paul Mineev Date: Wed, 14 Sep 2022 09:42:50 -0700 Subject: [PATCH] fix iframe resize on auth dropdown opening --- .../app/components/auth/auth.hooks.ts | 4 +- .../remark42/app/components/root/root.tsx | 95 +++++++++++-------- frontend/apps/remark42/webpack.config.js | 3 + 3 files changed, 58 insertions(+), 44 deletions(-) diff --git a/frontend/apps/remark42/app/components/auth/auth.hooks.ts b/frontend/apps/remark42/app/components/auth/auth.hooks.ts index dadb1b0c..c5e62e65 100644 --- a/frontend/apps/remark42/app/components/auth/auth.hooks.ts +++ b/frontend/apps/remark42/app/components/auth/auth.hooks.ts @@ -70,9 +70,7 @@ export function useDropdown(disableClosing?: boolean) { useEffect(() => { const dropdownElement = rootRef.current; - if (!dropdownElement || !showDropdown) { - handleChangeIframeSize(document.body); - + if (!dropdownElement) { return; } diff --git a/frontend/apps/remark42/app/components/root/root.tsx b/frontend/apps/remark42/app/components/root/root.tsx index 43e2091d..57fe3e10 100644 --- a/frontend/apps/remark42/app/components/root/root.tsx +++ b/frontend/apps/remark42/app/components/root/root.tsx @@ -122,7 +122,6 @@ export class Root extends Component { Promise.all([userloading, this.props.fetchComments()]).finally(() => { setTimeout(this.checkUrlHash); window.addEventListener('hashchange', this.checkUrlHash); - postMessageToParent({ height: document.body.offsetHeight }); }); window.addEventListener('message', this.onMessage); @@ -274,33 +273,12 @@ export class Root extends Component {
- {!!this.props.topComments.length && !props.isCommentsLoading && ( -
- {(IS_MOBILE && commentsShown < this.props.topComments.length - ? this.props.topComments.slice(0, commentsShown) - : this.props.topComments - ).map((id) => ( - - ))} - - {commentsShown < this.props.topComments.length && IS_MOBILE && ( - - )} -
- )} - {props.isCommentsLoading && ( -
- -
- )} + )} @@ -309,21 +287,17 @@ export class Root extends Component { } } -const CopyrightLink = (title: string) => ( - - {title} - -); - function updateIframeHeight() { postMessageToParent({ height: document.body.offsetHeight }); } -/** Root component connected to redux */ -export function ConnectedRoot() { - const intl = useIntl(); - const props = useSelector(mapStateToProps); - const actions = useActions(boundActions); +interface CommentsProps { + isLoading: boolean; + topComments: string[]; + commentsShown: number; + showMore(): void; +} +function Comments({ isLoading, topComments, commentsShown, showMore }: CommentsProps) { const rootRef = useRef(null); useEffect(() => { @@ -336,7 +310,9 @@ export function ConnectedRoot() { updateIframeHeight(); // a hacky way to force iframe height update when new image is rendered and loaded - rootRef.current?.querySelectorAll('img').forEach((img) => img.addEventListener('load', updateIframeHeight)); + rootRef.current?.querySelectorAll('img').forEach((img) => { + img.addEventListener('load', updateIframeHeight); + }); }); observer.observe(rootRef.current, { attributes: true, childList: true, subtree: true }); @@ -344,8 +320,45 @@ export function ConnectedRoot() { return () => observer.disconnect(); }, []); + const renderComments = + IS_MOBILE && commentsShown < topComments.length ? topComments.slice(0, commentsShown) : topComments; + const isShowMoreButtonVisible = IS_MOBILE && commentsShown < topComments.length; + return ( -
+
+ {isLoading ? ( + + ) : ( + <> + {topComments.length > 0 && + renderComments.map((id) => ( + + ))} + {isShowMoreButtonVisible && ( + + )} + + )} +
+ ); +} + +const CopyrightLink = (title: string) => ( + + {title} + +); + +/** Root component connected to redux */ +export function ConnectedRoot() { + const intl = useIntl(); + const props = useSelector(mapStateToProps); + const actions = useActions(boundActions); + + return ( +

{ { path: '/api', target: REMARK_API_BASE_URL, changeOrigin: true }, { path: '/auth', target: REMARK_API_BASE_URL, changeOrigin: true }, ], + client: { + overlay: false, + }, }; const plugins = [