Skip to content

Commit

Permalink
Revert "fix iframe resize on auth dropdown opening"
Browse files Browse the repository at this point in the history
This reverts commit 8e96aa2.
  • Loading branch information
umputun committed Sep 21, 2022
1 parent 8e96aa2 commit 4733ad8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 58 deletions.
4 changes: 3 additions & 1 deletion frontend/apps/remark42/app/components/auth/auth.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export function useDropdown(disableClosing?: boolean) {
useEffect(() => {
const dropdownElement = rootRef.current;

if (!dropdownElement) {
if (!dropdownElement || !showDropdown) {
handleChangeIframeSize(document.body);

return;
}

Expand Down
95 changes: 41 additions & 54 deletions frontend/apps/remark42/app/components/root/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class Root extends Component<Props, State> {
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);
Expand Down Expand Up @@ -273,12 +274,33 @@ export class Root extends Component<Props, State> {
<div className={clsx('sort-picker', styles.sortPicker)}>
<SortPicker />
</div>
<Comments
commentsShown={commentsShown}
isLoading={props.isCommentsLoading}
topComments={props.topComments}
showMore={this.showMore}
/>
{!!this.props.topComments.length && !props.isCommentsLoading && (
<div className="root__threads" role="list">
{(IS_MOBILE && commentsShown < this.props.topComments.length
? this.props.topComments.slice(0, commentsShown)
: this.props.topComments
).map((id) => (
<Thread
key={`thread-${id}`}
id={id}
mix="root__thread"
level={0}
getPreview={this.props.getPreview}
/>
))}

{commentsShown < this.props.topComments.length && IS_MOBILE && (
<Button className={clsx('more-comments', styles.moreComments)} onClick={this.showMore}>
<FormattedMessage id="root.show-more" defaultMessage="Show more" />
</Button>
)}
</div>
)}
{props.isCommentsLoading && (
<div className="root__threads" role="list">
<Preloader className="root__preloader" />
</div>
)}
</>
)}
</div>
Expand All @@ -287,17 +309,21 @@ export class Root extends Component<Props, State> {
}
}

const CopyrightLink = (title: string) => (
<a class="root__copyright-link" href="https://remark42.com/">
{title}
</a>
);

function updateIframeHeight() {
postMessageToParent({ height: document.body.offsetHeight });
}

interface CommentsProps {
isLoading: boolean;
topComments: string[];
commentsShown: number;
showMore(): void;
}
function Comments({ isLoading, topComments, commentsShown, showMore }: CommentsProps) {
/** Root component connected to redux */
export function ConnectedRoot() {
const intl = useIntl();
const props = useSelector(mapStateToProps);
const actions = useActions(boundActions);
const rootRef = useRef<HTMLDivElement>(null);

useEffect(() => {
Expand All @@ -310,55 +336,16 @@ function Comments({ isLoading, topComments, commentsShown, showMore }: CommentsP
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 });

return () => observer.disconnect();
}, []);

const renderComments =
IS_MOBILE && commentsShown < topComments.length ? topComments.slice(0, commentsShown) : topComments;
const isShowMoreButtonVisible = IS_MOBILE && commentsShown < topComments.length;

return (
<div className="root__threads" role="list" ref={rootRef}>
{isLoading ? (
<Preloader className="root__preloader" />
) : (
<>
{topComments.length > 0 &&
renderComments.map((id) => (
<Thread key={`thread-${id}`} id={id} mix="root__thread" level={0} getPreview={getPreview} />
))}
{isShowMoreButtonVisible && (
<Button className={clsx('more-comments', styles.moreComments)} onClick={showMore}>
<FormattedMessage id="root.show-more" defaultMessage="Show more" />
</Button>
)}
</>
)}
</div>
);
}

const CopyrightLink = (title: string) => (
<a class="root__copyright-link" href="https://remark42.com/">
{title}
</a>
);

/** Root component connected to redux */
export function ConnectedRoot() {
const intl = useIntl();
const props = useSelector(mapStateToProps);
const actions = useActions(boundActions);

return (
<div className={clsx(b('root', {}, { theme: props.theme }), props.theme)}>
<div className={clsx(b('root', {}, { theme: props.theme }), props.theme)} ref={rootRef}>
<Root {...props} {...actions} intl={intl} />
<p className="root__copyright" role="contentinfo">
<FormattedMessage
Expand Down
3 changes: 0 additions & 3 deletions frontend/apps/remark42/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ module.exports = (_, { mode, analyze }) => {
{ path: '/api', target: REMARK_API_BASE_URL, changeOrigin: true },
{ path: '/auth', target: REMARK_API_BASE_URL, changeOrigin: true },
],
client: {
overlay: false,
},
};

const plugins = [
Expand Down

0 comments on commit 4733ad8

Please sign in to comment.