about summary refs log tree commit diff
path: root/src/view/com/feeds/MissingFeed.tsx
blob: 3d281a73162cf3441ca9be061afc2f854ea7ad26 (plain) (blame)
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import {type StyleProp, View, type ViewStyle} from 'react-native'
import {AtUri} from '@atproto/api'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'

import {cleanError} from '#/lib/strings/errors'
import {isNative, isWeb} from '#/platform/detection'
import {useModerationOpts} from '#/state/preferences/moderation-opts'
import {getFeedTypeFromUri} from '#/state/queries/feed'
import {useProfileQuery} from '#/state/queries/profile'
import {atoms as a, useTheme, web} from '#/alf'
import {Button, ButtonText} from '#/components/Button'
import * as Dialog from '#/components/Dialog'
import {Divider} from '#/components/Divider'
import {Warning_Stroke2_Corner0_Rounded as WarningIcon} from '#/components/icons/Warning'
import * as ProfileCard from '#/components/ProfileCard'
import {Text} from '#/components/Typography'

export function MissingFeed({
  style,
  hideTopBorder,
  uri,
  error,
}: {
  style?: StyleProp<ViewStyle>
  hideTopBorder?: boolean
  uri: string
  error?: unknown
}) {
  const t = useTheme()
  const {_} = useLingui()
  const control = Dialog.useDialogControl()

  const type = getFeedTypeFromUri(uri)

  return (
    <>
      <Button
        label={
          type === 'feed'
            ? _(msg`Could not connect to custom feed`)
            : _(msg`Deleted list`)
        }
        accessibilityHint={_(msg`Tap for more information`)}
        onPress={control.open}
        style={[
          a.flex_1,
          a.p_lg,
          a.gap_md,
          !hideTopBorder && !a.border_t,
          t.atoms.border_contrast_low,
          a.justify_start,
          style,
        ]}>
        <View style={[a.flex_row, a.align_center]}>
          <View
            style={[
              {width: 36, height: 36},
              t.atoms.bg_contrast_25,
              a.rounded_sm,
              a.mr_md,
              a.align_center,
              a.justify_center,
            ]}>
            <WarningIcon size="lg" />
          </View>
          <View style={[a.flex_1]}>
            <Text
              emoji
              style={[a.text_sm, a.font_bold, a.leading_snug, a.italic]}
              numberOfLines={1}>
              {type === 'feed' ? (
                <Trans>Feed unavailable</Trans>
              ) : (
                <Trans>Deleted list</Trans>
              )}
            </Text>
            <Text
              style={[
                a.text_sm,
                t.atoms.text_contrast_medium,
                a.leading_snug,
                a.italic,
              ]}
              numberOfLines={1}>
              {isWeb ? (
                <Trans>Click for information</Trans>
              ) : (
                <Trans>Tap for information</Trans>
              )}
            </Text>
          </View>
        </View>
      </Button>

      <Dialog.Outer control={control} nativeOptions={{preventExpansion: true}}>
        <Dialog.Handle />
        <DialogInner uri={uri} type={type} error={error} />
      </Dialog.Outer>
    </>
  )
}

function DialogInner({
  uri,
  type,
  error,
}: {
  uri: string
  type: 'feed' | 'list'
  error: unknown
}) {
  const control = Dialog.useDialogContext()
  const t = useTheme()
  const {_} = useLingui()
  const atUri = new AtUri(uri)
  const {data: profile, isError: isProfileError} = useProfileQuery({
    did: atUri.host,
  })
  const moderationOpts = useModerationOpts()

  return (
    <Dialog.ScrollableInner
      label={
        type === 'feed'
          ? _(msg`Unavailable feed information`)
          : _(msg`Deleted list`)
      }
      style={web({maxWidth: 500})}>
      <View style={[a.gap_sm]}>
        <Text style={[a.font_heavy, a.text_2xl]}>
          {type === 'feed' ? (
            <Trans>Could not connect to feed service</Trans>
          ) : (
            <Trans>Deleted list</Trans>
          )}
        </Text>
        <Text style={[t.atoms.text_contrast_high, a.leading_snug]}>
          {type === 'feed' ? (
            <Trans>
              We could not connect to the service that provides this custom
              feed. It may be temporarily unavailable and experiencing issues,
              or permanently unavailable.
            </Trans>
          ) : (
            <Trans>We could not find this list. It was probably deleted.</Trans>
          )}
        </Text>
        <Divider style={[a.my_md]} />
        <Text style={[a.font_bold, t.atoms.text_contrast_high]}>
          {type === 'feed' ? (
            <Trans>Feed creator</Trans>
          ) : (
            <Trans>List creator</Trans>
          )}
        </Text>
        {profile && moderationOpts && (
          <View style={[a.w_full, a.align_start]}>
            <ProfileCard.Link profile={profile} onPress={() => control.close()}>
              <ProfileCard.Header>
                <ProfileCard.Avatar
                  profile={profile}
                  moderationOpts={moderationOpts}
                  disabledPreview
                />
                <ProfileCard.NameAndHandle
                  profile={profile}
                  moderationOpts={moderationOpts}
                />
              </ProfileCard.Header>
            </ProfileCard.Link>
          </View>
        )}
        {isProfileError && (
          <Text
            style={[
              t.atoms.text_contrast_high,
              a.italic,
              a.text_center,
              a.w_full,
            ]}>
            <Trans>Could not find profile</Trans>
          </Text>
        )}
        {type === 'feed' && (
          <>
            <Text style={[a.font_bold, t.atoms.text_contrast_high, a.mt_md]}>
              <Trans>Feed identifier</Trans>
            </Text>
            <Text style={[a.text_md, t.atoms.text_contrast_high, a.italic]}>
              {atUri.rkey}
            </Text>
          </>
        )}
        {error instanceof Error && (
          <>
            <Text style={[a.font_bold, t.atoms.text_contrast_high, a.mt_md]}>
              <Trans>Error message</Trans>
            </Text>
            <Text style={[a.text_md, t.atoms.text_contrast_high, a.italic]}>
              {cleanError(error.message)}
            </Text>
          </>
        )}
      </View>
      {isNative && (
        <Button
          label={_(msg`Close`)}
          onPress={() => control.close()}
          size="small"
          variant="solid"
          color="secondary"
          style={[a.mt_5xl]}>
          <ButtonText>
            <Trans>Close</Trans>
          </ButtonText>
        </Button>
      )}
      <Dialog.Close />
    </Dialog.ScrollableInner>
  )
}