mirror of
https://github.com/balzack/databag.git
synced 2025-02-15 13:09:17 +00:00
connecting staggered load action
This commit is contained in:
parent
dcf0699a3b
commit
c2783fe693
@ -27,6 +27,10 @@ export function Conversation() {
|
|||||||
}
|
}
|
||||||
}, [state]);
|
}, [state]);
|
||||||
|
|
||||||
|
const onMoreTopics = () => {
|
||||||
|
actions.more();
|
||||||
|
}
|
||||||
|
|
||||||
const topicRenderer = (topic) => {
|
const topicRenderer = (topic) => {
|
||||||
return (<TopicItem host={state.cardId == null} topic={topic} />)
|
return (<TopicItem host={state.cardId == null} topic={topic} />)
|
||||||
}
|
}
|
||||||
@ -90,8 +94,8 @@ export function Conversation() {
|
|||||||
</div>
|
</div>
|
||||||
<div class="thread">
|
<div class="thread">
|
||||||
<VirtualList id={state.channelId + state.cardId}
|
<VirtualList id={state.channelId + state.cardId}
|
||||||
items={state.topics} itemRenderer={topicRenderer} />
|
items={state.topics} itemRenderer={topicRenderer} onMore={onMoreTopics} />
|
||||||
<BusySpin size="large" delay="1000" spinning={!state.init} />
|
<BusySpin size="large" delay="1000" spinning={state.loading} />
|
||||||
</div>
|
</div>
|
||||||
<AddTopic />
|
<AddTopic />
|
||||||
<Modal title="Conversation Members" visible={showMembers} centered onCancel={() => setShowMembers(false)}
|
<Modal title="Conversation Members" visible={showMembers} centered onCancel={() => setShowMembers(false)}
|
||||||
|
@ -7,7 +7,7 @@ import { ChannelContext } from 'context/ChannelContext';
|
|||||||
export function useConversation() {
|
export function useConversation() {
|
||||||
|
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
init: true,
|
loading: true,
|
||||||
cardId: null,
|
cardId: null,
|
||||||
channelId: null,
|
channelId: null,
|
||||||
subject: null,
|
subject: null,
|
||||||
@ -33,6 +33,9 @@ export function useConversation() {
|
|||||||
remove: async () => {
|
remove: async () => {
|
||||||
await conversation.actions.removeConversation();
|
await conversation.actions.removeConversation();
|
||||||
navigate('/user');
|
navigate('/user');
|
||||||
|
},
|
||||||
|
more: () => {
|
||||||
|
conversation.actions.addHistory();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -51,7 +54,7 @@ export function useConversation() {
|
|||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
updateState({
|
updateState({
|
||||||
init: conversation.state.init,
|
loading: conversation.state.loading,
|
||||||
subject: conversation.state.subject,
|
subject: conversation.state.subject,
|
||||||
contacts: conversation.state.contacts,
|
contacts: conversation.state.contacts,
|
||||||
cardId: conversation.state.cardId,
|
cardId: conversation.state.cardId,
|
||||||
|
@ -2,7 +2,7 @@ import React, { useRef, useState, useEffect } from 'react';
|
|||||||
import { VirtualListWrapper, VirtualItem } from './VirtualList.styled';
|
import { VirtualListWrapper, VirtualItem } from './VirtualList.styled';
|
||||||
import ReactResizeDetector from 'react-resize-detector';
|
import ReactResizeDetector from 'react-resize-detector';
|
||||||
|
|
||||||
export function VirtualList({ id, items, itemRenderer }) {
|
export function VirtualList({ id, items, itemRenderer, onMore }) {
|
||||||
|
|
||||||
const REDZONE = 1024; // recenter on canvas if in canvas edge redzone
|
const REDZONE = 1024; // recenter on canvas if in canvas edge redzone
|
||||||
const HOLDZONE = 2048; // drop slots outside of holdzone of view
|
const HOLDZONE = 2048; // drop slots outside of holdzone of view
|
||||||
@ -23,6 +23,7 @@ export function VirtualList({ id, items, itemRenderer }) {
|
|||||||
let listRef = useRef();
|
let listRef = useRef();
|
||||||
let key = useRef(null);
|
let key = useRef(null);
|
||||||
let itemView = useRef([]);
|
let itemView = useRef([]);
|
||||||
|
let nomore = useRef(false);
|
||||||
|
|
||||||
const addSlot = (id, slot) => {
|
const addSlot = (id, slot) => {
|
||||||
setSlots((m) => { m.set(id, slot); return new Map(m); })
|
setSlots((m) => { m.set(id, slot); return new Map(m); })
|
||||||
@ -110,6 +111,13 @@ export function VirtualList({ id, items, itemRenderer }) {
|
|||||||
if (view?.overscan?.top <= 0) {
|
if (view?.overscan?.top <= 0) {
|
||||||
scrollTop.current = containers.current[0].top;
|
scrollTop.current = containers.current[0].top;
|
||||||
listRef.current.scrollTo({ top: scrollTop.current, left: 0 });
|
listRef.current.scrollTo({ top: scrollTop.current, left: 0 });
|
||||||
|
if (!nomore.current) {
|
||||||
|
nomore.current = true;
|
||||||
|
onMore();
|
||||||
|
setTimeout(() => {
|
||||||
|
nomore.current = false;
|
||||||
|
}, 2500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ export function useConversationContext() {
|
|||||||
|
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
init: false,
|
init: false,
|
||||||
|
loading: false,
|
||||||
cardId: null,
|
cardId: null,
|
||||||
channelId: null,
|
channelId: null,
|
||||||
subject: null,
|
subject: null,
|
||||||
@ -210,6 +211,7 @@ export function useConversationContext() {
|
|||||||
await setTopics(events.current[0]);
|
await setTopics(events.current[0]);
|
||||||
events.current.shift();
|
events.current.shift();
|
||||||
}
|
}
|
||||||
|
updateState({ loading: false });
|
||||||
|
|
||||||
serialize.current--;
|
serialize.current--;
|
||||||
}
|
}
|
||||||
@ -223,12 +225,15 @@ export function useConversationContext() {
|
|||||||
const actions = {
|
const actions = {
|
||||||
setConversationId: (cardId, channelId) => {
|
setConversationId: (cardId, channelId) => {
|
||||||
view.current += 1;
|
view.current += 1;
|
||||||
|
updateState({ loading: true });
|
||||||
events.current = [{ type: EVENT_OPEN, data: { cardId, channelId }}];
|
events.current = [{ type: EVENT_OPEN, data: { cardId, channelId }}];
|
||||||
updateState({ init: false, subject: null, cardId, channelId, topics: new Map() });
|
updateState({ init: false, subject: null, cardId, channelId, topics: new Map() });
|
||||||
|
topics.current = new Map();
|
||||||
updateConversation();
|
updateConversation();
|
||||||
|
|
||||||
},
|
},
|
||||||
addHistory: () => {
|
addHistory: () => {
|
||||||
|
updateState({ loading: true });
|
||||||
events.current.push({ type: EVENT_MORE });
|
events.current.push({ type: EVENT_MORE });
|
||||||
updateConversation();
|
updateConversation();
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user