forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import React from 'react'
2import {View} from 'react-native'
3import {msg, Trans} from '@lingui/macro'
4import {useLingui} from '@lingui/react'
5
6import {PROD_DEFAULT_FEED} from '#/lib/constants'
7import {logger} from '#/logger'
8import {
9 usePreferencesQuery,
10 useRemoveFeedMutation,
11 useReplaceForYouWithDiscoverFeedMutation,
12} from '#/state/queries/preferences'
13import {useSetSelectedFeed} from '#/state/shell/selected-feed'
14import * as Toast from '#/view/com/util/Toast'
15import {atoms as a, useTheme} from '#/alf'
16import {Button, ButtonIcon, ButtonText} from '#/components/Button'
17import {InlineLinkText} from '#/components/Link'
18import {Loader} from '#/components/Loader'
19import {Text} from '#/components/Typography'
20
21export function FeedShutdownMsg({feedUri}: {feedUri: string}) {
22 const t = useTheme()
23 const {_} = useLingui()
24 const setSelectedFeed = useSetSelectedFeed()
25 const {data: preferences} = usePreferencesQuery()
26 const {mutateAsync: removeFeed, isPending: isRemovePending} =
27 useRemoveFeedMutation()
28 const {mutateAsync: replaceFeedWithDiscover, isPending: isReplacePending} =
29 useReplaceForYouWithDiscoverFeedMutation()
30
31 const feedConfig = preferences?.savedFeeds?.find(
32 f => f.value === feedUri && f.pinned,
33 )
34 const discoverFeedConfig = preferences?.savedFeeds?.find(
35 f => f.value === PROD_DEFAULT_FEED('whats-hot'),
36 )
37 const hasFeedPinned = Boolean(feedConfig)
38 const hasDiscoverPinned = Boolean(discoverFeedConfig?.pinned)
39
40 const onRemoveFeed = React.useCallback(async () => {
41 try {
42 if (feedConfig) {
43 await removeFeed(feedConfig)
44 Toast.show(_(msg`Removed from your feeds`))
45 }
46 if (hasDiscoverPinned) {
47 setSelectedFeed(`feedgen|${PROD_DEFAULT_FEED('whats-hot')}`)
48 }
49 } catch (err: any) {
50 Toast.show(
51 _(
52 msg`There was an issue updating your feeds, please check your internet connection and try again.`,
53 ),
54 'exclamation-circle',
55 )
56 logger.error('Failed to update feeds', {message: err})
57 }
58 }, [removeFeed, feedConfig, _, hasDiscoverPinned, setSelectedFeed])
59
60 const onReplaceFeed = React.useCallback(async () => {
61 try {
62 await replaceFeedWithDiscover({
63 forYouFeedConfig: feedConfig,
64 discoverFeedConfig,
65 })
66 setSelectedFeed(`feedgen|${PROD_DEFAULT_FEED('whats-hot')}`)
67 Toast.show(_(msg`The feed has been replaced with Discover.`))
68 } catch (err: any) {
69 Toast.show(
70 _(
71 msg`There was an issue updating your feeds, please check your internet connection and try again.`,
72 ),
73 'exclamation-circle',
74 )
75 logger.error('Failed to update feeds', {message: err})
76 }
77 }, [
78 replaceFeedWithDiscover,
79 discoverFeedConfig,
80 feedConfig,
81 setSelectedFeed,
82 _,
83 ])
84
85 const isProcessing = isReplacePending || isRemovePending
86 return (
87 <View
88 style={[
89 a.py_3xl,
90 a.px_2xl,
91 a.gap_xl,
92 t.atoms.border_contrast_low,
93 a.border_t,
94 ]}>
95 <Text style={[a.text_5xl, a.font_semi_bold, t.atoms.text, a.text_center]}>
96 :(
97 </Text>
98 <Text style={[a.text_md, a.leading_snug, t.atoms.text, a.text_center]}>
99 <Trans>
100 This feed is no longer online. We are showing{' '}
101 <InlineLinkText
102 label={_(msg`The Discover feed`)}
103 to="/profile/bsky.app/feed/whats-hot"
104 style={[a.text_md]}>
105 Discover
106 </InlineLinkText>{' '}
107 instead.
108 </Trans>
109 </Text>
110 {hasFeedPinned ? (
111 <View style={[a.flex_row, a.justify_center, a.gap_sm]}>
112 <Button
113 variant="outline"
114 color="primary"
115 size="small"
116 label={_(msg`Remove feed`)}
117 disabled={isProcessing}
118 onPress={onRemoveFeed}>
119 <ButtonText>
120 <Trans>Remove feed</Trans>
121 </ButtonText>
122 {isRemovePending && <ButtonIcon icon={Loader} />}
123 </Button>
124 {!hasDiscoverPinned && (
125 <Button
126 variant="solid"
127 color="primary"
128 size="small"
129 label={_(msg`Replace with Discover`)}
130 disabled={isProcessing}
131 onPress={onReplaceFeed}>
132 <ButtonText>
133 <Trans>Replace with Discover</Trans>
134 </ButtonText>
135 {isReplacePending && <ButtonIcon icon={Loader} />}
136 </Button>
137 )}
138 </View>
139 ) : undefined}
140 </View>
141 )
142}