From c4a666c2210c2e9c14812ddc5a0f797dd538014c Mon Sep 17 00:00:00 2001 From: Ansh Nanda Date: Mon, 15 May 2023 17:59:36 -0700 Subject: [PATCH] new design for custom feed preview --- src/lib/icons.tsx | 4 +- src/lib/routes/types.ts | 2 +- src/state/models/feeds/algo/algo-item.ts | 77 +++++++++++++---- src/view/com/algos/AlgoItem.tsx | 18 ++-- src/view/com/algos/useCustomFeed.ts | 27 ++++++ src/view/com/util/PostCtrls.tsx | 2 +- src/view/screens/CustomFeed.tsx | 103 +++++++++++++++++++++-- 7 files changed, 199 insertions(+), 34 deletions(-) create mode 100644 src/view/com/algos/useCustomFeed.ts diff --git a/src/lib/icons.tsx b/src/lib/icons.tsx index 4cb491e4..960090ad 100644 --- a/src/lib/icons.tsx +++ b/src/lib/icons.tsx @@ -443,7 +443,7 @@ export function HeartIcon({ size = 24, strokeWidth = 1.5, }: { - style?: StyleProp + style?: StyleProp size?: string | number strokeWidth: number }) { @@ -464,7 +464,7 @@ export function HeartIconSolid({ style, size = 24, }: { - style?: StyleProp + style?: StyleProp size?: string | number }) { return ( diff --git a/src/lib/routes/types.ts b/src/lib/routes/types.ts index 29fadd70..77ed58cc 100644 --- a/src/lib/routes/types.ts +++ b/src/lib/routes/types.ts @@ -21,7 +21,7 @@ export type CommonNavigatorParams = { CopyrightPolicy: undefined AppPasswords: undefined SavedFeeds: undefined - CustomFeed: {name: string; rkey: string} + CustomFeed: {name?: string; rkey: string} MutedAccounts: undefined BlockedAccounts: undefined } diff --git a/src/state/models/feeds/algo/algo-item.ts b/src/state/models/feeds/algo/algo-item.ts index 3dee5e2b..41fe6a97 100644 --- a/src/state/models/feeds/algo/algo-item.ts +++ b/src/state/models/feeds/algo/algo-item.ts @@ -33,6 +33,20 @@ export class AlgoItemModel { return this.data.uri } + get isSaved() { + return this.data.viewer?.saved + } + + get isLiked() { + return this.data.viewer?.liked + } + + set toggleLiked(value: boolean) { + if (this.data.viewer) { + this.data.viewer.liked = value + } + } + // public apis // = async save() { @@ -57,19 +71,52 @@ export class AlgoItemModel { } } - // async getFeedSkeleton() { - // const res = await this.rootStore.agent.app.bsky.feed.getFeedSkeleton({ - // feed: this.data.uri, - // }) - // const skeleton = res.data.feed - // console.log('skeleton', skeleton) - // return skeleton - // } - // async getFeed() { - // const feed = await this.rootStore.agent.app.bsky.feed.getFeed({ - // feed: this.data.uri, - // }) - // console.log('feed', feed) - // return feed - // } + async like() { + try { + this.toggleLiked = true + await this.rootStore.agent.app.bsky.feed.like.create( + { + repo: this.rootStore.me.did, + }, + { + subject: { + uri: this.data.uri, + cid: this.data.cid, + }, + createdAt: new Date().toString(), + }, + ) + } catch (e: any) { + this.rootStore.log.error('Failed to like feed', e) + } + } + + static async getView(store: RootStoreModel, uri: string) { + const res = await store.agent.app.bsky.feed.getFeedGenerator({ + feed: uri, + }) + const view = res.data.view + return view + } + + async checkIsValid() { + const res = await this.rootStore.agent.app.bsky.feed.getFeedGenerator({ + feed: this.data.uri, + }) + return res.data.isValid + } + + async checkIsOnline() { + const res = await this.rootStore.agent.app.bsky.feed.getFeedGenerator({ + feed: this.data.uri, + }) + return res.data.isOnline + } + + async reload() { + const res = await this.rootStore.agent.app.bsky.feed.getFeedGenerator({ + feed: this.data.uri, + }) + this.data = res.data.view + } } diff --git a/src/view/com/algos/AlgoItem.tsx b/src/view/com/algos/AlgoItem.tsx index 04117e58..f2fb075d 100644 --- a/src/view/com/algos/AlgoItem.tsx +++ b/src/view/com/algos/AlgoItem.tsx @@ -29,7 +29,7 @@ const AlgoItem = observer( style={[styles.container, style]} onPress={() => { navigation.navigate('CustomFeed', { - name: item.data.creator.did, + name: item.data.displayName, rkey: item.data.uri, }) }} @@ -40,25 +40,27 @@ const AlgoItem = observer( - {item.data.displayName ? item.data.displayName : 'Feed name'} + {item.data.displayName ?? 'Feed name'} - {item.data.description ?? - 'THIS IS A FEED DESCRIPTION, IT WILL TELL YOU WHAT THE FEED IS ABOUT. THIS IS A COOL FEED ABOUT COOL PEOPLE.'} + {item.data.description ?? 'Feed description'} - {/* TODO: this feed is like by *3* people UserAvatars and others */} - + {/* - + */} - Liked by 3 others + + {item.data.likeCount && item.data.likeCount > 1 + ? `Liked by ${item.data.likeCount} others` + : 'Be the first to like this'} +