update pinned feed from custom feed view

zio/stable
Ansh Nanda 2023-05-22 20:07:40 -07:00
parent 8a2349c55f
commit 52a8879754
2 changed files with 48 additions and 14 deletions

View File

@ -129,8 +129,14 @@ export class SavedFeedsModel {
) )
} }
isPinned(feed: CustomFeedModel) { isPinned(feedOrUri: CustomFeedModel | string) {
return this.rootStore.preferences.pinnedFeeds.includes(feed.uri) 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') { async movePinnedFeed(item: CustomFeedModel, direction: 'up' | 'down') {

View File

@ -24,7 +24,7 @@ import {isDesktopWeb} from 'platform/detection'
import {useSetTitle} from 'lib/hooks/useSetTitle' import {useSetTitle} from 'lib/hooks/useSetTitle'
import {shareUrl} from 'lib/sharing' import {shareUrl} from 'lib/sharing'
import {toShareUrl} from 'lib/strings/url-helpers' 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} const HITSLOP = {top: 5, left: 5, bottom: 5, right: 5}
@ -47,6 +47,7 @@ export const CustomFeedScreen = withAuthRequired(
feed.setup() feed.setup()
return feed return feed
}, [store, uri]) }, [store, uri])
const isPinned = store.me.savedFeeds.isPinned(uri)
useSetTitle(currentFeed?.displayName) useSetTitle(currentFeed?.displayName)
@ -65,7 +66,6 @@ export const CustomFeedScreen = withAuthRequired(
store.log.error('Failed up update feeds', {err}) store.log.error('Failed up update feeds', {err})
} }
}, [store, currentFeed]) }, [store, currentFeed])
const onToggleLiked = React.useCallback(async () => { const onToggleLiked = React.useCallback(async () => {
Haptics.default() Haptics.default()
try { try {
@ -81,6 +81,13 @@ export const CustomFeedScreen = withAuthRequired(
store.log.error('Failed up toggle like', {err}) store.log.error('Failed up toggle like', {err})
} }
}, [store, currentFeed]) }, [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 onPressShare = React.useCallback(() => {
const url = toShareUrl(`/profile/${name}/feed/${rkey}`) const url = toShareUrl(`/profile/${name}/feed/${rkey}`)
shareUrl(url) shareUrl(url)
@ -212,15 +219,30 @@ export const CustomFeedScreen = withAuthRequired(
{currentFeed.data.description} {currentFeed.data.description}
</Text> </Text>
) : null} ) : null}
<TextLink <View style={styles.headerDetailsFooter}>
type="md-medium" <TextLink
style={pal.textLight} type="md-medium"
href={`/profile/${name}/feed/${rkey}/liked-by`} style={pal.textLight}
text={`Liked by ${currentFeed?.data.likeCount} ${pluralize( href={`/profile/${name}/feed/${rkey}/liked-by`}
currentFeed?.data.likeCount || 0, text={`Liked by ${currentFeed?.data.likeCount} ${pluralize(
'user', 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>
<View style={[styles.fakeSelector, pal.border]}> <View style={[styles.fakeSelector, pal.border]}>
<View <View
@ -241,6 +263,7 @@ export const CustomFeedScreen = withAuthRequired(
onPressShare, onPressShare,
name, name,
rkey, rkey,
isPinned,
]) ])
return ( return (
@ -250,7 +273,7 @@ export const CustomFeedScreen = withAuthRequired(
scrollElRef={scrollElRef} scrollElRef={scrollElRef}
feed={algoFeed} feed={algoFeed}
ListHeaderComponent={renderListHeaderComponent} ListHeaderComponent={renderListHeaderComponent}
extraData={uri} extraData={[uri, isPinned]}
/> />
</View> </View>
) )
@ -275,6 +298,11 @@ const styles = StyleSheet.create({
paddingHorizontal: 16, paddingHorizontal: 16,
paddingBottom: 16, paddingBottom: 16,
}, },
headerDetailsFooter: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
},
fakeSelector: { fakeSelector: {
flexDirection: 'row', flexDirection: 'row',
paddingHorizontal: isDesktopWeb ? 16 : 6, paddingHorizontal: isDesktopWeb ? 16 : 6,