render app loading indicator

This commit is contained in:
Roland Osborne 2022-08-30 14:08:55 -07:00
parent 28e19034fd
commit 286f523fd9
4 changed files with 49 additions and 1 deletions

View File

@ -1,5 +1,5 @@
import { useEffect, useContext } from 'react';
import { Drawer } from 'antd';
import { Drawer, Spin } from 'antd';
import { useNavigate } from 'react-router-dom';
import { SessionWrapper } from './Session.styled';
import { AppContext } from 'context/AppContext';
@ -76,6 +76,13 @@ export function Session() {
<div class="bottom">
<Channels open={openConversation} />
</div>
{ state.loading && (
<div class="reframe">
<div class="spinner">
<Spin size="large" />
</div>
</div>
)}
</div>
<div class="center">
<div class="reframe">
@ -131,6 +138,13 @@ export function Session() {
<div class="bottom">
<Channels open={actions.openConversation} />
</div>
{ state.loading && (
<div class="reframe">
<div class="spinner">
<Spin size="large" />
</div>
</div>
)}
</div>
<div class="right">
<div class="reframe">
@ -210,6 +224,13 @@ export function Session() {
<Profile />
</div>
)}
{ state.loading && (
<div class="reframe">
<div class="spinner">
<Spin size="large" />
</div>
</div>
)}
</div>
<div class="bottom">
<BottomNav state={state} actions={actions} />

View File

@ -9,6 +9,15 @@ export const SessionWrapper = styled.div`
width: 100%;
height: 100%;
z-index: 2;
.spinner {
display: flex;
align-items: center;
justify-content: center;
background-color: rgba(0,0,0,0.1);
width: 100%;
height: 100%;
}
}
.desktop-layout {

View File

@ -4,6 +4,7 @@ import { CardContext } from 'context/CardContext';
import { ChannelContext } from 'context/ChannelContext';
import { ConversationContext } from 'context/ConversationContext';
import { UploadContext } from 'context/UploadContext';
import { StoreContext } from 'context/StoreContext';
export function useConversation(cardId, channelId) {
@ -25,6 +26,7 @@ export function useConversation(cardId, channelId) {
const channel = useContext(ChannelContext);
const conversation = useContext(ConversationContext);
const upload = useContext(UploadContext);
const store = useContext(StoreContext);
const updateState = (value) => {
setState((s) => ({ ...s, ...value }));
@ -119,6 +121,8 @@ export function useConversation(cardId, channelId) {
});
const { loadingInit, loadingMore } = conversation.state;
updateState({ topics, loadingInit, loadingMore });
store.actions.setValue(`${channelId}::${cardId}`, Number(conversation.state.revision));
}, [conversation]);
const actions = {

View File

@ -2,6 +2,8 @@ import { useContext, useState, useEffect, useRef } from 'react';
import { CardContext } from 'context/CardContext';
import { StoreContext } from 'context/StoreContext';
import { ViewportContext } from 'context/ViewportContext';
import { ProfileContext } from 'context/ProfileContext';
import { ChannelContext } from 'context/ChannelContext';
export function useSession() {
@ -18,11 +20,14 @@ export function useSession() {
contact: false,
profile: false,
account: false,
loading: false,
});
const card = useContext(CardContext);
const store = useContext(StoreContext);
const viewport = useContext(ViewportContext);
const channel = useContext(ChannelContext);
const profile = useContext(ProfileContext);
const storeStatus = useRef(null);
const cardStatus = useRef(null);
@ -31,6 +36,15 @@ export function useSession() {
setState((s) => ({ ...s, ...value }));
}
useEffect(() => {
if (!profile.state.init || !card.state.init || !channel.state.init) {
updateState({ loading: true });
}
else {
updateState({ loading: false });
}
}, [card, channel, profile]);
useEffect(() => {
updateState({ display: viewport.state.display });
}, [viewport]);