diff options
author | Ansh Nanda <anshnanda10@gmail.com> | 2023-05-22 20:07:40 -0700 |
---|---|---|
committer | Ansh Nanda <anshnanda10@gmail.com> | 2023-05-22 20:07:40 -0700 |
commit | 52a8879754e07c3e0aa90a40fdc27dfdc40fd450 (patch) | |
tree | e2153a156c7e8e12d4f7d23c5fa81d87eb4498be /src | |
parent | 8a2349c55ffcff4f833c015f9b10296aa9d77738 (diff) | |
download | voidsky-52a8879754e07c3e0aa90a40fdc27dfdc40fd450.tar.zst |
update pinned feed from custom feed view
Diffstat (limited to 'src')
-rw-r--r-- | src/state/models/ui/saved-feeds.ts | 10 | ||||
-rw-r--r-- | src/view/screens/CustomFeed.tsx | 52 |
2 files changed, 48 insertions, 14 deletions
diff --git a/src/state/models/ui/saved-feeds.ts b/src/state/models/ui/saved-feeds.ts index 0d04f9c8d..244e75898 100644 --- a/src/state/models/ui/saved-feeds.ts +++ b/src/state/models/ui/saved-feeds.ts @@ -129,8 +129,14 @@ export class SavedFeedsModel { ) } - isPinned(feed: CustomFeedModel) { - return this.rootStore.preferences.pinnedFeeds.includes(feed.uri) + isPinned(feedOrUri: CustomFeedModel | string) { + let uri: string + if (typeof feedOrUri === 'string') { + uri = feedOrUri + } else { + uri = feedOrUri.uri + } + return this.rootStore.preferences.pinnedFeeds.includes(uri) } async movePinnedFeed(item: CustomFeedModel, direction: 'up' | 'down') { diff --git a/src/view/screens/CustomFeed.tsx b/src/view/screens/CustomFeed.tsx index 353995540..952461c9c 100644 --- a/src/view/screens/CustomFeed.tsx +++ b/src/view/screens/CustomFeed.tsx @@ -24,7 +24,7 @@ import {isDesktopWeb} from 'platform/detection' import {useSetTitle} from 'lib/hooks/useSetTitle' import {shareUrl} from 'lib/sharing' import {toShareUrl} from 'lib/strings/url-helpers' -import { Haptics } from 'lib/haptics' +import {Haptics} from 'lib/haptics' const HITSLOP = {top: 5, left: 5, bottom: 5, right: 5} @@ -47,6 +47,7 @@ export const CustomFeedScreen = withAuthRequired( feed.setup() return feed }, [store, uri]) + const isPinned = store.me.savedFeeds.isPinned(uri) useSetTitle(currentFeed?.displayName) @@ -65,7 +66,6 @@ export const CustomFeedScreen = withAuthRequired( store.log.error('Failed up update feeds', {err}) } }, [store, currentFeed]) - const onToggleLiked = React.useCallback(async () => { Haptics.default() try { @@ -81,6 +81,13 @@ export const CustomFeedScreen = withAuthRequired( store.log.error('Failed up toggle like', {err}) } }, [store, currentFeed]) + const onTogglePinned = React.useCallback(async () => { + Haptics.default() + store.me.savedFeeds.togglePinnedFeed(currentFeed!).catch(e => { + Toast.show('There was an issue contacting the server') + store.log.error('Failed to toggle pinned feed', {e}) + }) + }, [store, currentFeed]) const onPressShare = React.useCallback(() => { const url = toShareUrl(`/profile/${name}/feed/${rkey}`) shareUrl(url) @@ -212,15 +219,30 @@ export const CustomFeedScreen = withAuthRequired( {currentFeed.data.description} </Text> ) : null} - <TextLink - type="md-medium" - style={pal.textLight} - href={`/profile/${name}/feed/${rkey}/liked-by`} - text={`Liked by ${currentFeed?.data.likeCount} ${pluralize( - currentFeed?.data.likeCount || 0, - 'user', - )}`} - /> + <View style={styles.headerDetailsFooter}> + <TextLink + type="md-medium" + style={pal.textLight} + href={`/profile/${name}/feed/${rkey}/liked-by`} + text={`Liked by ${currentFeed?.data.likeCount} ${pluralize( + currentFeed?.data.likeCount || 0, + 'user', + )}`} + /> + <Button + type={'default'} + accessibilityLabel={ + isPinned ? 'Unpin this feed' : 'Pin this feed' + } + accessibilityHint="" + onPress={onTogglePinned}> + <FontAwesomeIcon + icon="thumb-tack" + size={20} + color={isPinned ? colors.blue3 : pal.colors.icon} + /> + </Button> + </View> </View> <View style={[styles.fakeSelector, pal.border]}> <View @@ -241,6 +263,7 @@ export const CustomFeedScreen = withAuthRequired( onPressShare, name, rkey, + isPinned, ]) return ( @@ -250,7 +273,7 @@ export const CustomFeedScreen = withAuthRequired( scrollElRef={scrollElRef} feed={algoFeed} ListHeaderComponent={renderListHeaderComponent} - extraData={uri} + extraData={[uri, isPinned]} /> </View> ) @@ -275,6 +298,11 @@ const styles = StyleSheet.create({ paddingHorizontal: 16, paddingBottom: 16, }, + headerDetailsFooter: { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'space-between', + }, fakeSelector: { flexDirection: 'row', paddingHorizontal: isDesktopWeb ? 16 : 6, |