From b4eacc717580efa05e878dca3fb8f901d42c3fde Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:25:05 +0900 Subject: [PATCH] [bugfix_2] Main Page: Message Log Input Box Ratio: Fix init apply ratio. (when I did it at the first time, 5ddc77a9ccf2be4a73cf4493eaf461f27d0f9b70, it looks not fixed yet.) --- .../message_container/MessageContainer.jsx | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src-ui/app/main_page/main_section/message_container/MessageContainer.jsx b/src-ui/app/main_page/main_section/message_container/MessageContainer.jsx index cad18079..dbc5c100 100644 --- a/src-ui/app/main_page/main_section/message_container/MessageContainer.jsx +++ b/src-ui/app/main_page/main_section/message_container/MessageContainer.jsx @@ -14,7 +14,7 @@ export const MessageContainer = () => { const { currentUiScaling } = useUiScaling(); const [is_hovered, setIsHovered] = useState(false); const [message_box_height_in_rem, setMessageBoxHeightInRem] = useState(10); - const FONT_SIZE_STANDARD = 10 * currentUiScaling.data / 100; // 10px = 1rem + const FONT_SIZE_STANDARD = 10 * currentUiScaling.data / 100; // 10px = 1rem const { currentIsAppliedInitMessageBoxHeight, updateIsAppliedInitMessageBoxHeight } = useStore_IsAppliedInitMessageBoxHeight(); const container_ref = useRef(null); @@ -23,9 +23,10 @@ export const MessageContainer = () => { const asyncSetMessageBoxHeightInRem = async (data) => { const minimized = await appWindow.isMinimized(); - if (minimized === true) return; // don't save while the window is minimized. + if (minimized) return; // don't save while the window is minimized. setMessageBoxHeightInRem(data); }; + const calculateMessageBoxRatioAndHeight = () => { if (!currentIsAppliedInitMessageBoxHeight.data) { asyncSetMessageInputBoxRatio(currentMessageInputBoxRatio.data); @@ -33,7 +34,7 @@ export const MessageContainer = () => { return; } - if (log_box_ref.current && message_box_wrapper_ref.current) { + if (log_box_ref.current && message_box_wrapper_ref.current && container_ref.current) { const container_height = container_ref.current.offsetHeight; const container_padding_bottom = parseFloat(window.getComputedStyle(container_ref.current).paddingBottom); const total_height = container_height - container_padding_bottom; @@ -43,6 +44,8 @@ export const MessageContainer = () => { asyncSetMessageInputBoxRatio(message_box_ratio); asyncSetMessageBoxHeightInRem(convertRatioToRem(message_box_ratio)); + } else { + console.warn("References not ready for calculation"); } }; @@ -53,24 +56,26 @@ export const MessageContainer = () => { }); useEffect(() => { - // Note: I thought the part "1.4" is message box bottom padding + (message box separator height/2) - // but it should be fixed at 1.4. Idk why, tho. asyncSetMessageBoxHeightInRem((position / FONT_SIZE_STANDARD) - 1.4); }, [position]); - useEffect(() => { asyncSetMessageBoxHeightInRem(convertRatioToRem(currentMessageInputBoxRatio.data)); }, [currentMessageInputBoxRatio.data]); const convertRatioToRem = (ratio) => { + if (!container_ref.current) return 0; const container_height = container_ref.current.offsetHeight; const container_padding_bottom = parseFloat(window.getComputedStyle(container_ref.current).paddingBottom); const total_height = container_height - container_padding_bottom; - if (total_height === 0) return 0; - return ((ratio / 100) * total_height / FONT_SIZE_STANDARD); + return total_height === 0 ? 0 : ((ratio / 100) * total_height / FONT_SIZE_STANDARD); }; + useEffect(() => { + calculateMessageBoxRatioAndHeight(); + updateIsAppliedInitMessageBoxHeight(true); // Ensure this happens after initial calculation + }, []); + useEffect(() => { let resizeTimeout; @@ -86,10 +91,6 @@ export const MessageContainer = () => { }; }, []); - useEffect(() => { - updateIsAppliedInitMessageBoxHeight(true); - }, []); - return (