Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove unwanted hasMore state to prevent re-rendering #1905

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/web/src/components/Comment/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { SCROLL_THRESHOLD } from 'data/constants';
import type { Comment, Publication, PublicationsQueryRequest } from 'lens';
import { CommentOrderingTypes, CommentRankingFilter, CustomFiltersTypes, useCommentFeedQuery } from 'lens';
import type { FC } from 'react';
import { useState } from 'react';
import InfiniteScroll from 'react-infinite-scroll-component';
import { useAppStore } from 'src/store/app';
import { useTransactionPersistStore } from 'src/store/transaction';

import NewPublication from '../Composer/NewPublication';
import CommentWarning from '../Shared/CommentWarning';

let hasMore = true;

interface Props {
publication?: Publication;
}
Expand All @@ -27,7 +28,6 @@ const Feed: FC<Props> = ({ publication }) => {
const publicationId = publication?.__typename === 'Mirror' ? publication?.mirrorOf?.id : publication?.id;
const currentProfile = useAppStore((state) => state.currentProfile);
const txnQueue = useTransactionPersistStore((state) => state.txnQueue);
const [hasMore, setHasMore] = useState(true);

// Variables
const request: PublicationsQueryRequest = {
Expand Down Expand Up @@ -56,7 +56,7 @@ const Feed: FC<Props> = ({ publication }) => {
await fetchMore({
variables: { request: { ...request, cursor: pageInfo?.next }, reactionRequest, profileId }
}).then(({ data }) => {
setHasMore(data?.publications?.items?.length > 0);
hasMore = data?.publications?.items?.length > 0;
});
};

Expand Down
5 changes: 3 additions & 2 deletions apps/web/src/components/Comment/NoneRelevantFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import { useState } from 'react';
import InfiniteScroll from 'react-infinite-scroll-component';
import { useAppStore } from 'src/store/app';

let hasMore = true;

interface Props {
publication?: Publication;
}

const NoneRelevantFeed: FC<Props> = ({ publication }) => {
const publicationId = publication?.__typename === 'Mirror' ? publication?.mirrorOf?.id : publication?.id;
const currentProfile = useAppStore((state) => state.currentProfile);
const [hasMore, setHasMore] = useState(true);
const [showMore, setShowMore] = useState(false);

// Variables
Expand Down Expand Up @@ -45,7 +46,7 @@ const NoneRelevantFeed: FC<Props> = ({ publication }) => {
await fetchMore({
variables: { request: { ...request, cursor: pageInfo?.next }, reactionRequest, profileId }
}).then(({ data }) => {
setHasMore(data?.publications?.items?.length > 0);
hasMore = data?.publications?.items?.length > 0;
});
};

Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/Explore/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import { SCROLL_THRESHOLD } from 'data/constants';
import type { ExplorePublicationRequest, Publication, PublicationMainFocus } from 'lens';
import { CustomFiltersTypes, PublicationSortCriteria, useExploreFeedQuery } from 'lens';
import type { FC } from 'react';
import { useState } from 'react';
import InfiniteScroll from 'react-infinite-scroll-component';
import { useAppStore } from 'src/store/app';

let hasMore = true;

interface Props {
focus?: PublicationMainFocus;
feedType?: PublicationSortCriteria;
}

const Feed: FC<Props> = ({ focus, feedType = PublicationSortCriteria.CuratedProfiles }) => {
const currentProfile = useAppStore((state) => state.currentProfile);
const [hasMore, setHasMore] = useState(true);

// Variables
const request: ExplorePublicationRequest = {
Expand All @@ -45,7 +45,7 @@ const Feed: FC<Props> = ({ focus, feedType = PublicationSortCriteria.CuratedProf
await fetchMore({
variables: { request: { ...request, cursor: pageInfo?.next }, reactionRequest, profileId }
}).then(({ data }) => {
setHasMore(data?.explorePublications?.items?.length > 0);
hasMore = data?.explorePublications?.items?.length > 0;
});
};

Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/Home/Highlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import { SCROLL_THRESHOLD } from 'data/constants';
import type { FeedHighlightsRequest, Publication } from 'lens';
import { useFeedHighlightsQuery } from 'lens';
import type { FC } from 'react';
import { useState } from 'react';
import InfiniteScroll from 'react-infinite-scroll-component';
import { useAppStore } from 'src/store/app';
import { useTransactionPersistStore } from 'src/store/transaction';

let hasMore = true;

const Highlights: FC = () => {
const currentProfile = useAppStore((state) => state.currentProfile);
const txnQueue = useTransactionPersistStore((state) => state.txnQueue);
const [hasMore, setHasMore] = useState(true);

// Variables
const request: FeedHighlightsRequest = { profileId: currentProfile?.id, limit: 10 };
Expand All @@ -37,7 +37,7 @@ const Highlights: FC = () => {
await fetchMore({
variables: { request: { ...request, cursor: pageInfo?.next }, reactionRequest, profileId }
}).then(({ data }) => {
setHasMore(data?.feedHighlights?.items?.length > 0);
hasMore = data?.feedHighlights?.items?.length > 0;
});
};

Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/Home/Timeline/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import { SCROLL_THRESHOLD } from 'data/constants';
import type { FeedItem, FeedRequest, Publication } from 'lens';
import { FeedEventItemType, useTimelineQuery } from 'lens';
import type { FC } from 'react';
import { useState } from 'react';
import InfiniteScroll from 'react-infinite-scroll-component';
import { useAppStore } from 'src/store/app';
import { useTimelinePersistStore, useTimelineStore } from 'src/store/timeline';
import { useTransactionPersistStore } from 'src/store/transaction';

let hasMore = true;

const Timeline: FC = () => {
const currentProfile = useAppStore((state) => state.currentProfile);
const txnQueue = useTransactionPersistStore((state) => state.txnQueue);
const feedEventFilters = useTimelinePersistStore((state) => state.feedEventFilters);
const seeThroughProfile = useTimelineStore((state) => state.seeThroughProfile);
const [hasMore, setHasMore] = useState(true);

const getFeedEventItems = () => {
const filters: FeedEventItemType[] = [];
Expand Down Expand Up @@ -57,7 +57,7 @@ const Timeline: FC = () => {
await fetchMore({
variables: { request: { ...request, cursor: pageInfo?.next }, reactionRequest, profileId }
}).then(({ data }) => {
setHasMore(data?.feed?.items?.length > 0);
hasMore = data?.feed?.items?.length > 0;
});
};

Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/Mod/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { SCROLL_THRESHOLD } from 'data/constants';
import type { ExplorePublicationRequest, Publication } from 'lens';
import { PublicationSortCriteria, PublicationTypes, useExploreFeedQuery } from 'lens';
import type { FC } from 'react';
import { useState } from 'react';
import InfiniteScroll from 'react-infinite-scroll-component';
import { useAppStore } from 'src/store/app';

let hasMore = true;

const Feed: FC = () => {
const currentProfile = useAppStore((state) => state.currentProfile);
const [hasMore, setHasMore] = useState(true);

// Variables
const request: ExplorePublicationRequest = {
Expand All @@ -39,7 +39,7 @@ const Feed: FC = () => {
await fetchMore({
variables: { request: { ...request, cursor: pageInfo?.next }, reactionRequest, profileId }
}).then(({ data }) => {
setHasMore(data?.explorePublications?.items?.length > 0);
hasMore = data?.explorePublications?.items?.length > 0;
});
};

Expand Down
7 changes: 3 additions & 4 deletions apps/web/src/components/NFT/NFTFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ import { IS_MAINNET, SCROLL_THRESHOLD } from 'data/constants';
import type { Nft, NfTsRequest, Profile } from 'lens';
import { useNftFeedQuery } from 'lens';
import type { FC } from 'react';
import { useState } from 'react';
import InfiniteScroll from 'react-infinite-scroll-component';
import { CHAIN_ID } from 'src/constants';
import { mainnet } from 'wagmi/chains';

let hasMore = true;

interface Props {
profile: Profile;
}

const NFTFeed: FC<Props> = ({ profile }) => {
const [hasMore, setHasMore] = useState(true);

// Variables
const request: NfTsRequest = {
chainIds: IS_MAINNET ? [CHAIN_ID, mainnet.id] : [CHAIN_ID],
Expand All @@ -41,7 +40,7 @@ const NFTFeed: FC<Props> = ({ profile }) => {
await fetchMore({
variables: { request: { ...request, cursor: pageInfo?.next } }
}).then(({ data }) => {
setHasMore(data?.nfts?.items?.length > 0);
hasMore = data?.nfts?.items?.length > 0;
});
};

Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/Notification/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import type {
} from 'lens';
import { CustomFiltersTypes, NotificationTypes, useNotificationsQuery } from 'lens';
import type { FC } from 'react';
import { useState } from 'react';
import InfiniteScroll from 'react-infinite-scroll-component';
import { useAppStore } from 'src/store/app';

Expand All @@ -36,13 +35,14 @@ export enum NotificationType {
Collects = 'COLLECTS'
}

let hasMore = true;

interface Props {
feedType: string;
}

const List: FC<Props> = ({ feedType }) => {
const currentProfile = useAppStore((state) => state.currentProfile);
const [hasMore, setHasMore] = useState(true);

const getNotificationType = () => {
switch (feedType) {
Expand Down Expand Up @@ -80,7 +80,7 @@ const List: FC<Props> = ({ feedType }) => {
await fetchMore({
variables: { request: { ...request, cursor: pageInfo?.next } }
}).then(({ data }) => {
setHasMore(data?.notifications?.items?.length > 0);
hasMore = data?.notifications?.items?.length > 0;
});
};

Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/Profile/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { SCROLL_THRESHOLD } from 'data/constants';
import type { Profile, Publication, PublicationsQueryRequest } from 'lens';
import { PublicationMainFocus, PublicationTypes, useProfileFeedQuery } from 'lens';
import type { FC } from 'react';
import { useState } from 'react';
import InfiniteScroll from 'react-infinite-scroll-component';
import { useAppStore } from 'src/store/app';
import { useProfileFeedStore } from 'src/store/profile-feed';
Expand All @@ -24,6 +23,8 @@ export enum ProfileFeedType {
Nft = 'NFT'
}

let hasMore = true;

interface Props {
profile: Profile;
type: ProfileFeedType.Feed | ProfileFeedType.Replies | ProfileFeedType.Media | ProfileFeedType.Collects;
Expand All @@ -32,7 +33,6 @@ interface Props {
const Feed: FC<Props> = ({ profile, type }) => {
const currentProfile = useAppStore((state) => state.currentProfile);
const mediaFeedFilters = useProfileFeedStore((state) => state.mediaFeedFilters);
const [hasMore, setHasMore] = useState(true);

const getMediaFilters = () => {
let filters: PublicationMainFocus[] = [];
Expand Down Expand Up @@ -84,7 +84,7 @@ const Feed: FC<Props> = ({ profile, type }) => {
await fetchMore({
variables: { request: { ...request, cursor: pageInfo?.next }, reactionRequest, profileId }
}).then(({ data }) => {
setHasMore(data?.publications?.items?.length > 0);
hasMore = data?.publications?.items?.length > 0;
});
};

Expand Down
7 changes: 3 additions & 4 deletions apps/web/src/components/Profile/Followers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ import { SCROLL_THRESHOLD } from 'data/constants';
import type { FollowersRequest, Profile, Wallet } from 'lens';
import { useFollowersQuery } from 'lens';
import type { FC } from 'react';
import { useState } from 'react';
import InfiniteScroll from 'react-infinite-scroll-component';

let hasMore = true;

interface Props {
profile: Profile;
}

const Followers: FC<Props> = ({ profile }) => {
const [hasMore, setHasMore] = useState(true);

// Variables
const request: FollowersRequest = { profileId: profile?.id, limit: 10 };

Expand All @@ -37,7 +36,7 @@ const Followers: FC<Props> = ({ profile }) => {
await fetchMore({
variables: { request: { ...request, cursor: pageInfo?.next } }
}).then(({ data }) => {
setHasMore(data?.followers?.items?.length > 0);
hasMore = data?.followers?.items?.length > 0;
});
};

Expand Down
7 changes: 3 additions & 4 deletions apps/web/src/components/Profile/Following.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ import { SCROLL_THRESHOLD } from 'data/constants';
import type { FollowingRequest, Profile } from 'lens';
import { useFollowingQuery } from 'lens';
import type { FC } from 'react';
import { useState } from 'react';
import InfiniteScroll from 'react-infinite-scroll-component';

let hasMore = true;

interface Props {
profile: Profile;
onProfileSelected?: (profile: Profile) => void;
}

const Following: FC<Props> = ({ profile, onProfileSelected }) => {
const [hasMore, setHasMore] = useState(true);

// Variables
const request: FollowingRequest = { address: profile?.ownedBy, limit: 10 };

Expand All @@ -37,7 +36,7 @@ const Following: FC<Props> = ({ profile, onProfileSelected }) => {
await fetchMore({
variables: { request: { ...request, cursor: pageInfo?.next } }
}).then(({ data }) => {
setHasMore(data?.following?.items?.length > 0);
hasMore = data?.following?.items?.length > 0;
});
};

Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/Profile/MutualFollowers/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import { SCROLL_THRESHOLD } from 'data/constants';
import type { MutualFollowersProfilesQueryRequest, Profile } from 'lens';
import { useMutualFollowersListQuery } from 'lens';
import type { FC } from 'react';
import { useState } from 'react';
import InfiniteScroll from 'react-infinite-scroll-component';
import { useAppStore } from 'src/store/app';

let hasMore = true;

interface Props {
profileId: string;
}

const MutualFollowersList: FC<Props> = ({ profileId }) => {
const currentProfile = useAppStore((state) => state.currentProfile);
const [hasMore, setHasMore] = useState(true);

// Variables
const request: MutualFollowersProfilesQueryRequest = {
Expand All @@ -39,7 +39,7 @@ const MutualFollowersList: FC<Props> = ({ profileId }) => {
await fetchMore({
variables: { request: { ...request, cursor: pageInfo?.next } }
}).then(({ data }) => {
setHasMore(data?.mutualFollowersProfiles?.items?.length > 0);
hasMore = data?.mutualFollowersProfiles?.items?.length > 0;
});
};

Expand Down
7 changes: 4 additions & 3 deletions apps/web/src/components/Profile/NftGallery/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IS_MAINNET, SCROLL_THRESHOLD } from 'data/constants';
import type { Nft, NfTsRequest } from 'lens';
import { useNftFeedQuery } from 'lens';
import type { FC } from 'react';
import React, { useState } from 'react';
import React from 'react';
import { toast } from 'react-hot-toast';
import InfiniteScroll from 'react-infinite-scroll-component';
import { CHAIN_ID } from 'src/constants';
Expand All @@ -20,11 +20,12 @@ import type { NftGalleryItem } from 'src/store/nft-gallery';
import { useNftGalleryStore } from 'src/store/nft-gallery';
import { mainnet } from 'wagmi/chains';

let hasMore = true;

const Picker: FC = () => {
const currentProfile = useAppStore((state) => state.currentProfile);
const gallery = useNftGalleryStore((state) => state.gallery);
const setGallery = useNftGalleryStore((state) => state.setGallery);
const [hasMore, setHasMore] = useState(true);

// Variables
const request: NfTsRequest = {
Expand All @@ -45,7 +46,7 @@ const Picker: FC = () => {
await fetchMore({
variables: { request: { ...request, cursor: pageInfo?.next } }
}).then(({ data }) => {
setHasMore(data?.nfts?.items?.length > 0);
hasMore = data?.nfts?.items?.length > 0;
});
};

Expand Down
Loading