Forum: Refetch topic if missing thread info (#6861)
This commit is contained in:
parent
903f20010f
commit
5db531a04b
@ -19,6 +19,7 @@ import {
|
|||||||
selectChat,
|
selectChat,
|
||||||
selectCurrentMessageList,
|
selectCurrentMessageList,
|
||||||
selectIsForumPanelOpen,
|
selectIsForumPanelOpen,
|
||||||
|
selectIsSynced,
|
||||||
selectTabState,
|
selectTabState,
|
||||||
selectTopicsInfo,
|
selectTopicsInfo,
|
||||||
} from '../../../../global/selectors';
|
} from '../../../../global/selectors';
|
||||||
@ -33,6 +34,7 @@ import { mapTruthyValues, mapValues } from '../../../../util/iteratees';
|
|||||||
|
|
||||||
import useSelector from '../../../../hooks/data/useSelector';
|
import useSelector from '../../../../hooks/data/useSelector';
|
||||||
import useAppLayout from '../../../../hooks/useAppLayout';
|
import useAppLayout from '../../../../hooks/useAppLayout';
|
||||||
|
import useEffectWithPrevDeps from '../../../../hooks/useEffectWithPrevDeps';
|
||||||
import useHistoryBack from '../../../../hooks/useHistoryBack';
|
import useHistoryBack from '../../../../hooks/useHistoryBack';
|
||||||
import useInfiniteScroll from '../../../../hooks/useInfiniteScroll';
|
import useInfiniteScroll from '../../../../hooks/useInfiniteScroll';
|
||||||
import { useIntersectionObserver, useOnIntersect } from '../../../../hooks/useIntersectionObserver';
|
import { useIntersectionObserver, useOnIntersect } from '../../../../hooks/useIntersectionObserver';
|
||||||
@ -66,6 +68,7 @@ type StateProps = {
|
|||||||
chat?: ApiChat;
|
chat?: ApiChat;
|
||||||
topicsInfo?: TopicsInfo;
|
topicsInfo?: TopicsInfo;
|
||||||
currentTopicId?: number;
|
currentTopicId?: number;
|
||||||
|
isSynced?: boolean;
|
||||||
withInterfaceAnimations?: boolean;
|
withInterfaceAnimations?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -76,6 +79,7 @@ const ForumPanel = ({
|
|||||||
currentTopicId,
|
currentTopicId,
|
||||||
isOpen,
|
isOpen,
|
||||||
isHidden,
|
isHidden,
|
||||||
|
isSynced,
|
||||||
topicsInfo,
|
topicsInfo,
|
||||||
withInterfaceAnimations,
|
withInterfaceAnimations,
|
||||||
onTopicSearch,
|
onTopicSearch,
|
||||||
@ -93,11 +97,13 @@ const ForumPanel = ({
|
|||||||
const { isMobile } = useAppLayout();
|
const { isMobile } = useAppLayout();
|
||||||
const chatId = chat?.id;
|
const chatId = chat?.id;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffectWithPrevDeps(([prevIsSynced]) => {
|
||||||
if (chatId && !topicsInfo) {
|
if (!isSynced) return;
|
||||||
loadTopics({ chatId });
|
const hasJustSynced = prevIsSynced === false;
|
||||||
|
if (chatId && (hasJustSynced || !topicsInfo)) {
|
||||||
|
loadTopics({ chatId, force: hasJustSynced });
|
||||||
}
|
}
|
||||||
}, [topicsInfo, chatId]);
|
}, [isSynced, chatId, topicsInfo]);
|
||||||
|
|
||||||
const [isScrolled, setIsScrolled] = useState(false);
|
const [isScrolled, setIsScrolled] = useState(false);
|
||||||
const lang = useLang();
|
const lang = useLang();
|
||||||
@ -150,7 +156,7 @@ const ForumPanel = ({
|
|||||||
const { orderDiffById, shiftDiff, getAnimationType, onReorderAnimationEnd } = useOrderDiff(orderedIds, 0, chat?.id);
|
const { orderDiffById, shiftDiff, getAnimationType, onReorderAnimationEnd } = useOrderDiff(orderedIds, 0, chat?.id);
|
||||||
|
|
||||||
const [viewportIds, getMore] = useInfiniteScroll(() => {
|
const [viewportIds, getMore] = useInfiniteScroll(() => {
|
||||||
if (!chat) return;
|
if (!chat || !isSynced) return;
|
||||||
loadTopics({ chatId: chat.id });
|
loadTopics({ chatId: chat.id });
|
||||||
}, orderedIds, !topicsInfo?.totalCount || orderedIds.length >= topicsInfo.totalCount, TOPICS_SLICE);
|
}, orderedIds, !topicsInfo?.totalCount || orderedIds.length >= topicsInfo.totalCount, TOPICS_SLICE);
|
||||||
|
|
||||||
@ -336,6 +342,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
return {
|
return {
|
||||||
chat,
|
chat,
|
||||||
currentTopicId: chatId === currentChatId ? Number(currentThreadId) : undefined,
|
currentTopicId: chatId === currentChatId ? Number(currentThreadId) : undefined,
|
||||||
|
isSynced: selectIsSynced(global),
|
||||||
withInterfaceAnimations: selectCanAnimateInterface(global),
|
withInterfaceAnimations: selectCanAnimateInterface(global),
|
||||||
topicsInfo,
|
topicsInfo,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -272,6 +272,27 @@ addActionHandler('openSavedDialog', (global, actions, payload): ActionReturnType
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Refetch topic if thread info is missing
|
||||||
|
addActionHandler('openThread', (global, actions, payload): ActionReturnType => {
|
||||||
|
if (payload.isComments || payload.threadId === MAIN_THREAD_ID) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { chatId, threadId, tabId = getCurrentTabId() } = payload;
|
||||||
|
const chat = selectChat(global, chatId);
|
||||||
|
if (!chat?.isForum) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const topic = selectTopic(global, chatId, threadId);
|
||||||
|
const threadInfo = selectThreadInfo(global, chatId, threadId);
|
||||||
|
if (!topic || threadInfo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
actions.loadTopicById({ chatId, topicId: Number(threadId), tabId });
|
||||||
|
});
|
||||||
|
|
||||||
addActionHandler('openThread', async (global, actions, payload): Promise<void> => {
|
addActionHandler('openThread', async (global, actions, payload): Promise<void> => {
|
||||||
const {
|
const {
|
||||||
type, isComments, noForumTopicPanel, shouldReplaceHistory, shouldReplaceLast,
|
type, isComments, noForumTopicPanel, shouldReplaceHistory, shouldReplaceLast,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user