Do not expand timelines while loading

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-08-25 23:44:28 +02:00
parent 7ee99288e0
commit 4b489ed524

View file

@ -179,45 +179,51 @@ const handleTimelineExpand = (timelineId: string, fn: Promise<PaginatedResponse<
};
const fetchHomeTimeline = (expand = false, done = noOp) =>
(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<string, any> = {}, 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<string, any> = {}, 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<string, any> = {}, 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<string, any> = {}, 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<strin
if (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).timelines.groupTimeline(groupId, params);
return dispatch(handleTimelineExpand(timelineId, fn, false, done));
};
const fetchHashtagTimeline = (hashtag: string, { tags }: Record<string, any> = {}, 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<string, any> = {
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);