Skip to content

Commit

Permalink
Merge pull request #9580 from hicommonwealth/rotorsoft/9579-pass-quer…
Browse files Browse the repository at this point in the history
…y-from-index

Pass query from index.tsx to avoid invoking a secure API when user is logged off
  • Loading branch information
Rotorsoft authored Oct 17, 2024
2 parents 93ca306 + 29cc12f commit fd02a14
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 @@ -27,17 +27,9 @@ import {
} from 'state/api/feeds/fetchUserActivity';
import useUserStore from 'state/ui/user';
import Permissions from 'utils/Permissions';
import { DashboardViews } from 'views/pages/user_dashboard';
import { z } from 'zod';
import { ThreadCard } from '../pages/discussions/ThreadCard';

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

const DEFAULT_COUNT = 10;

const FeedThread = ({ thread }: { thread: Thread }) => {
Expand Down Expand Up @@ -189,16 +181,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 @@ -220,7 +211,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 fd02a14

Please sign in to comment.