mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
render upload status
This commit is contained in:
parent
b2798163d0
commit
0f4fbda445
@ -1,5 +1,6 @@
|
|||||||
import { useState, useEffect, useRef, useContext } from 'react';
|
import { useState, useEffect, useRef, useContext } from 'react';
|
||||||
import { StoreContext } from 'context/StoreContext';
|
import { StoreContext } from 'context/StoreContext';
|
||||||
|
import { UploadContext } from 'context/UploadContext';
|
||||||
import { CardContext } from 'context/CardContext';
|
import { CardContext } from 'context/CardContext';
|
||||||
import { ChannelContext } from 'context/ChannelContext';
|
import { ChannelContext } from 'context/ChannelContext';
|
||||||
import { ProfileContext } from 'context/ProfileContext';
|
import { ProfileContext } from 'context/ProfileContext';
|
||||||
@ -16,8 +17,12 @@ export function useConversationContext() {
|
|||||||
created: null,
|
created: null,
|
||||||
host: null,
|
host: null,
|
||||||
init: false,
|
init: false,
|
||||||
|
progress: null,
|
||||||
|
cardId: null,
|
||||||
|
channelId: null,
|
||||||
});
|
});
|
||||||
const store = useContext(StoreContext);
|
const store = useContext(StoreContext);
|
||||||
|
const upload = useContext(UploadContext);
|
||||||
const card = useContext(CardContext);
|
const card = useContext(CardContext);
|
||||||
const channel = useContext(ChannelContext);
|
const channel = useContext(ChannelContext);
|
||||||
const profile = useContext(ProfileContext);
|
const profile = useContext(ProfileContext);
|
||||||
@ -34,6 +39,44 @@ export function useConversationContext() {
|
|||||||
setState((s) => ({ ...s, ...value }))
|
setState((s) => ({ ...s, ...value }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const { cardId, channelId } = state;
|
||||||
|
const key = cardId ? `${cardId}:${channelId}` : `:${channelId}`
|
||||||
|
const progress = upload.state.progress.get(key);
|
||||||
|
if (progress) {
|
||||||
|
let count = 0;
|
||||||
|
let complete = 0;
|
||||||
|
let active = 0;
|
||||||
|
let loaded = 0;
|
||||||
|
let total = 0;
|
||||||
|
let error = false;
|
||||||
|
progress.forEach(post => {
|
||||||
|
count += post.count;
|
||||||
|
complete += (post.index - 1);
|
||||||
|
if (post.active) {
|
||||||
|
active += 1;
|
||||||
|
loaded += post.active.loaded;
|
||||||
|
total += post.active.total;
|
||||||
|
}
|
||||||
|
if (post.error) {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
percent = Math.floor(((((loaded / total) * active) + complete) / count) * 100);
|
||||||
|
updateState({ progress: percent, uploadError: error });
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
setTimeout(() => {
|
||||||
|
upload.actions.clearErrors(cardId, channelId);
|
||||||
|
updateState({ progress: null, uploadError: false });
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
updateState({ progress: null });
|
||||||
|
}
|
||||||
|
}, [upload, state.cardId, state.channelId]);
|
||||||
|
|
||||||
const getTopicItems = async (cardId, channelId) => {
|
const getTopicItems = async (cardId, channelId) => {
|
||||||
if (cardId) {
|
if (cardId) {
|
||||||
return await card.actions.getChannelTopicItems(cardId, channelId);
|
return await card.actions.getChannelTopicItems(cardId, channelId);
|
||||||
@ -307,7 +350,8 @@ export function useConversationContext() {
|
|||||||
setView.current++;
|
setView.current++;
|
||||||
conversationId.current = selected;
|
conversationId.current = selected;
|
||||||
reset.current = true;
|
reset.current = true;
|
||||||
updateState({ subject: null, logo: null, contacts: [], topics: new Map(), init: false });
|
updateState({ subject: null, logo: null, contacts: [], topics: new Map(), init: false,
|
||||||
|
cardId: selected.cardId, channelId: selected.channelId });
|
||||||
sync();
|
sync();
|
||||||
const { cardId, channelId, revision } = selected;
|
const { cardId, channelId, revision } = selected;
|
||||||
if (cardId) {
|
if (cardId) {
|
||||||
|
@ -111,6 +111,15 @@ export function AddTopic() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView style={styles.add} edges={['right']}>
|
<SafeAreaView style={styles.add} edges={['right']}>
|
||||||
|
{ !state.uploadError && state.progress && (
|
||||||
|
<View style={{ height: 0, width: `${state.progress}%`, borderColor: Colors.background, borderWidth: 1 }} />
|
||||||
|
)}
|
||||||
|
{ !state.uploadError && !state.progress && (
|
||||||
|
<View style={{ height: 0, width: '100%', borderColor: Colors.formBackground, borderWidth: 1 }} />
|
||||||
|
)}
|
||||||
|
{ state.uploadError && (
|
||||||
|
<View style={{ height: 0, width: '100%', borderColor: Colors.alert, borderWidth: 1 }} />
|
||||||
|
)}
|
||||||
{ state.assets.length > 0 && (
|
{ state.assets.length > 0 && (
|
||||||
<FlatList style={styles.carousel}
|
<FlatList style={styles.carousel}
|
||||||
data={state.assets}
|
data={state.assets}
|
||||||
|
@ -25,6 +25,11 @@ export function useAddTopic(cardId, channelId) {
|
|||||||
setState((s) => ({ ...s, ...value }));
|
setState((s) => ({ ...s, ...value }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const { progress, uploadError } = conversation.state;
|
||||||
|
updateState({ progress, uploadError });
|
||||||
|
}, [conversation]);
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
setMessage: (message) => {
|
setMessage: (message) => {
|
||||||
updateState({ message });
|
updateState({ message });
|
||||||
|
Loading…
Reference in New Issue
Block a user