From a5c23d8081b2332f06f765654f914d2c3234983d Mon Sep 17 00:00:00 2001 From: Rogee Date: Wed, 7 Oct 2026 12:24:38 +0800 Subject: [PATCH] fix(messages): dismiss sync warnings and fill available page height --- web/src/pages/creator/messages/index.tsx | 48 +++++++++-- web/tests/private-messages-page.test.cjs | 102 ++++++++++++++++++++--- 2 files changed, 128 insertions(+), 22 deletions(-) diff --git a/web/src/pages/creator/messages/index.tsx b/web/src/pages/creator/messages/index.tsx index 9a05f24..6287d63 100644 --- a/web/src/pages/creator/messages/index.tsx +++ b/web/src/pages/creator/messages/index.tsx @@ -1,7 +1,7 @@ import { Bubble, Conversations, Sender } from '@ant-design/x'; import { Alert, App, Button, Card, Empty, Flex, Form, Input, Modal, Select, Spin, Splitter, Tooltip, Typography } from 'antd'; import { CheckCircleOutlined, CloseCircleOutlined, LoadingOutlined, PlusOutlined, QuestionCircleOutlined } from '@ant-design/icons'; -import { useEffect, useRef, useState } from 'react'; +import { useEffect, useLayoutEffect, useRef, useState } from 'react'; import { creatorCreate, creatorGet } from '@/services/api'; import { conflictMessage, dateTime } from '@/utils/helpers'; import { @@ -36,6 +36,9 @@ export default function PrivateMessagesPage() { const [accounts, setAccounts] = useState([]); const accountsRef = useRef([]); const [statuses, setStatuses] = useState([]); + const [dismissedSyncErrors, setDismissedSyncErrors] = useState>({}); + const cardRef = useRef(null); + const [cardHeight, setCardHeight] = useState(); const [accountId, setAccountId] = useState(); const [contacts, setContacts] = useState([]); const [contactTotal, setContactTotal] = useState(0); @@ -69,6 +72,25 @@ export default function PrivateMessagesPage() { const [sendForm] = Form.useForm(); const [newChatError, setNewChatError] = useState(''); + useLayoutEffect(() => { + const card = cardRef.current; + if (!card?.parentElement) return; + const parent = card.parentElement; + const resize = () => { + const bottomPadding = Number.parseFloat(getComputedStyle(parent).paddingBottom); + const top = card.getBoundingClientRect().top + window.scrollY; + setCardHeight(Math.max(0, window.innerHeight - top - bottomPadding)); + }; + resize(); + const observer = new ResizeObserver(resize); + observer.observe(parent); + window.addEventListener('resize', resize); + return () => { + observer.disconnect(); + window.removeEventListener('resize', resize); + }; + }, []); + function changeDraft(key: string, text: string) { draftsRef.current = updateDraft(draftsRef.current, key, text); setDrafts(draftsRef.current); @@ -128,6 +150,9 @@ export default function PrivateMessagesPage() { accountsRef.current = accountRows; setAccounts(accountRows); setStatuses(statusRows); + setDismissedSyncErrors((previous) => Object.fromEntries( + Object.entries(previous).filter(([id, error]) => statusRows.some((status) => status.account_id === id && status.error === error)), + )); const pages = await Promise.all(Array.from({ length: contactPages.current }, (_, index) => readPage(`/creator/private-messages/conversations?${conversationQuery({ accountId }, index + 1, PAGE_SIZE)}`))); if (stopped) return; @@ -306,17 +331,22 @@ export default function PrivateMessagesPage() { && enabledAccounts.some((account) => account.id === contact.account_id)); return ( - - - + + + {contactTotal} 个私信会话 {contactError && } - {statuses.filter((status) => status.error).map((status) => )} - + {statuses.filter((status) => status.error && dismissedSyncErrors[status.account_id] !== status.error).map((status) => setDismissedSyncErrors((previous) => ({ ...previous, [status.account_id]: status.error })) }} + style={{ flexShrink: 0 }} + />)} + - +