Skip to content

Commit

Permalink
showOnlyFollowing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
artlu99 committed Jul 3, 2024
1 parent b99a274 commit 9b719f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/api/forYouFeed.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ export const getNeynarOpenrankForYouFeed = (forYouFeedRequestPayload: ForYouFeed
interface EnhancedForYouFeedRequest {
fid: number;
cursor?: string;
following: number[];
powerBadgeUsers: number[];
allChannels: ChannelObject[];
}
export const getEnhancedForYouFeed = async (
homeFeedRequestPayload: EnhancedForYouFeedRequest,
): Promise<PagedCronFeed> => {
const { fid, cursor, powerBadgeUsers, allChannels } = homeFeedRequestPayload;
const { fid, cursor, following, powerBadgeUsers, allChannels } = homeFeedRequestPayload;

const forYouFeed = await getNeynarOpenrankForYouFeed({ fid: fid, limit: FORYOU_FEED_PAGESIZE, cursor });
const seenFids = sift(forYouFeed.casts.map((cast) => cast.author.fid).filter((fid) => fid !== null));
Expand All @@ -39,7 +40,7 @@ export const getEnhancedForYouFeed = async (
...forYouFeed,
casts: forYouFeed.casts.map((castObject) => ({
...castObject,
amFollowing: true,
amFollowing: following.find((fid) => fid === castObject.author.fid) !== undefined,

authorHasPowerBadge: powerBadgeUsers.find((fid) => fid === castObject.author.fid) !== undefined,
botOrNotResult: botOrNotResponse.fids.find((fid) => fid.fid === castObject.author.fid)?.result ?? {
Expand Down
8 changes: 8 additions & 0 deletions src/components/apps/forYouFeed/ForYouFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const ForYouFeed: React.FC<ForYouFeedProps> = ({ fid }) => {
const [loaded, setLoaded] = useState<boolean>(false);
const {
setNumCasts,
setNumFollowingCasts,
setNumCuratedChannelsCasts,
setNumFarcaptchas,
setNumUpvotes,
Expand All @@ -33,6 +34,7 @@ export const ForYouFeed: React.FC<ForYouFeedProps> = ({ fid }) => {
} = useZustand();

const signalToNoiseState = useAppSelector((state) => state.signalToNoise);
const showOnlyFollowing = signalToNoiseState.showOnlyFollowing;
const showOnlyCuratedChannels = signalToNoiseState.showOnlyCuratedChannels;
const showOnlyFarcaptcha = signalToNoiseState.showOnlyFarcaptcha;
const onlyShowUpvoted = signalToNoiseState.onlyShowUpvoted;
Expand Down Expand Up @@ -68,6 +70,7 @@ export const ForYouFeed: React.FC<ForYouFeedProps> = ({ fid }) => {

getEnhancedForYouFeed({
fid: fid,
following: memodFfData ?? [],
powerBadgeUsers: allPowerBadgeUsers,
allChannels: memodChannelData ?? [],
})
Expand All @@ -83,6 +86,7 @@ export const ForYouFeed: React.FC<ForYouFeedProps> = ({ fid }) => {

useEffect(() => {
setNumCasts(casts.length);
setNumFollowingCasts(casts.filter((c) => c.amFollowing).length);
setNumCuratedChannelsCasts(casts.filter((c) => c.tags.length > 1).length);
setNumFarcaptchas(casts.filter((c) => c.botOrNotResult.farcaptcha).length);
setNumUpvotes(casts.reduce((acc, c) => acc + c.curation.upvotes.length, 0));
Expand All @@ -96,6 +100,7 @@ export const ForYouFeed: React.FC<ForYouFeedProps> = ({ fid }) => {
casts,
ratioThreshold,
setNumCasts,
setNumFollowingCasts,
setNumCuratedChannelsCasts,
setNumCastsAboveThreshold,
setNumCastsWithDownvotes,
Expand All @@ -109,6 +114,7 @@ export const ForYouFeed: React.FC<ForYouFeedProps> = ({ fid }) => {
getEnhancedForYouFeed({
fid: fid,
cursor: nextCursor,
following: memodFfData ?? [],
powerBadgeUsers: allPowerBadgeUsers,
allChannels: memodChannelData ?? [],
}).then((newCasts) => {
Expand All @@ -118,6 +124,7 @@ export const ForYouFeed: React.FC<ForYouFeedProps> = ({ fid }) => {

const filteredCastsList = useMemo(() => {
const filteredCasts = casts
.filter((c) => !showOnlyFollowing || c.amFollowing)
.filter((c) => !showOnlyCuratedChannels || c.tags.length > 1)
.filter((c) => !showOnlyFarcaptcha || c.botOrNotResult.farcaptcha)
.filter((c) => !onlyShowUpvoted || c.curation.upvotes.length > 0)
Expand Down Expand Up @@ -162,6 +169,7 @@ export const ForYouFeed: React.FC<ForYouFeedProps> = ({ fid }) => {
}, [
casts,
setNumCastsAfterFiltering,
showOnlyFollowing,
showOnlyCuratedChannels,
showOnlyFarcaptcha,
onlyShowUpvoted,
Expand Down

0 comments on commit 9b719f4

Please sign in to comment.