diff --git a/src/actions/timelines.ts b/src/actions/timelines.ts index ece5183f8..8f7624a54 100644 --- a/src/actions/timelines.ts +++ b/src/actions/timelines.ts @@ -179,45 +179,51 @@ const handleTimelineExpand = (timelineId: string, fn: Promise - (dispatch: AppDispatch, getState: () => RootState) => { + async (dispatch: AppDispatch, getState: () => RootState) => { const state = getState(); const params: HomeTimelineParams = {}; if (getSettings(state).get('autoTranslate')) params.language = getLocale(state); + if (expand && state.timelines.get('home')?.isLoading) return; + const fn = (expand && state.timelines.get('home')?.next?.()) || getClient(state).timelines.homeTimeline(params); return dispatch(handleTimelineExpand('home', fn, false, done)); }; const fetchPublicTimeline = ({ onlyMedia, local, instance }: Record = {}, expand = false, done = noOp) => - (dispatch: AppDispatch, getState: () => RootState) => { + async (dispatch: AppDispatch, getState: () => RootState) => { const state = getState(); const timelineId = `${instance ? 'remote' : 'public'}${local ? ':local' : ''}${onlyMedia ? ':media' : ''}${instance ? `:${instance}` : ''}`; const params: PublicTimelineParams = { only_media: onlyMedia, local: instance ? false : local, instance }; if (getSettings(state).get('autoTranslate')) params.language = getLocale(state); + if (expand && state.timelines.get(timelineId)?.isLoading) return; + const fn = (expand && state.timelines.get(timelineId)?.next?.()) || getClient(state).timelines.publicTimeline(params); return dispatch(handleTimelineExpand(timelineId, fn, false, done)); }; const fetchBubbleTimeline = ({ onlyMedia }: Record = {}, expand = false, done = noOp) => - (dispatch: AppDispatch, getState: () => RootState) => { + async (dispatch: AppDispatch, getState: () => RootState) => { const state = getState(); const timelineId = `bubble${onlyMedia ? ':media' : ''}`; const params: PublicTimelineParams = { only_media: onlyMedia }; if (getSettings(state).get('autoTranslate')) params.language = getLocale(state); + if (expand && state.timelines.get(timelineId)?.isLoading) return; + const fn = (expand && state.timelines.get(timelineId)?.next?.()) || getClient(state).timelines.bubbleTimeline(params); return dispatch(handleTimelineExpand(timelineId, fn, false, done)); }; const fetchAccountTimeline = (accountId: string, { exclude_replies, pinned, only_media, limit }: Record = {}, expand = false, done = noOp) => - (dispatch: AppDispatch, getState: () => RootState) => { + async (dispatch: AppDispatch, getState: () => RootState) => { const state = getState(); const timelineId = `account:${accountId}${!exclude_replies ? ':with_replies' : ''}${pinned ? ':pinned' : only_media ? ':media' : ''}`; @@ -225,26 +231,30 @@ const fetchAccountTimeline = (accountId: string, { exclude_replies, pinned, only if (pinned || only_media) params.with_muted = true; if (getSettings(state).get('autoTranslate')) params.language = getLocale(state); + if (expand && state.timelines.get(timelineId)?.isLoading) return; + const fn = (expand && state.timelines.get(timelineId)?.next?.()) || getClient(state).accounts.getAccountStatuses(accountId, params); return dispatch(handleTimelineExpand(timelineId, fn, false, done)); }; const fetchListTimeline = (listId: string, expand = false, done = noOp) => - (dispatch: AppDispatch, getState: () => RootState) => { + async (dispatch: AppDispatch, getState: () => RootState) => { const state = getState(); const timelineId = `list:${listId}`; const params: ListTimelineParams = {}; if (getSettings(state).get('autoTranslate')) params.language = getLocale(state); + if (expand && state.timelines.get(timelineId)?.isLoading) return; + const fn = (expand && state.timelines.get(timelineId)?.next?.()) || getClient(state).timelines.listTimeline(listId, params); return dispatch(handleTimelineExpand(timelineId, fn, false, done)); }; const fetchGroupTimeline = (groupId: string, { only_media, limit }: Record = {}, expand = false, done = noOp) => - (dispatch: AppDispatch, getState: () => RootState) => { + async (dispatch: AppDispatch, getState: () => RootState) => { const state = getState(); const timelineId = `group:${groupId}${only_media ? ':media' : ''}`; @@ -252,13 +262,15 @@ const fetchGroupTimeline = (groupId: string, { only_media, limit }: Record = {}, expand = false, done = noOp) => - (dispatch: AppDispatch, getState: () => RootState) => { + async (dispatch: AppDispatch, getState: () => RootState) => { const state = getState(); const timelineId = `hashtag:${hashtag}`; @@ -268,6 +280,8 @@ const fetchHashtagTimeline = (hashtag: string, { tags }: Record = { none: parseTags(tags, 'none'), }; + if (expand && state.timelines.get(timelineId)?.isLoading) return; + if (getSettings(state).get('autoTranslate')) params.language = getLocale(state); const fn = (expand && state.timelines.get(timelineId)?.next?.()) || getClient(state).timelines.hashtagTimeline(hashtag, params);