refactor: Consolidate icon imports across components and streamline import statements for improved readability

This commit is contained in:
2026-07-06 03:29:18 +10:00
parent 1f71fd7a51
commit 09db721b7e
221 changed files with 3472 additions and 2128 deletions
+87 -57
View File
@@ -1,38 +1,39 @@
import React, { useEffect, useRef } from 'react';
import { Box, Icon, Icons, Text } from 'folds';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Box, Scroll, Text, color } from 'folds';
import { Icon, Icons } from '../../components/icons';
import classNames from 'classnames';
import { useSetAtom } from 'jotai';
import { Page, PageContent } from '../../components/page';
import { useMatrixClient } from '../../hooks/useMatrixClient';
import { PowerLevelsContextProvider, usePowerLevels } from '../../hooks/usePowerLevels';
import { ThreadView } from '../room/ThreadView';
import { RoomInput } from '../room/RoomInput';
import { useEditor } from '../../components/editor';
import { Page, PageContent } from '../../components/page';
import { ContainerColor } from '../../styles/ContainerColor.css';
import { activeThreadIdAtomFamily } from '../../state/activeThread';
import { useForumBoardContext } from './ForumBoardContext';
import * as css from './ForumBoardView.css';
import { ForumThreadDetail } from './ForumThreadDetail';
import type { ForumPost } from './types';
import * as theme from './forumTheme.css';
/** Thread detail + composer (main pane); post list lives in ForumFeedSidebar. */
/** Thread detail in the main pane; post list lives in ForumFeedSidebar. */
export function ForumBoardDetail() {
const mx = useMatrixClient();
const editor = useEditor();
const detailScrollRef = useRef<HTMLDivElement>(null);
const [optimisticPost, setOptimisticPost] = useState<ForumPost | null>(null);
const {
forumSpace,
query,
error,
selectedPostId,
activeTopicRoomId,
error,
threads,
recordThreadReply,
} = useForumBoardContext();
const activeTopicRoom = activeTopicRoomId ? mx.getRoom(activeTopicRoomId) : null;
const topicPowerLevels = usePowerLevels(activeTopicRoom ?? forumSpace);
const topicSelected = Boolean(query.topic);
const setActiveThreadId = useSetAtom(
activeThreadIdAtomFamily(activeTopicRoomId ?? forumSpace.roomId)
);
const topicSelected = Boolean(query.topic);
useEffect(() => {
if (selectedPostId && activeTopicRoomId) {
setActiveThreadId(selectedPostId);
@@ -42,51 +43,80 @@ export function ForumBoardDetail() {
return undefined;
}, [selectedPostId, activeTopicRoomId, setActiveThreadId]);
const showComposer = Boolean(activeTopicRoom && topicSelected);
useEffect(() => {
if (optimisticPost && optimisticPost.eventId !== selectedPostId) {
setOptimisticPost(null);
}
}, [optimisticPost, selectedPostId]);
const selectedThread = useMemo(
() => threads.find((t) => t.eventId === selectedPostId),
[threads, selectedPostId]
);
const handleReplySent = useCallback(
(_reply: ForumPost) => {
if (selectedPostId) {
recordThreadReply(selectedPostId);
}
},
[recordThreadReply, selectedPostId]
);
const showThread = Boolean(selectedPostId && activeTopicRoom);
const threadInitialPost =
optimisticPost?.eventId === selectedPostId ? optimisticPost : null;
const detailDropRef = useRef<HTMLDivElement>(null);
return (
<Page>
<PageContent>
<Box className={css.ForumDetailOnlyRoot}>
{error && (
<Box style={{ padding: '0.5rem 1rem' }}>
<Text style={{ color: 'var(--fc-critical, #f38ba8)' }}>{error}</Text>
</Box>
<Page className={classNames(ContainerColor({ variant: 'Background' }), theme.ForumAppRoot)}>
<PageContent className={theme.ForumPageContent}>
{error && (
<Text as="p" style={{ color: color.Critical.Main, padding: '0.5rem 1rem' }}>
{error}
</Text>
)}
<aside className={theme.ForumDetailPane}>
{showThread && activeTopicRoom ? (
<div ref={detailDropRef} className={theme.ForumTopicPostDetailThreadLayout}>
<ForumThreadDetail
roomId={activeTopicRoom.roomId}
rootEventId={selectedPostId!}
titleHint={selectedThread?.title}
initialPost={threadInitialPost}
fileDropContainerRef={detailDropRef}
onReplySent={handleReplySent}
/>
</div>
) : (
<Scroll
id="topicPostDetail"
className={theme.ForumTopicPostDetailScroll}
variant="Surface"
direction="Vertical"
size="300"
hideTrack
visibility="Hover"
>
<div className={theme.ForumTopicPostDetailInner}>
<Box
className={theme.ForumEmptyDetail}
direction="Column"
alignItems="Center"
justifyContent="Center"
gap="300"
>
<Icon src={Icons.Thread} size="600" />
<Text size="T300" priority="300">
{topicSelected
? 'Select a post to read the thread'
: 'Pick a category and topic, then choose a post'}
</Text>
</Box>
</div>
</Scroll>
)}
<Box ref={detailScrollRef} className={css.ForumDetailPanelFull}>
{selectedPostId && activeTopicRoom ? (
<PowerLevelsContextProvider value={topicPowerLevels}>
<ThreadView room={activeTopicRoom} threadRootId={selectedPostId} />
</PowerLevelsContextProvider>
) : (
<Box grow="Yes" alignItems="Center" justifyContent="Center" direction="Column" gap="200">
<Icon src={Icons.Thread} size="600" />
<Text priority="300">
{topicSelected
? 'Select a post from the list'
: 'Choose a topic in the sidebar'}
</Text>
</Box>
)}
{showComposer && activeTopicRoom && (
<Box
shrink="No"
direction="Column"
style={{ padding: '0.75rem', borderTop: '1px solid var(--fc-surface-container)' }}
>
<PowerLevelsContextProvider value={topicPowerLevels}>
<RoomInput
room={activeTopicRoom}
editor={editor}
roomId={activeTopicRoom.roomId}
fileDropContainerRef={detailScrollRef}
/>
</PowerLevelsContextProvider>
</Box>
)}
</Box>
</Box>
</aside>
</PageContent>
</Page>
);