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