Simplify how GlobalThreads fetches threads (#26984)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ada9c64658
Коммит
3e734ee949
@@ -9,7 +9,7 @@ import {useIntl} from 'react-intl';
|
|||||||
import {useSelector, useDispatch, shallowEqual} from 'react-redux';
|
import {useSelector, useDispatch, shallowEqual} from 'react-redux';
|
||||||
import {Link, useRouteMatch} from 'react-router-dom';
|
import {Link, useRouteMatch} from 'react-router-dom';
|
||||||
|
|
||||||
import {getThreadCounts, getThreads} from 'mattermost-redux/actions/threads';
|
import {getThreadCounts, getThreadsForCurrentTeam} from 'mattermost-redux/actions/threads';
|
||||||
import {getPost} from 'mattermost-redux/selectors/entities/posts';
|
import {getPost} from 'mattermost-redux/selectors/entities/posts';
|
||||||
import {
|
import {
|
||||||
getThreadOrderInCurrentTeam,
|
getThreadOrderInCurrentTeam,
|
||||||
@@ -30,7 +30,7 @@ import LocalStorageStore from 'stores/local_storage_store';
|
|||||||
import LoadingScreen from 'components/loading_screen';
|
import LoadingScreen from 'components/loading_screen';
|
||||||
import NoResultsIndicator from 'components/no_results_indicator';
|
import NoResultsIndicator from 'components/no_results_indicator';
|
||||||
|
|
||||||
import {Constants, PreviousViewedTypes} from 'utils/constants';
|
import {PreviousViewedTypes} from 'utils/constants';
|
||||||
|
|
||||||
import type {GlobalState} from 'types/store/index';
|
import type {GlobalState} from 'types/store/index';
|
||||||
import {LhsItemType, LhsPage} from 'types/store/lhs';
|
import {LhsItemType, LhsPage} from 'types/store/lhs';
|
||||||
@@ -93,19 +93,6 @@ const GlobalThreads = () => {
|
|||||||
|
|
||||||
const [isLoading, setLoading] = useState(isEmptyList);
|
const [isLoading, setLoading] = useState(isEmptyList);
|
||||||
|
|
||||||
const fetchThreads = useCallback(async (unread): Promise<{data: any}> => {
|
|
||||||
await dispatch(getThreads(
|
|
||||||
currentUserId,
|
|
||||||
currentTeamId,
|
|
||||||
{
|
|
||||||
unread,
|
|
||||||
perPage: Constants.THREADS_PAGE_SIZE,
|
|
||||||
},
|
|
||||||
));
|
|
||||||
|
|
||||||
return {data: true};
|
|
||||||
}, [currentUserId, currentTeamId]);
|
|
||||||
|
|
||||||
const isOnlySelectedThreadInList = (list: string[]) => {
|
const isOnlySelectedThreadInList = (list: string[]) => {
|
||||||
return selectedThreadId && list.length === 1 && list[0] === selectedThreadId;
|
return selectedThreadId && list.length === 1 && list[0] === selectedThreadId;
|
||||||
};
|
};
|
||||||
@@ -118,17 +105,17 @@ const GlobalThreads = () => {
|
|||||||
|
|
||||||
// this is needed to jump start threads fetching
|
// this is needed to jump start threads fetching
|
||||||
if (shouldLoadThreads) {
|
if (shouldLoadThreads) {
|
||||||
promises.push(fetchThreads(false));
|
promises.push(dispatch(getThreadsForCurrentTeam({unread: false})));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter === ThreadFilter.unread && shouldLoadUnreadThreads) {
|
if (filter === ThreadFilter.unread && shouldLoadUnreadThreads) {
|
||||||
promises.push(fetchThreads(true));
|
promises.push(dispatch(getThreadsForCurrentTeam({unread: false})));
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(promises).then(() => {
|
Promise.all(promises).then(() => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
}, [fetchThreads, filter, threadIds, unreadThreadIds]);
|
}, [filter, threadIds, unreadThreadIds]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedThread && !selectedPost && !isLoading) {
|
if (!selectedThread && !selectedPost && !isLoading) {
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import {shallow} from 'enzyme';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import type {ComponentProps} from 'react';
|
import type {ComponentProps} from 'react';
|
||||||
|
|
||||||
import {getThreads} from 'mattermost-redux/actions/threads';
|
import {getThreadsForCurrentTeam} from 'mattermost-redux/actions/threads';
|
||||||
|
|
||||||
import {openModal} from 'actions/views/modals';
|
import {openModal} from 'actions/views/modals';
|
||||||
|
|
||||||
import Header from 'components/widgets/header';
|
import Header from 'components/widgets/header';
|
||||||
|
|
||||||
import {Constants, WindowSizes} from 'utils/constants';
|
import {WindowSizes} from 'utils/constants';
|
||||||
import {TestHelper} from 'utils/test_helper';
|
import {TestHelper} from 'utils/test_helper';
|
||||||
|
|
||||||
import ThreadList, {ThreadFilter} from './thread_list';
|
import ThreadList, {ThreadFilter} from './thread_list';
|
||||||
@@ -136,7 +136,7 @@ describe('components/threading/global_threads/thread_list', () => {
|
|||||||
const loadMoreItems = await handleLoadMoreItems(2, 3);
|
const loadMoreItems = await handleLoadMoreItems(2, 3);
|
||||||
|
|
||||||
expect(loadMoreItems).toEqual({data: true});
|
expect(loadMoreItems).toEqual({data: true});
|
||||||
expect(getThreads).toHaveBeenCalledWith('uid', 'tid', {unread: false, perPage: Constants.THREADS_PAGE_SIZE, before: '2'});
|
expect(getThreadsForCurrentTeam).toHaveBeenCalledWith({unread: false, before: '2'});
|
||||||
expect(setState.mock.calls).toEqual([[true], [false], [true]]);
|
expect(setState.mock.calls).toEqual([[true], [false], [true]]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {useDispatch, useSelector} from 'react-redux';
|
|||||||
import {PlaylistCheckIcon} from '@mattermost/compass-icons/components';
|
import {PlaylistCheckIcon} from '@mattermost/compass-icons/components';
|
||||||
import type {UserThread} from '@mattermost/types/threads';
|
import type {UserThread} from '@mattermost/types/threads';
|
||||||
|
|
||||||
import {getThreads, markAllThreadsInTeamRead} from 'mattermost-redux/actions/threads';
|
import {getThreadsForCurrentTeam, markAllThreadsInTeamRead} from 'mattermost-redux/actions/threads';
|
||||||
import {getInt} from 'mattermost-redux/selectors/entities/preferences';
|
import {getInt} from 'mattermost-redux/selectors/entities/preferences';
|
||||||
import {getThreadCountsInCurrentTeam} from 'mattermost-redux/selectors/entities/threads';
|
import {getThreadCountsInCurrentTeam} from 'mattermost-redux/selectors/entities/threads';
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ const ThreadList = ({
|
|||||||
before = data[startIndex - 2];
|
before = data[startIndex - 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
await dispatch(getThreads(currentUserId, currentTeamId, {unread, perPage: Constants.THREADS_PAGE_SIZE, before}));
|
await dispatch(getThreadsForCurrentTeam({unread, before}));
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setHasLoaded(true);
|
setHasLoaded(true);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import InfiniteLoader from 'react-window-infinite-loader';
|
|||||||
|
|
||||||
import type {UserThread} from '@mattermost/types/threads';
|
import type {UserThread} from '@mattermost/types/threads';
|
||||||
|
|
||||||
|
import ThreadsConstants from 'mattermost-redux/constants/threads';
|
||||||
|
|
||||||
import {Constants} from 'utils/constants';
|
import {Constants} from 'utils/constants';
|
||||||
|
|
||||||
import Row from './virtualized_thread_list_row';
|
import Row from './virtualized_thread_list_row';
|
||||||
@@ -77,7 +79,7 @@ function VirtualizedThreadList({
|
|||||||
itemCount={total}
|
itemCount={total}
|
||||||
loadMoreItems={loadMoreItems}
|
loadMoreItems={loadMoreItems}
|
||||||
isItemLoaded={isItemLoaded}
|
isItemLoaded={isItemLoaded}
|
||||||
minimumBatchSize={Constants.THREADS_PAGE_SIZE}
|
minimumBatchSize={ThreadsConstants.THREADS_PAGE_SIZE}
|
||||||
>
|
>
|
||||||
{({onItemsRendered, ref}) => {
|
{({onItemsRendered, ref}) => {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import nock from 'nock';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
getThread as fetchThread,
|
getThread as fetchThread,
|
||||||
getThreads as fetchThreads,
|
getThreadsForCurrentTeam,
|
||||||
getThreadCounts as fetchThreadCounts,
|
getThreadCounts as fetchThreadCounts,
|
||||||
} from 'mattermost-redux/actions/threads';
|
} from 'mattermost-redux/actions/threads';
|
||||||
import {Client4} from 'mattermost-redux/client';
|
import {Client4} from 'mattermost-redux/client';
|
||||||
@@ -123,7 +123,7 @@ describe('Actions.Threads', () => {
|
|||||||
expect(thread).toEqual({...mockThread, is_following: true});
|
expect(thread).toEqual({...mockThread, is_following: true});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getThreads', async () => {
|
test('getThreadsForCurrentTeam', async () => {
|
||||||
const [mockThread0, {threadId: threadId0}] = mockUserThread({uniq: 0});
|
const [mockThread0, {threadId: threadId0}] = mockUserThread({uniq: 0});
|
||||||
const [mockThread1, {threadId: threadId1}] = mockUserThread({uniq: 1});
|
const [mockThread1, {threadId: threadId1}] = mockUserThread({uniq: 1});
|
||||||
const [mockThread2, {threadId: threadId2}] = mockUserThread({uniq: 2});
|
const [mockThread2, {threadId: threadId2}] = mockUserThread({uniq: 2});
|
||||||
@@ -139,7 +139,7 @@ describe('Actions.Threads', () => {
|
|||||||
get((uri) => uri.includes(`/users/${currentUserId}/teams/${currentTeamId}/threads`)).
|
get((uri) => uri.includes(`/users/${currentUserId}/teams/${currentTeamId}/threads`)).
|
||||||
reply(200, mockResponse);
|
reply(200, mockResponse);
|
||||||
|
|
||||||
const {error, data} = await store.dispatch(fetchThreads(currentUserId, currentTeamId));
|
const {error, data} = await store.dispatch(getThreadsForCurrentTeam());
|
||||||
const state = store.getState();
|
const state = store.getState();
|
||||||
const threads = getThreadsInCurrentTeam(state);
|
const threads = getThreadsInCurrentTeam(state);
|
||||||
expect(error).toBeUndefined();
|
expect(error).toBeUndefined();
|
||||||
|
|||||||
@@ -42,9 +42,20 @@ export function fetchThreads(userId: string, teamId: string, {before = '', after
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getThreads(userId: string, teamId: string, {before = '', after = '', perPage = ThreadConstants.THREADS_CHUNK_SIZE, unread = false, extended = true} = {}): ActionFuncAsync<UserThreadList> {
|
export function getThreadsForCurrentTeam({before = '', after = '', unread = false} = {}): ActionFuncAsync<UserThreadList> {
|
||||||
return async (dispatch) => {
|
return async (dispatch, getState) => {
|
||||||
const response = await dispatch(fetchThreads(userId, teamId, {before, after, perPage, unread, totalsOnly: false, threadsOnly: true, extended}));
|
const userId = getCurrentUserId(getState());
|
||||||
|
const teamId = getCurrentTeamId(getState());
|
||||||
|
|
||||||
|
const response = await dispatch(fetchThreads(userId, teamId, {
|
||||||
|
before,
|
||||||
|
after,
|
||||||
|
perPage: ThreadConstants.THREADS_PAGE_SIZE,
|
||||||
|
unread,
|
||||||
|
totalsOnly: false,
|
||||||
|
threadsOnly: true,
|
||||||
|
extended: true,
|
||||||
|
}));
|
||||||
|
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
THREADS_CHUNK_SIZE: 20,
|
THREADS_CHUNK_SIZE: 20,
|
||||||
|
THREADS_PAGE_SIZE: 25,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2023,7 +2023,6 @@ export const Constants = {
|
|||||||
MAX_ATTACHMENT_FOOTER_LENGTH: 300,
|
MAX_ATTACHMENT_FOOTER_LENGTH: 300,
|
||||||
ACCEPT_STATIC_IMAGE: '.jpeg,.jpg,.png,.bmp',
|
ACCEPT_STATIC_IMAGE: '.jpeg,.jpg,.png,.bmp',
|
||||||
ACCEPT_EMOJI_IMAGE: '.jpeg,.jpg,.png,.gif',
|
ACCEPT_EMOJI_IMAGE: '.jpeg,.jpg,.png,.gif',
|
||||||
THREADS_PAGE_SIZE: 25,
|
|
||||||
THREADS_LOADING_INDICATOR_ITEM_ID: 'threads_loading_indicator_item_id',
|
THREADS_LOADING_INDICATOR_ITEM_ID: 'threads_loading_indicator_item_id',
|
||||||
THREADS_NO_RESULTS_ITEM_ID: 'threads_no_results_item_id',
|
THREADS_NO_RESULTS_ITEM_ID: 'threads_no_results_item_id',
|
||||||
TRIAL_MODAL_AUTO_SHOWN: 'trial_modal_auto_shown',
|
TRIAL_MODAL_AUTO_SHOWN: 'trial_modal_auto_shown',
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user