mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
fix delay on loading message
This commit is contained in:
parent
90a63fbf5c
commit
1b3c606c5b
@ -87,7 +87,9 @@ export function ConversationBody() {
|
|||||||
<View style={styles.thread}>
|
<View style={styles.thread}>
|
||||||
{ state.topics.length === 0 && (
|
{ state.topics.length === 0 && (
|
||||||
<View style={styles.empty}>
|
<View style={styles.empty}>
|
||||||
|
{ state.init && (
|
||||||
<Text style={styles.emptyText}>No Messages</Text>
|
<Text style={styles.emptyText}>No Messages</Text>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
{ state.topics.length !== 0 && (
|
{ state.topics.length !== 0 && (
|
||||||
@ -107,7 +109,7 @@ export function ConversationBody() {
|
|||||||
keyExtractor={item => item.topicId}
|
keyExtractor={item => item.topicId}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{ !state.init && (
|
{ !state.init && state.delayed && (
|
||||||
<View style={styles.loading}>
|
<View style={styles.loading}>
|
||||||
<ActivityIndicator size="large" color={Colors.primary} />
|
<ActivityIndicator size="large" color={Colors.primary} />
|
||||||
</View>
|
</View>
|
||||||
|
@ -19,12 +19,15 @@ export function useConversation() {
|
|||||||
editData: null,
|
editData: null,
|
||||||
editMessage: null,
|
editMessage: null,
|
||||||
init: false,
|
init: false,
|
||||||
|
delayed: false,
|
||||||
error: false,
|
error: false,
|
||||||
keyboard: false,
|
keyboard: false,
|
||||||
locked: false,
|
locked: false,
|
||||||
sealKey: null,
|
sealKey: null,
|
||||||
|
delayed: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const init = useRef(true);
|
||||||
const delay = useRef(null);
|
const delay = useRef(null);
|
||||||
const conversation = useContext(ConversationContext);
|
const conversation = useContext(ConversationContext);
|
||||||
const account = useContext(AccountContext);
|
const account = useContext(AccountContext);
|
||||||
@ -33,15 +36,6 @@ export function useConversation() {
|
|||||||
setState((s) => ({ ...s, ...value }));
|
setState((s) => ({ ...s, ...value }));
|
||||||
}
|
}
|
||||||
|
|
||||||
const converPem = (str) => {
|
|
||||||
var result = '';
|
|
||||||
while (str.length > 0) {
|
|
||||||
result += str.substring(0, 64) + '\n';
|
|
||||||
str = str.substring(64);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let sealKey;
|
let sealKey;
|
||||||
const { locked, seals } = conversation.state;
|
const { locked, seals } = conversation.state;
|
||||||
@ -59,6 +53,7 @@ const converPem = (str) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { error, subject, logo, topics, host, init } = conversation.state;
|
const { error, subject, logo, topics, host, init } = conversation.state;
|
||||||
|
|
||||||
const items = Array.from(topics.values());
|
const items = Array.from(topics.values());
|
||||||
const sorted = items.sort((a, b) => {
|
const sorted = items.sort((a, b) => {
|
||||||
const aTimestamp = a?.detail?.created;
|
const aTimestamp = a?.detail?.created;
|
||||||
@ -72,18 +67,17 @@ const converPem = (str) => {
|
|||||||
return -1;
|
return -1;
|
||||||
});
|
});
|
||||||
const filtered = sorted.filter(item => !(item.blocked === 1));
|
const filtered = sorted.filter(item => !(item.blocked === 1));
|
||||||
updateState({ subject, logo, host, error, topics: filtered });
|
|
||||||
if (init) {
|
if (!init) {
|
||||||
clearTimeout(delay.current);
|
setTimeout(() => {
|
||||||
updateState({ init: true });
|
updateState({ delayed: true });
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!delay.current) {
|
|
||||||
delay.current = setTimeout(() => {
|
|
||||||
updateState({ init: false });
|
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
updateState({ delayed: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateState({ init, subject, logo, host, error, topics: filtered });
|
||||||
}, [conversation]);
|
}, [conversation]);
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
|
@ -157,10 +157,12 @@ export function ProfileBody({ navigation }) {
|
|||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
<Switch style={styles.visibleSwitch} value={state.pushEnabled} onValueChange={setNotifications} trackColor={styles.switch}/>
|
<Switch style={styles.visibleSwitch} value={state.pushEnabled} onValueChange={setNotifications} trackColor={styles.switch}/>
|
||||||
</View>
|
</View>
|
||||||
|
{ state.sealable && (
|
||||||
<TouchableOpacity style={styles.link} onPress={actions.showSealEdit}>
|
<TouchableOpacity style={styles.link} onPress={actions.showSealEdit}>
|
||||||
<Ionicons name="setting" size={14} color={Colors.primary} />
|
<Ionicons name="setting" size={14} color={Colors.primary} />
|
||||||
<Text style={styles.linkText}>Sealed Topics</Text>
|
<Text style={styles.linkText}>Sealed Topics</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
)}
|
||||||
<TouchableOpacity style={styles.link} onPress={actions.showLoginEdit}>
|
<TouchableOpacity style={styles.link} onPress={actions.showLoginEdit}>
|
||||||
<Ionicons name="lock" size={14} color={Colors.primary} />
|
<Ionicons name="lock" size={14} color={Colors.primary} />
|
||||||
<Text style={styles.linkText}>Change Login</Text>
|
<Text style={styles.linkText}>Change Login</Text>
|
||||||
|
@ -17,6 +17,7 @@ export function useProfileBody() {
|
|||||||
description: null,
|
description: null,
|
||||||
node: null,
|
node: null,
|
||||||
imageSource: null,
|
imageSource: null,
|
||||||
|
sealable: false,
|
||||||
searchable: null,
|
searchable: null,
|
||||||
notifications: null,
|
notifications: null,
|
||||||
showDetailEdit: false,
|
showDetailEdit: false,
|
||||||
@ -83,11 +84,11 @@ export function useProfileBody() {
|
|||||||
}, [profile]);
|
}, [profile]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { searchable, pushEnabled, seal } = account.state.status;
|
const { searchable, pushEnabled, seal, sealable } = account.state.status;
|
||||||
const sealKey = account.state.sealKey;
|
const sealKey = account.state.sealKey;
|
||||||
const sealEnabled = seal?.publicKey != null;
|
const sealEnabled = seal?.publicKey != null;
|
||||||
const sealUnlocked = seal?.publicKey === sealKey?.public && sealKey?.private && sealKey?.public;
|
const sealUnlocked = seal?.publicKey === sealKey?.public && sealKey?.private && sealKey?.public;
|
||||||
updateState({ searchable, pushEnabled, seal, sealKey, sealEnabled, sealUnlocked });
|
updateState({ searchable, sealable, pushEnabled, seal, sealKey, sealEnabled, sealUnlocked });
|
||||||
}, [account]);
|
}, [account]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user