Re-align error components and types

This commit is contained in:
Eric Bailey
2024-05-16 12:32:25 -05:00
parent 3334b2f201
commit 8075605796
5 changed files with 37 additions and 118 deletions
@@ -5,26 +5,25 @@ import {useLingui} from '@lingui/react'
import {ConvoItem, ConvoItemError} from '#/state/messages/convo/types'
import {atoms as a, useTheme} from '#/alf'
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
import {ArrowRotateCounterClockwise_Stroke2_Corner0_Rounded as Refresh} from '#/components/icons/ArrowRotateCounterClockwise'
import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'
import {InlineLinkText} from '#/components/Link'
import {Text} from '#/components/Typography'
export function MessageListError({item}: {item: ConvoItem & {type: 'error'}}) {
const t = useTheme()
const {_} = useLingui()
const message = React.useMemo(() => {
const {description, help, cta} = React.useMemo(() => {
return {
[ConvoItemError.Unknown]: _(
msg`An unknown error occurred. If the issue persists, contact support.`,
),
[ConvoItemError.FirehoseFailed]: _(
msg`This chat was disconnected due to a network error.`,
),
[ConvoItemError.HistoryFailed]: _(msg`Failed to load past messages.`),
[ConvoItemError.UserBlocked]: _(
msg`The other user in this chat has blocked you.`,
),
[ConvoItemError.FirehoseFailed]: {
description: _(msg`This chat was disconnected`),
help: _(msg`Press to attempt reconnection`),
cta: _(msg`Reconnect`),
},
[ConvoItemError.HistoryFailed]: {
description: _(msg`Failed to load past messages`),
help: _(msg`Press to retry`),
cta: _(msg`Retry`),
},
}[item.code]
}, [_, item.code])
@@ -35,39 +34,31 @@ export function MessageListError({item}: {item: ConvoItem & {type: 'error'}}) {
a.flex_row,
a.align_center,
a.justify_between,
a.gap_lg,
a.py_md,
a.px_lg,
a.rounded_md,
t.atoms.bg_contrast_25,
a.gap_sm,
a.pb_lg,
{maxWidth: 400},
]}>
<View style={[a.flex_row, a.align_start, a.justify_between, a.gap_sm]}>
<CircleInfo
size="sm"
fill={t.palette.negative_400}
style={[{top: 3}]}
/>
<View style={[a.flex_1, {maxWidth: 240}]}>
<Text style={[a.leading_snug]}>{message}</Text>
</View>
</View>
<CircleInfo
size="sm"
fill={t.palette.negative_400}
style={[{top: 3}]}
/>
{item.retry && (
<Button
label={_(msg`Press to retry`)}
size="small"
variant="ghost"
color="secondary"
onPress={e => {
e.preventDefault()
item.retry?.()
return false
}}>
<ButtonText>{_(msg`Retry`)}</ButtonText>
<ButtonIcon icon={Refresh} position="right" />
</Button>
)}
<Text style={[a.leading_snug, a.flex_1, t.atoms.text_contrast_medium]}>
{description} &middot;{' '}
{item.retry && (
<InlineLinkText
to="#"
label={help}
onPress={e => {
e.preventDefault()
item.retry?.()
return false
}}>
{cta}
</InlineLinkText>
)}
</Text>
</View>
</View>
)
@@ -1,54 +0,0 @@
import React from 'react'
import {View} from 'react-native'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {ConvoItem} from '#/state/messages/convo/types'
import {atoms as a, useTheme} from '#/alf'
import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'
import {InlineLinkText} from '#/components/Link'
import {Text} from '#/components/Typography'
export function MessageListFirehoseError({
item,
}: {
item: ConvoItem & {type: 'firehose-error'}
}) {
const t = useTheme()
const {_} = useLingui()
return (
<View style={[a.py_lg, a.align_center]}>
<View
style={[
a.flex_row,
a.align_center,
a.justify_between,
a.gap_sm,
{maxWidth: 400},
]}>
<CircleInfo
size="sm"
fill={t.palette.negative_400}
style={[{top: 3}]}
/>
<Text style={[a.leading_snug, a.flex_1, t.atoms.text_contrast_medium]}>
{_(msg`This chat was disconnected`)} &middot;{' '}
{item.retry && (
<InlineLinkText
to="#"
label={_(msg`Press to attempt reconnection`)}
onPress={e => {
e.preventDefault()
item.retry?.()
return false
}}>
{_(msg`Reconnect`)}
</InlineLinkText>
)}
</Text>
</View>
</View>
)
}
@@ -15,7 +15,6 @@ import {isWeb} from 'platform/detection'
import {List} from 'view/com/util/List'
import {MessageInput} from '#/screens/Messages/Conversation/MessageInput'
import {MessageListError} from '#/screens/Messages/Conversation/MessageListError'
import {MessageListFirehoseError} from '#/screens/Messages/Conversation/MessageListFirehoseError'
import {atoms as a} from '#/alf'
import {MessageItem} from '#/components/dms/MessageItem'
import {Loader} from '#/components/Loader'
@@ -42,8 +41,6 @@ function renderItem({item}: {item: ConvoItem}) {
return <Text>Deleted message</Text>
} else if (item.type === 'error') {
return <MessageListError item={item} />
} else if (item.type === 'firehose-error') {
return <MessageListFirehoseError item={item} />
}
return null
+3 -2
View File
@@ -1007,8 +1007,9 @@ export class Convo {
if (this.firehoseError) {
items.push({
type: 'firehose-error',
key: 'firehose-error',
type: 'error',
code: ConvoItemError.FirehoseFailed,
key: ConvoItemError.FirehoseFailed,
retry: () => {
this.firehoseError?.retry()
},
-16
View File
@@ -23,10 +23,6 @@ export enum ConvoStatus {
}
export enum ConvoItemError {
/**
* Generic error
*/
Unknown = 'unknown',
/**
* Error connecting to event firehose
*/
@@ -35,10 +31,6 @@ export enum ConvoItemError {
* Error fetching past messages
*/
HistoryFailed = 'historyFailed',
/**
* Recipient is blocking the user
*/
UserBlocked = 'userBlocked',
}
export enum ConvoErrorCode {
@@ -123,14 +115,6 @@ export type ConvoItem =
*/
retry?: () => void
}
| {
type: 'firehose-error'
key: string
/**
* If present, error is recoverable.
*/
retry?: () => void
}
type DeleteMessage = (messageId: string) => Promise<void>
type SendMessage = (