Style send failure, retry
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
import React, {useCallback, useMemo, useRef} from 'react'
|
import React, {useCallback, useMemo, useRef} from 'react'
|
||||||
import {LayoutAnimation, StyleProp, TextStyle, View} from 'react-native'
|
import {
|
||||||
|
GestureResponderEvent,
|
||||||
|
LayoutAnimation,
|
||||||
|
StyleProp,
|
||||||
|
TextStyle,
|
||||||
|
View,
|
||||||
|
} from 'react-native'
|
||||||
import {ChatBskyConvoDefs, RichText as RichTextAPI} from '@atproto/api'
|
import {ChatBskyConvoDefs, RichText as RichTextAPI} from '@atproto/api'
|
||||||
import {msg} from '@lingui/macro'
|
import {msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
@@ -9,6 +15,7 @@ import {useSession} from '#/state/session'
|
|||||||
import {TimeElapsed} from 'view/com/util/TimeElapsed'
|
import {TimeElapsed} from 'view/com/util/TimeElapsed'
|
||||||
import {atoms as a, useTheme} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {ActionsWrapper} from '#/components/dms/ActionsWrapper'
|
import {ActionsWrapper} from '#/components/dms/ActionsWrapper'
|
||||||
|
import {InlineLinkText} from '#/components/Link'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
import {RichText} from '../RichText'
|
import {RichText} from '../RichText'
|
||||||
|
|
||||||
@@ -21,7 +28,7 @@ let MessageItem = ({
|
|||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
|
|
||||||
const {message, nextMessage} = item
|
const {message, nextMessage} = item
|
||||||
const pending = item.type === 'pending-message'
|
const isPending = item.type === 'pending-message'
|
||||||
|
|
||||||
const isFromSelf = message.sender?.did === currentAccount?.did
|
const isFromSelf = message.sender?.did === currentAccount?.did
|
||||||
|
|
||||||
@@ -30,11 +37,6 @@ let MessageItem = ({
|
|||||||
nextMessage.sender?.did === currentAccount?.did
|
nextMessage.sender?.did === currentAccount?.did
|
||||||
|
|
||||||
const isLastInGroup = useMemo(() => {
|
const isLastInGroup = useMemo(() => {
|
||||||
// TODO this means it's a placeholder. Let's figure out the right way to do this though!
|
|
||||||
if (message.id.length > 13) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the next message is from a different sender, then it's the last in the group
|
// if the next message is from a different sender, then it's the last in the group
|
||||||
if (isFromSelf ? !isNextFromSelf : isNextFromSelf) {
|
if (isFromSelf ? !isNextFromSelf : isNextFromSelf) {
|
||||||
return true
|
return true
|
||||||
@@ -79,7 +81,7 @@ let MessageItem = ({
|
|||||||
paddingLeft: 14,
|
paddingLeft: 14,
|
||||||
paddingRight: 14,
|
paddingRight: 14,
|
||||||
backgroundColor: isFromSelf
|
backgroundColor: isFromSelf
|
||||||
? pending
|
? isPending
|
||||||
? pendingColor
|
? pendingColor
|
||||||
: t.palette.primary_500
|
: t.palette.primary_500
|
||||||
: t.palette.contrast_50,
|
: t.palette.contrast_50,
|
||||||
@@ -95,18 +97,20 @@ let MessageItem = ({
|
|||||||
a.text_md,
|
a.text_md,
|
||||||
a.leading_snug,
|
a.leading_snug,
|
||||||
isFromSelf && {color: t.palette.white},
|
isFromSelf && {color: t.palette.white},
|
||||||
pending && t.name !== 'light' && {color: t.palette.primary_300},
|
isPending && t.name !== 'light' && {color: t.palette.primary_300},
|
||||||
]}
|
]}
|
||||||
interactiveStyle={a.underline}
|
interactiveStyle={a.underline}
|
||||||
enableTags
|
enableTags
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</ActionsWrapper>
|
</ActionsWrapper>
|
||||||
|
|
||||||
|
{isLastInGroup && (
|
||||||
<MessageItemMetadata
|
<MessageItemMetadata
|
||||||
message={message}
|
item={item}
|
||||||
isLastInGroup={isLastInGroup}
|
|
||||||
style={isFromSelf ? a.text_right : a.text_left}
|
style={isFromSelf ? a.text_right : a.text_left}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -114,16 +118,26 @@ MessageItem = React.memo(MessageItem)
|
|||||||
export {MessageItem}
|
export {MessageItem}
|
||||||
|
|
||||||
let MessageItemMetadata = ({
|
let MessageItemMetadata = ({
|
||||||
message,
|
item,
|
||||||
isLastInGroup,
|
|
||||||
style,
|
style,
|
||||||
}: {
|
}: {
|
||||||
message: ChatBskyConvoDefs.MessageView
|
item: ConvoItem & {type: 'message' | 'pending-message'}
|
||||||
isLastInGroup: boolean
|
|
||||||
style: StyleProp<TextStyle>
|
style: StyleProp<TextStyle>
|
||||||
}): React.ReactNode => {
|
}): React.ReactNode => {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
|
const {message} = item
|
||||||
|
|
||||||
|
const handleRetry = useCallback(
|
||||||
|
(e: GestureResponderEvent) => {
|
||||||
|
if (item.type === 'pending-message' && item.retry) {
|
||||||
|
e.preventDefault()
|
||||||
|
item.retry()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[item],
|
||||||
|
)
|
||||||
|
|
||||||
const relativeTimestamp = useCallback(
|
const relativeTimestamp = useCallback(
|
||||||
(timestamp: string) => {
|
(timestamp: string) => {
|
||||||
@@ -166,25 +180,47 @@ let MessageItemMetadata = ({
|
|||||||
[_],
|
[_],
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!isLastInGroup) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TimeElapsed timestamp={message.sentAt} timeToString={relativeTimestamp}>
|
|
||||||
{({timeElapsed}) => (
|
|
||||||
<Text
|
<Text
|
||||||
style={[
|
style={[
|
||||||
t.atoms.text_contrast_medium,
|
|
||||||
a.text_xs,
|
a.text_xs,
|
||||||
a.mt_2xs,
|
a.mt_2xs,
|
||||||
a.mb_lg,
|
a.mb_lg,
|
||||||
|
t.atoms.text_contrast_medium,
|
||||||
style,
|
style,
|
||||||
]}>
|
]}>
|
||||||
|
<TimeElapsed timestamp={message.sentAt} timeToString={relativeTimestamp}>
|
||||||
|
{({timeElapsed}) => (
|
||||||
|
<Text style={[a.text_xs, t.atoms.text_contrast_medium]}>
|
||||||
{timeElapsed}
|
{timeElapsed}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</TimeElapsed>
|
</TimeElapsed>
|
||||||
|
|
||||||
|
{item.type === 'pending-message' && item.retry && (
|
||||||
|
<>
|
||||||
|
{' '}
|
||||||
|
·{' '}
|
||||||
|
<Text
|
||||||
|
style={[
|
||||||
|
a.text_xs,
|
||||||
|
{
|
||||||
|
color: t.palette.negative_400,
|
||||||
|
},
|
||||||
|
]}>
|
||||||
|
{_(msg`Failed to send`)}
|
||||||
|
</Text>{' '}
|
||||||
|
·{' '}
|
||||||
|
<InlineLinkText
|
||||||
|
label={_(msg`Click to retry failed message`)}
|
||||||
|
to="#"
|
||||||
|
onPress={handleRetry}
|
||||||
|
style={[a.text_xs]}>
|
||||||
|
{_(msg`Retry`)}
|
||||||
|
</InlineLinkText>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Text>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user