From 3515e312375b2fa51f01f26702eac5c12872f31e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicole=20Miko=C5=82ajczyk?= Date: Wed, 2 Apr 2025 17:14:45 +0200 Subject: [PATCH] pl-fe: restore some code i don't really like MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicole Mikołajczyk --- packages/pl-fe/src/components/account.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/pl-fe/src/components/account.tsx b/packages/pl-fe/src/components/account.tsx index 7d5926169..b39d3baed 100644 --- a/packages/pl-fe/src/components/account.tsx +++ b/packages/pl-fe/src/components/account.tsx @@ -1,4 +1,4 @@ -import React, { useRef } from 'react'; +import React, { useLayoutEffect, useRef, useState } from 'react'; import { defineMessages, useIntl, FormattedMessage } from 'react-intl'; import { Link, useHistory } from 'react-router-dom'; @@ -136,6 +136,8 @@ const Account = ({ const overflowRef = useRef(null); const actionRef = useRef(null); + const [style, setStyle] = useState({}); + const me = useAppSelector((state) => state.me); const username = useAppSelector((state) => account ? getAcct(account, displayFqn(state)) : null); @@ -175,6 +177,18 @@ const Account = ({ const intl = useIntl(); + useLayoutEffect(() => { + const style: React.CSSProperties = {}; + const actionWidth = actionRef.current?.clientWidth || 0; + + if (overflowRef.current) { + style.maxWidth = Math.max(0, overflowRef.current.clientWidth - (withAvatar ? avatarSize + 12 : 0) - (actionWidth ? actionWidth + 12 : 0)); + } + + setStyle(style); + }, [overflowRef, actionRef]); + + if (!account) { return null; } @@ -261,7 +275,7 @@ const Account = ({ )} -
+
{children}}