Apply the auto-fixable lint rules and the formatter, and drop the Vite build artifacts.
This commit is contained in:
@@ -9,11 +9,7 @@ import { getSpaceLobbyPath } from '../../pages/pathUtils';
|
||||
import { createRoomModalAtom } from '../../state/createRoomModal';
|
||||
import { createSpaceModalAtom } from '../../state/createSpaceModal';
|
||||
import { StateEvent } from '../../../types/matrix/room';
|
||||
import {
|
||||
buildForumSections,
|
||||
buildTopicThreads,
|
||||
buildThreadSummaries,
|
||||
} from './forumTopicHelpers';
|
||||
import { buildForumSections, buildTopicThreads, buildThreadSummaries } from './forumTopicHelpers';
|
||||
import { applyTopicStatusSort } from './topicSearch';
|
||||
import {
|
||||
createForumPostFromPayload,
|
||||
@@ -39,7 +35,7 @@ export type ForumBoardScope = {
|
||||
function scopesFromSelection(
|
||||
sections: ForumSection[],
|
||||
category?: string,
|
||||
topic?: string
|
||||
topic?: string,
|
||||
): Array<{ roomId: string; sectionTitle?: string; topicName?: string }> {
|
||||
if (topic) {
|
||||
for (const section of sections) {
|
||||
@@ -66,7 +62,7 @@ function scopesFromSelection(
|
||||
roomId: t.roomId,
|
||||
sectionTitle: section.title,
|
||||
topicName: t.name,
|
||||
}))
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -76,10 +72,7 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
const navigate = useNavigate();
|
||||
const selectedRoomId = useSelectedRoom();
|
||||
|
||||
const searchParams = useMemo(
|
||||
() => new URLSearchParams(location.search),
|
||||
[location.search]
|
||||
);
|
||||
const searchParams = useMemo(() => new URLSearchParams(location.search), [location.search]);
|
||||
|
||||
const filterQuery: ForumBoardQuery = useMemo(
|
||||
() => ({
|
||||
@@ -89,7 +82,7 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
status: (searchParams.get('status') as ForumBoardQuery['status']) || 'all',
|
||||
sort: (searchParams.get('sort') as ForumBoardQuery['sort']) || 'hot',
|
||||
}),
|
||||
[searchParams]
|
||||
[searchParams],
|
||||
);
|
||||
|
||||
const query: ForumBoardQuery = useMemo(
|
||||
@@ -98,7 +91,7 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
post: searchParams.get('post') || undefined,
|
||||
postRoom: searchParams.get('postRoom') || undefined,
|
||||
}),
|
||||
[filterQuery, searchParams]
|
||||
[filterQuery, searchParams],
|
||||
);
|
||||
|
||||
const [sections, setSections] = useState<ForumSection[]>([]);
|
||||
@@ -115,8 +108,7 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
mutate(next);
|
||||
const search = next.toString();
|
||||
|
||||
const onTopicRoomRoute =
|
||||
Boolean(selectedRoomId) && selectedRoomId !== forumSpace.roomId;
|
||||
const onTopicRoomRoute = Boolean(selectedRoomId) && selectedRoomId !== forumSpace.roomId;
|
||||
|
||||
navigate(
|
||||
{
|
||||
@@ -125,10 +117,10 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
: location.pathname,
|
||||
search: search ? `?${search}` : '',
|
||||
},
|
||||
{ replace: true }
|
||||
{ replace: true },
|
||||
);
|
||||
},
|
||||
[location.pathname, location.search, navigate, mx, forumSpace.roomId, selectedRoomId]
|
||||
[location.pathname, location.search, navigate, mx, forumSpace.roomId, selectedRoomId],
|
||||
);
|
||||
|
||||
const setQueryParam = useCallback(
|
||||
@@ -142,7 +134,7 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
}
|
||||
});
|
||||
},
|
||||
[applyForumSearchParams]
|
||||
[applyForumSearchParams],
|
||||
);
|
||||
|
||||
const setCategory = useCallback(
|
||||
@@ -155,7 +147,7 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
next.delete('postRoom');
|
||||
});
|
||||
},
|
||||
[applyForumSearchParams]
|
||||
[applyForumSearchParams],
|
||||
);
|
||||
|
||||
const loadSections = useCallback(async () => {
|
||||
@@ -171,39 +163,42 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
}
|
||||
}, [mx, scope.forumSpaceId]);
|
||||
|
||||
const refreshThreads = useCallback(async (options?: { silent?: boolean }) => {
|
||||
if (!options?.silent) setLoadingThreads(true);
|
||||
setError(null);
|
||||
try {
|
||||
const roomScopes = scopesFromSelection(sections, filterQuery.category, filterQuery.topic);
|
||||
if (roomScopes.length === 0) {
|
||||
setThreads([]);
|
||||
return;
|
||||
}
|
||||
const refreshThreads = useCallback(
|
||||
async (options?: { silent?: boolean }) => {
|
||||
if (!options?.silent) setLoadingThreads(true);
|
||||
setError(null);
|
||||
try {
|
||||
const roomScopes = scopesFromSelection(sections, filterQuery.category, filterQuery.topic);
|
||||
if (roomScopes.length === 0) {
|
||||
setThreads([]);
|
||||
return;
|
||||
}
|
||||
|
||||
let posts;
|
||||
if (roomScopes.length === 1) {
|
||||
const result = await listTopicFeedPosts(mx, roomScopes[0].roomId);
|
||||
posts = result.posts;
|
||||
setPostsNextBatch(result.nextBatch);
|
||||
const scopeMeta = roomScopes[0];
|
||||
posts.forEach((post) => {
|
||||
post.topicRoomId = scopeMeta.roomId;
|
||||
if (scopeMeta.sectionTitle) post.sectionTitle = scopeMeta.sectionTitle;
|
||||
if (scopeMeta.topicName) post.topicName = scopeMeta.topicName;
|
||||
});
|
||||
} else {
|
||||
posts = await loadAggregatedTopicFeed(mx, roomScopes);
|
||||
setPostsNextBatch(null);
|
||||
}
|
||||
let posts;
|
||||
if (roomScopes.length === 1) {
|
||||
const result = await listTopicFeedPosts(mx, roomScopes[0].roomId);
|
||||
posts = result.posts;
|
||||
setPostsNextBatch(result.nextBatch);
|
||||
const scopeMeta = roomScopes[0];
|
||||
posts.forEach((post) => {
|
||||
post.topicRoomId = scopeMeta.roomId;
|
||||
if (scopeMeta.sectionTitle) post.sectionTitle = scopeMeta.sectionTitle;
|
||||
if (scopeMeta.topicName) post.topicName = scopeMeta.topicName;
|
||||
});
|
||||
} else {
|
||||
posts = await loadAggregatedTopicFeed(mx, roomScopes);
|
||||
setPostsNextBatch(null);
|
||||
}
|
||||
|
||||
setThreads(buildTopicThreads(posts, filterQuery));
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to load forum posts');
|
||||
} finally {
|
||||
if (!options?.silent) setLoadingThreads(false);
|
||||
}
|
||||
}, [mx, sections, filterQuery]);
|
||||
setThreads(buildTopicThreads(posts, filterQuery));
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to load forum posts');
|
||||
} finally {
|
||||
if (!options?.silent) setLoadingThreads(false);
|
||||
}
|
||||
},
|
||||
[mx, sections, filterQuery],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
loadSections();
|
||||
@@ -214,10 +209,7 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
if (event.getType() !== StateEvent.SpaceChild) return;
|
||||
const roomId = event.getRoomId();
|
||||
if (!roomId) return;
|
||||
if (
|
||||
roomId === forumSpace.roomId ||
|
||||
sections.some((section) => section.spaceId === roomId)
|
||||
) {
|
||||
if (roomId === forumSpace.roomId || sections.some((section) => section.spaceId === roomId)) {
|
||||
loadSections();
|
||||
}
|
||||
};
|
||||
@@ -285,7 +277,7 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
}
|
||||
});
|
||||
},
|
||||
[applyForumSearchParams]
|
||||
[applyForumSearchParams],
|
||||
);
|
||||
|
||||
const insertThreadFromNewPost = useCallback(
|
||||
@@ -312,7 +304,7 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
topicRoomId: published.topicRoomId,
|
||||
sectionTitle: scopeMeta?.sectionTitle,
|
||||
topicName: scopeMeta?.topicName,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if (inScope) {
|
||||
@@ -321,14 +313,18 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
setThreads((prev) => {
|
||||
const without = prev.filter((t) => t.eventId !== summary.eventId);
|
||||
const merged = [summary, ...without];
|
||||
return applyTopicStatusSort(merged, filterQuery.status || 'all', filterQuery.sort || 'hot');
|
||||
return applyTopicStatusSort(
|
||||
merged,
|
||||
filterQuery.status || 'all',
|
||||
filterQuery.sort || 'hot',
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return post;
|
||||
},
|
||||
[mx, sections, filterQuery]
|
||||
[mx, sections, filterQuery],
|
||||
);
|
||||
|
||||
const recordThreadReply = useCallback((rootEventId: string) => {
|
||||
@@ -340,8 +336,8 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
totalReplies: t.totalReplies + 1,
|
||||
lastActivityTs: Date.now(),
|
||||
}
|
||||
: t
|
||||
)
|
||||
: t,
|
||||
),
|
||||
);
|
||||
}, []);
|
||||
|
||||
@@ -367,7 +363,7 @@ export function useForumBoard(scope: ForumBoardScope, forumSpace: Room) {
|
||||
setThreads((prev) => {
|
||||
const existingIds = new Set(prev.map((t) => t.eventId));
|
||||
const added = buildTopicThreads(result.posts, filterQuery).filter(
|
||||
(t) => !existingIds.has(t.eventId)
|
||||
(t) => !existingIds.has(t.eventId),
|
||||
);
|
||||
const merged = [...prev, ...added];
|
||||
const sort = filterQuery.sort || 'hot';
|
||||
|
||||
Reference in New Issue
Block a user