[Clipclops] External store, suspend/resume (#3829)

* Initial working external store

* Clean up WIP, explore suspend/resume

* Clean up state, bindings, snapshots, add some logs

* Reduce snapshots, add better logic check

* Bump interval a smidge

* Remove unused type
This commit is contained in:
Eric Bailey 2024-05-02 20:57:51 -05:00 committed by GitHub
parent c13685a0cf
commit c9cf608f78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 344 additions and 172 deletions

View file

@ -90,7 +90,9 @@ export function MessagesList() {
}, [])
const onEndReached = useCallback(() => {
chat.service.fetchMessageHistory()
if (chat.status === ConvoStatus.Ready) {
chat.fetchMessageHistory()
}
}, [chat])
const onInputFocus = useCallback(() => {
@ -103,11 +105,13 @@ export function MessagesList() {
const onSendMessage = useCallback(
(text: string) => {
chat.service.sendMessage({
text,
})
if (chat.status === ConvoStatus.Ready) {
chat.sendMessage({
text,
})
}
},
[chat.service],
[chat],
)
const onScroll = React.useCallback(
@ -136,9 +140,7 @@ export function MessagesList() {
contentContainerStyle={a.flex_1}>
<FlatList
ref={flatListRef}
data={
chat.state.status === ConvoStatus.Ready ? chat.state.items : undefined
}
data={chat.status === ConvoStatus.Ready ? chat.items : undefined}
keyExtractor={keyExtractor}
renderItem={renderItem}
contentContainerStyle={{paddingHorizontal: 10}}
@ -161,8 +163,7 @@ export function MessagesList() {
ListFooterComponent={
<MaybeLoader
isLoading={
chat.state.status === ConvoStatus.Ready &&
chat.state.isFetchingHistory
chat.status === ConvoStatus.Ready && chat.isFetchingHistory
}
/>
}

View file

@ -1,7 +1,6 @@
import React, {useCallback} from 'react'
import {TouchableOpacity, View} from 'react-native'
import {AppBskyActorDefs} from '@atproto/api'
import {ChatBskyConvoDefs} from '@atproto-labs/api'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'
@ -47,16 +46,16 @@ function Inner() {
const myDid = currentAccount?.did
const otherProfile = React.useMemo(() => {
if (chat.state.status !== ConvoStatus.Ready) return
return chat.state.convo.members.find(m => m.did !== myDid)
}, [chat.state, myDid])
if (chat.status !== ConvoStatus.Ready) return
return chat.convo.members.find(m => m.did !== myDid)
}, [chat, myDid])
// TODO whenever we have error messages, we should use them in here -hailey
if (chat.state.status !== ConvoStatus.Ready || !otherProfile) {
if (chat.status !== ConvoStatus.Ready || !otherProfile) {
return (
<ListMaybePlaceholder
isLoading={true}
isError={chat.state.status === ConvoStatus.Error}
isError={chat.status === ConvoStatus.Error}
/>
)
}
@ -78,7 +77,7 @@ let Header = ({
const {_} = useLingui()
const {gtTablet} = useBreakpoints()
const navigation = useNavigation<NavigationProp>()
const {service} = useChat()
const chat = useChat()
const onPressBack = useCallback(() => {
if (isWeb) {
@ -88,12 +87,9 @@ let Header = ({
}
}, [navigation])
const onUpdateConvo = useCallback(
(convo: ChatBskyConvoDefs.ConvoView) => {
service.convo = convo
},
[service],
)
const onUpdateConvo = useCallback(() => {
// TODO eric update muted state
}, [])
return (
<View
@ -133,9 +129,9 @@ let Header = ({
<PreviewableUserAvatar size={32} profile={profile} />
<Text style={[a.text_lg, a.font_bold]}>{profile.displayName}</Text>
</View>
{service.convo ? (
{chat.status === ConvoStatus.Ready ? (
<ConvoMenu
convo={service.convo}
convo={chat.convo}
profile={profile}
onUpdateConvo={onUpdateConvo}
currentScreen="conversation"