Forward Modal: Fix order for forum topics in Forward Modal (#6970)
This commit is contained in:
parent
d7082efd93
commit
328943d254
@ -4,13 +4,12 @@ import {
|
|||||||
} from '../../../lib/teact/teact';
|
} from '../../../lib/teact/teact';
|
||||||
import { getActions, getGlobal, withGlobal } from '../../../global';
|
import { getActions, getGlobal, withGlobal } from '../../../global';
|
||||||
|
|
||||||
import type { ApiTopic } from '../../../api/types';
|
|
||||||
import type { GlobalState } from '../../../global/types';
|
import type { GlobalState } from '../../../global/types';
|
||||||
import type { AnimationLevel, ThreadId } from '../../../types';
|
import type { AnimationLevel, ThreadId } from '../../../types';
|
||||||
|
|
||||||
import { PEER_PICKER_ITEM_HEIGHT_PX } from '../../../config';
|
import { PEER_PICKER_ITEM_HEIGHT_PX } from '../../../config';
|
||||||
import {
|
import {
|
||||||
getCanPostInChat, getGroupStatus, getUserStatus, isUserOnline,
|
getCanPostInChat, getGroupStatus, getOrderedTopics, getUserStatus, isUserOnline,
|
||||||
} from '../../../global/helpers';
|
} from '../../../global/helpers';
|
||||||
import { isApiPeerChat } from '../../../global/helpers/peers';
|
import { isApiPeerChat } from '../../../global/helpers/peers';
|
||||||
import {
|
import {
|
||||||
@ -21,7 +20,9 @@ import {
|
|||||||
selectUserStatus,
|
selectUserStatus,
|
||||||
} from '../../../global/selectors';
|
} from '../../../global/selectors';
|
||||||
import { selectAnimationLevel } from '../../../global/selectors/sharedState';
|
import { selectAnimationLevel } from '../../../global/selectors/sharedState';
|
||||||
|
import { selectThread } from '../../../global/selectors/threads';
|
||||||
import buildClassName from '../../../util/buildClassName';
|
import buildClassName from '../../../util/buildClassName';
|
||||||
|
import { mapTruthyValues, mapValues } from '../../../util/iteratees';
|
||||||
import {
|
import {
|
||||||
buildChatSelectionKey,
|
buildChatSelectionKey,
|
||||||
type ChatSelectionKey,
|
type ChatSelectionKey,
|
||||||
@ -31,7 +32,7 @@ import { resolveTransitionName } from '../../../util/resolveTransitionName';
|
|||||||
import { REM } from '../helpers/mediaDimensions';
|
import { REM } from '../helpers/mediaDimensions';
|
||||||
import renderText from '../helpers/renderText';
|
import renderText from '../helpers/renderText';
|
||||||
|
|
||||||
import useSelector from '../../../hooks/data/useSelector';
|
import useSelector, { useShallowSelector } from '../../../hooks/data/useSelector';
|
||||||
import useInfiniteScroll from '../../../hooks/useInfiniteScroll';
|
import useInfiniteScroll from '../../../hooks/useInfiniteScroll';
|
||||||
import useInputFocusOnOpen from '../../../hooks/useInputFocusOnOpen';
|
import useInputFocusOnOpen from '../../../hooks/useInputFocusOnOpen';
|
||||||
import useKeyboardListNavigation from '../../../hooks/useKeyboardListNavigation';
|
import useKeyboardListNavigation from '../../../hooks/useKeyboardListNavigation';
|
||||||
@ -144,7 +145,16 @@ const ChatOrUserPicker = ({
|
|||||||
}, [forumId]);
|
}, [forumId]);
|
||||||
|
|
||||||
const topicsInfo = useSelector(selectForumTopicsInfo);
|
const topicsInfo = useSelector(selectForumTopicsInfo);
|
||||||
const forumTopicsById = topicsInfo?.topicsById;
|
|
||||||
|
const selectTopicThreads = useCallback((global: GlobalState) => {
|
||||||
|
if (!forumId) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapTruthyValues(topicsInfo?.topicsById || {}, (topic) => selectThread(global, forumId, topic.id));
|
||||||
|
}, [forumId, topicsInfo?.topicsById]);
|
||||||
|
|
||||||
|
const topicThreads = useShallowSelector(selectTopicThreads);
|
||||||
|
|
||||||
const [topicIds, topics] = useMemo(() => {
|
const [topicIds, topics] = useMemo(() => {
|
||||||
const global = getGlobal();
|
const global = getGlobal();
|
||||||
@ -153,27 +163,25 @@ const ChatOrUserPicker = ({
|
|||||||
|
|
||||||
const chat = chatsById[forumId!];
|
const chat = chatsById[forumId!];
|
||||||
|
|
||||||
if (!chat || !forumTopicsById) {
|
if (!chat || !topicsInfo) {
|
||||||
return [undefined, undefined];
|
return [undefined, undefined];
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchTitle = topicSearch.toLowerCase();
|
const searchTitle = topicSearch.toLowerCase();
|
||||||
|
|
||||||
const result = forumTopicsById
|
const filteredTopics = Object.values(topicsInfo.topicsById).filter((topic) => (
|
||||||
? Object.values(forumTopicsById).reduce((acc, topic) => {
|
getCanPostInChat(chat, topic, undefined, chatFullInfoById[forumId!])
|
||||||
if (
|
&& (!searchTitle || topic.title.toLowerCase().includes(searchTitle))
|
||||||
getCanPostInChat(chat, topic, undefined, chatFullInfoById[forumId!])
|
));
|
||||||
&& (!searchTitle || topic.title.toLowerCase().includes(searchTitle))
|
const topicThreadInfos = topicThreads && mapValues(topicThreads, (topicThread) => topicThread.threadInfo);
|
||||||
) {
|
const orderedTopics = getOrderedTopics(
|
||||||
acc[topic.id] = topic;
|
filteredTopics,
|
||||||
}
|
topicThreadInfos,
|
||||||
|
topicsInfo.orderedPinnedTopicIds,
|
||||||
|
);
|
||||||
|
|
||||||
return acc;
|
return [orderedTopics.map(({ id }) => id), topicsInfo.topicsById];
|
||||||
}, {} as Record<number, ApiTopic>)
|
}, [forumId, topicSearch, topicsInfo, topicThreads]);
|
||||||
: forumTopicsById;
|
|
||||||
|
|
||||||
return [Object.keys(result).map(Number), result];
|
|
||||||
}, [forumId, topicSearch, forumTopicsById]);
|
|
||||||
|
|
||||||
const handleHeaderBackClick = useLastCallback(() => {
|
const handleHeaderBackClick = useLastCallback(() => {
|
||||||
setForumId(undefined);
|
setForumId(undefined);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user