mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at rn-stack-repro 110 lines 3.0 kB view raw
1import React from 'react' 2import {View, StyleSheet} from 'react-native' 3import {useNavigationState, useNavigation} from '@react-navigation/native' 4import {usePalette} from 'lib/hooks/usePalette' 5import {TextLink} from 'view/com/util/Link' 6import {getCurrentRoute} from 'lib/routes/helpers' 7import {useLingui} from '@lingui/react' 8import {msg} from '@lingui/macro' 9import {usePinnedFeedsInfos} from '#/state/queries/feed' 10import {useSelectedFeed, useSetSelectedFeed} from '#/state/shell/selected-feed' 11import {FeedDescriptor} from '#/state/queries/post-feed' 12import {NavigationProp} from 'lib/routes/types' 13import {emitSoftReset} from '#/state/events' 14 15export function DesktopFeeds() { 16 const pal = usePalette('default') 17 const {_} = useLingui() 18 const {data: pinnedFeedInfos} = usePinnedFeedsInfos() 19 const selectedFeed = useSelectedFeed() 20 const setSelectedFeed = useSetSelectedFeed() 21 const navigation = useNavigation<NavigationProp>() 22 const route = useNavigationState(state => { 23 if (!state) { 24 return {name: 'Home'} 25 } 26 return getCurrentRoute(state) 27 }) 28 if (!pinnedFeedInfos) { 29 return null 30 } 31 return ( 32 <View style={[styles.container, pal.view]}> 33 {pinnedFeedInfos.map(feedInfo => { 34 const uri = feedInfo.uri 35 let feed: FeedDescriptor 36 if (!uri) { 37 feed = 'home' 38 } else if (uri.includes('app.bsky.feed.generator')) { 39 feed = `feedgen|${uri}` 40 } else if (uri.includes('app.bsky.graph.list')) { 41 feed = `list|${uri}` 42 } else { 43 return null 44 } 45 return ( 46 <FeedItem 47 key={feed} 48 href={'/?' + new URLSearchParams([['feed', feed]])} 49 title={feedInfo.displayName} 50 current={route.name === 'Home' && feed === selectedFeed} 51 onPress={() => { 52 setSelectedFeed(feed) 53 navigation.navigate('Home') 54 if (feed === selectedFeed) { 55 emitSoftReset() 56 } 57 }} 58 /> 59 ) 60 })} 61 <View style={{paddingTop: 8, paddingBottom: 6}}> 62 <TextLink 63 type="lg" 64 href="/feeds" 65 text={_(msg`More feeds`)} 66 style={[pal.link]} 67 /> 68 </View> 69 </View> 70 ) 71} 72 73function FeedItem({ 74 title, 75 href, 76 current, 77 onPress, 78}: { 79 title: string 80 href: string 81 current: boolean 82 onPress: () => void 83}) { 84 const pal = usePalette('default') 85 return ( 86 <View style={{paddingVertical: 6}}> 87 <TextLink 88 type="xl" 89 href={href} 90 text={title} 91 onPress={onPress} 92 style={[ 93 current ? pal.text : pal.textLight, 94 {letterSpacing: 0.15, fontWeight: current ? '500' : 'normal'}, 95 ]} 96 /> 97 </View> 98 ) 99} 100 101const styles = StyleSheet.create({ 102 container: { 103 flex: 1, 104 // @ts-ignore web only -prf 105 overflowY: 'auto', 106 width: 300, 107 paddingHorizontal: 12, 108 paddingVertical: 18, 109 }, 110})