@@ -19,6 +19,9 @@ import SecureMediaEmbed from "./SecureMediaEmbed";
1919import Thumbnail from "./Thumbnail" ;
2020import { postTypeOptions } from "../utils/timeOptions" ;
2121import SegmentedControl from "./SegmentedControl" ;
22+ import TopCommunitiesStatusBar from "./TopCommunitiesStatusBar" ;
23+
24+ const NUM_TOP_COMMUNITIES = 6 ;
2225
2326const columnClasses : { [ key : number ] : string } = {
2427 1 : "lg:columns-1" ,
@@ -52,6 +55,19 @@ const UserPost: React.FC<UserPostProps> = memo(({ username }) => {
5255 return posts . filter ( ( post ) => getPostType ( post ) === postTypeFilter ) ;
5356 } , [ posts , comments , postTypeFilter , activeTab ] ) ;
5457
58+ const topCommunities = useMemo ( ( ) => {
59+ const communityCounts : { [ key : string ] : number } = { } ;
60+
61+ [ ...posts , ...comments ] . forEach ( ( item ) => {
62+ if ( item . subreddit ) {
63+ communityCounts [ item . subreddit ] = ( communityCounts [ item . subreddit ] || 0 ) + 1 ;
64+ }
65+ } ) ;
66+
67+ const sortedCommunities = Object . entries ( communityCounts ) . sort ( ( [ , countA ] , [ , countB ] ) => countB - countA ) ;
68+ return sortedCommunities . slice ( 0 , NUM_TOP_COMMUNITIES ) ;
69+ } , [ posts , comments ] ) ;
70+
5571 const fetchPosts = useCallback ( ( ) => {
5672 if ( ! hasMore ) return ;
5773
@@ -271,6 +287,7 @@ const UserPost: React.FC<UserPostProps> = memo(({ username }) => {
271287 ) ) }
272288 </ div >
273289 < div ref = { sentinel } className = "h-1" > </ div >
290+ < TopCommunitiesStatusBar topCommunities = { topCommunities } />
274291 </ div >
275292 </ div >
276293 ) ;
0 commit comments