Skip to content

Commit

Permalink
pass query from index.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
rotorsoft committed Oct 17, 2024
1 parent 163e9c2 commit 29cc12f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
29 changes: 11 additions & 18 deletions packages/commonwealth/client/scripts/views/components/feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,11 @@ import { useFetchCustomDomainQuery } from 'state/api/configuration';
import { useRefreshMembershipQuery } from 'state/api/groups';
import useUserStore from 'state/ui/user';
import Permissions from 'utils/Permissions';
import { DashboardViews } from 'views/pages/user_dashboard';
import { z } from 'zod';
import { PageNotFound } from '../pages/404';
import { ThreadCard } from '../pages/discussions/ThreadCard';
import { UserDashboardRowSkeleton } from '../pages/user_dashboard/user_dashboard_row';

type FeedProps = {
dashboardView: DashboardViews;
noFeedMessage: string;
defaultCount?: number;
customScrollParent?: HTMLElement;
};

const DEFAULT_COUNT = 10;

const FeedThread = ({ thread }: { thread: Thread }) => {
Expand Down Expand Up @@ -180,16 +172,15 @@ function mapThread(thread: z.infer<typeof ActivityThread>): Thread {
});
}

// eslint-disable-next-line react/no-multi-comp
export const Feed = ({
dashboardView,
noFeedMessage,
customScrollParent,
}: FeedProps) => {
const userFeed = useFetchUserActivityQuery();
const globalFeed = useFetchGlobalActivityQuery();
type FeedProps = {
query: typeof useFetchGlobalActivityQuery | typeof useFetchUserActivityQuery;
defaultCount?: number;
customScrollParent?: HTMLElement;
};

const feed = dashboardView === DashboardViews.Global ? globalFeed : userFeed;
// eslint-disable-next-line react/no-multi-comp
export const Feed = ({ query, customScrollParent }: FeedProps) => {
const feed = query();

if (feed.isLoading) {
return (
Expand All @@ -211,7 +202,9 @@ export const Feed = ({
if (feed.data.length === 0) {
return (
<div className="Feed">
<div className="no-feed-message">{noFeedMessage}</div>
<div className="no-feed-message">
Join some communities to see Activity!
</div>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
useFetchGlobalActivityQuery,
useFetchUserActivityQuery,
} from 'client/scripts/state/api/feeds/fetchUserActivity';
import { notifyInfo } from 'controllers/app/notifications';
import { useBrowserAnalyticsTrack } from 'hooks/useBrowserAnalyticsTrack';
import useBrowserWindow from 'hooks/useBrowserWindow';
Expand Down Expand Up @@ -123,11 +127,17 @@ const UserDashboard = ({ type }: UserDashboardProps) => {
/>
</CWTabsRow>
</div>
<Feed
dashboardView={activePage}
noFeedMessage="Join some communities to see Activity!"
customScrollParent={scrollElement!}
/>
{activePage === DashboardViews.Global ? (
<Feed
query={useFetchGlobalActivityQuery}
customScrollParent={scrollElement!}
/>
) : (
<Feed
query={useFetchUserActivityQuery}
customScrollParent={scrollElement!}
/>
)}
</div>
{isWindowExtraSmall ? (
<>
Expand Down

0 comments on commit 29cc12f

Please sign in to comment.