prevent flicker of message placeholder

This commit is contained in:
Roland Osborne 2022-12-20 16:12:22 -08:00
parent 2a7d1423e2
commit b0c97b86f5
2 changed files with 14 additions and 2 deletions

View File

@ -69,7 +69,7 @@ export function Conversation({ closeConversation, openDetails, cardId, channelId
)}
</div>
<div class="thread" ref={thread} onScroll={scrollThread}>
{ state.topics.length === 0 && (
{ state.delayed && state.topics.length === 0 && (
<div class="empty">This Topic Has No Messages</div>
)}
{ state.topics.length !== 0 && (

View File

@ -24,6 +24,7 @@ export function useConversation(cardId, channelId) {
error: false,
sealed: false,
sealKey: null,
delayed: false,
});
const account = useContext(AccountContext);
@ -90,7 +91,10 @@ export function useConversation(cardId, channelId) {
}, [cardId, channelId, upload]);
useEffect(() => {
updateState({ topics: [] });
updateState({ delayed: false, topics: [] });
setTimeout(() => {
updateState({ delayed: true });
}, 250);
conversation.actions.setConversationId(cardId, channelId);
// eslint-disable-next-line
}, [cardId, channelId]);
@ -107,6 +111,14 @@ export function useConversation(cardId, channelId) {
}
return 1;
});
if (topics.length) {
updateState({ delayed: false });
}
else {
setTimeout(() => {
updateState({ delayed: true });
}, 250);
}
const { error, loadingInit, loadingMore, subject, logoUrl, logoImg } = conversation.state;
updateState({ topics, error, loadingInit, loadingMore, subject, logoUrl, logoImg });
store.actions.setValue(`${channelId}::${cardId}`, Number(conversation.state.revision));