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