added conversation loading indicator

This commit is contained in:
Roland Osborne 2022-10-20 15:09:10 -07:00
parent 95e1f55121
commit bd0d6e07d8
5 changed files with 32 additions and 6 deletions

View File

@ -15,6 +15,7 @@ export function useConversationContext() {
topics: new Map(),
created: null,
host: null,
init: false,
});
const store = useContext(StoreContext);
const card = useContext(CardContext);
@ -173,7 +174,7 @@ export function useConversationContext() {
else {
channel.actions.setReadRevision(channelId, revision.current);
}
updateState({ topics: topics.current });
updateState({ topics: topics.current, init: true });
}
syncing.current = false;
@ -306,7 +307,7 @@ export function useConversationContext() {
setView.current++;
conversationId.current = selected;
reset.current = true;
updateState({ subject: null, logo: null, contacts: [], topics: new Map() });
updateState({ subject: null, logo: null, contacts: [], topics: new Map(), init: false });
sync();
const { cardId, channelId, revision } = selected;
if (cardId) {

View File

@ -1,7 +1,7 @@
import { useEffect, useState, useRef, useContext } from 'react';
import SQLite from "react-native-sqlite-storage";
const DATABAG_DB = 'databag_v044.db';
const DATABAG_DB = 'databag_v045.db';
export function useStoreContext() {
const [state, setState] = useState({});

View File

@ -1,4 +1,4 @@
import { KeyboardAvoidingView, Modal, Platform, TextInput, View, TouchableOpacity, Text, } from 'react-native';
import { KeyboardAvoidingView, ActivityIndicator, Modal, Platform, TextInput, View, TouchableOpacity, Text, } from 'react-native';
import { useKeepAwake } from 'expo-keep-awake';
import { FlatList, ScrollView } from '@stream-io/flat-list-mvcp';
import { memo, useState, useRef, useEffect } from 'react';
@ -80,6 +80,11 @@ export function ConversationBody() {
remove={actions.removeTopic} update={actions.editTopic} block={actions.blockTopic} />}
keyExtractor={item => item.topicId}
/>
{ !state.init && (
<View style={styles.loading}>
<ActivityIndicator size="large" color={Colors.primary} />
</View>
)}
<View>
<AddTopic />
<View style={styles.latchbar}>

View File

@ -180,5 +180,12 @@ export const styles = StyleSheet.create({
alignItems: 'center',
justifyContent: 'center',
},
loading: {
position: 'absolute',
width: '100%',
height: '100%',
alignItems: 'center',
justifyContent: 'center',
},
})

View File

@ -1,4 +1,4 @@
import { useState, useEffect, useContext } from 'react';
import { useRef, useState, useEffect, useContext } from 'react';
import { ConversationContext } from 'context/ConversationContext';
export function useConversation() {
@ -15,8 +15,10 @@ export function useConversation() {
editTopicId: null,
editData: null,
editMessage: null,
init: false,
});
const delay = useRef(null);
const conversation = useContext(ConversationContext);
const updateState = (value) => {
@ -24,7 +26,7 @@ export function useConversation() {
}
useEffect(() => {
const { subject, logo, topics, host } = conversation.state;
const { subject, logo, topics, host, init } = conversation.state;
const items = Array.from(topics.values());
const sorted = items.sort((a, b) => {
const aTimestamp = a?.detail?.created;
@ -39,6 +41,17 @@ export function useConversation() {
});
const filtered = sorted.filter(item => !(item.blocked === 1));
updateState({ topics, subject, logo, host, topics: filtered });
if (init) {
clearTimeout(delay.current);
updateState({ init: true });
}
else {
if (!delay.current) {
delay.current = setTimeout(() => {
updateState({ init: false });
}, 500);
}
}
}, [conversation]);
const actions = {