Prefer getNextLink

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-06-13 23:55:37 +02:00
parent b8a19ff794
commit 8029fc0e95
16 changed files with 92 additions and 92 deletions

View file

@ -4,7 +4,7 @@ import { selectAccount } from 'soapbox/selectors';
import { isLoggedIn } from 'soapbox/utils/auth';
import { getFeatures, parseVersion, PLEROMA } from 'soapbox/utils/features';
import api, { getLinks, type PlfeResponse } from '../api';
import api, { getNextLink, type PlfeResponse } from '../api';
import {
importFetchedAccount,
@ -450,10 +450,10 @@ const fetchFollowers = (id: string) =>
return api(getState)(`/api/v1/accounts/${id}/followers`)
.then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json));
dispatch(fetchFollowersSuccess(id, response.json, next ? next.uri : null));
dispatch(fetchFollowersSuccess(id, response.json, next || null));
dispatch(fetchRelationships(response.json.map((item: APIEntity) => item.id)));
})
.catch(error => {
@ -493,10 +493,10 @@ const expandFollowers = (id: string) =>
return api(getState)(url)
.then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json));
dispatch(expandFollowersSuccess(id, response.json, next ? next.uri : null));
dispatch(expandFollowersSuccess(id, response.json, next || null));
dispatch(fetchRelationships(response.json.map((item: APIEntity) => item.id)));
})
.catch(error => {
@ -528,10 +528,10 @@ const fetchFollowing = (id: string) =>
return api(getState)(`/api/v1/accounts/${id}/following`)
.then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json));
dispatch(fetchFollowingSuccess(id, response.json, next ? next.uri : null));
dispatch(fetchFollowingSuccess(id, response.json, next || null));
dispatch(fetchRelationships(response.json.map((item: APIEntity) => item.id)));
})
.catch(error => {
@ -571,10 +571,10 @@ const expandFollowing = (id: string) =>
return api(getState)(url)
.then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json));
dispatch(expandFollowingSuccess(id, response.json, next ? next.uri : null));
dispatch(expandFollowingSuccess(id, response.json, next || null));
dispatch(fetchRelationships(response.json.map((item: APIEntity) => item.id)));
})
.catch(error => {
@ -647,9 +647,9 @@ const fetchFollowRequests = () =>
return api(getState)('/api/v1/follow_requests')
.then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json));
dispatch(fetchFollowRequestsSuccess(response.json, next ? next.uri : null));
dispatch(fetchFollowRequestsSuccess(response.json, next || null));
})
.catch(error => dispatch(fetchFollowRequestsFail(error)));
};
@ -683,9 +683,9 @@ const expandFollowRequests = () =>
return api(getState)(url)
.then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json));
dispatch(expandFollowRequestsSuccess(response.json, next ? next.uri : null));
dispatch(expandFollowRequestsSuccess(response.json, next || null));
})
.catch(error => dispatch(expandFollowRequestsFail(error)));
};

View file

@ -5,7 +5,7 @@ import { accountIdsToAccts } from 'soapbox/selectors';
import { filterBadges, getTagDiff } from 'soapbox/utils/badges';
import { getFeatures } from 'soapbox/utils/features';
import api, { getLinks } from '../api';
import api, { getNextLink } from '../api';
import type { AppDispatch, RootState } from 'soapbox/store';
import type { APIEntity } from 'soapbox/types/entities';
@ -217,7 +217,7 @@ const fetchMastodonUsers = (filters: string[], page: number, query: string | nul
return api(getState)(next || '/api/v1/admin/accounts', { params })
.then((response) => {
const accounts = response.json;
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
const count = next
? page * pageSize + 1
@ -225,8 +225,8 @@ const fetchMastodonUsers = (filters: string[], page: number, query: string | nul
dispatch(importFetchedAccounts(accounts.map(({ account }: APIEntity) => account)));
dispatch(fetchRelationships(accounts.map((account: APIEntity) => account.id)));
dispatch({ type: ADMIN_USERS_FETCH_SUCCESS, users: accounts, count, pageSize, filters, page, next: next?.uri || false });
return { users: accounts, count, pageSize, next: next?.uri || false };
dispatch({ type: ADMIN_USERS_FETCH_SUCCESS, users: accounts, count, pageSize, filters, page, next: next || false });
return { users: accounts, count, pageSize, next: next || false };
}).catch(error =>
dispatch({ type: ADMIN_USERS_FETCH_FAIL, error, filters, page, pageSize }),
);

View file

@ -1,4 +1,4 @@
import api, { getLinks } from '../api';
import api, { getNextLink } from '../api';
import { importFetchedStatuses } from './importer';
@ -24,9 +24,9 @@ const fetchBookmarkedStatuses = (folderId?: string) =>
dispatch(fetchBookmarkedStatusesRequest(folderId));
return api(getState)(`/api/v1/bookmarks${folderId ? `?folder_id=${folderId}` : ''}`).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedStatuses(response.json));
return dispatch(fetchBookmarkedStatusesSuccess(response.json, next ? next.uri : null, folderId));
return dispatch(fetchBookmarkedStatusesSuccess(response.json, next || null, folderId));
}).catch(error => {
dispatch(fetchBookmarkedStatusesFail(error, folderId));
});
@ -62,9 +62,9 @@ const expandBookmarkedStatuses = (folderId?: string) =>
dispatch(expandBookmarkedStatusesRequest(folderId));
return api(getState)(url).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedStatuses(response.json));
return dispatch(expandBookmarkedStatusesSuccess(response.json, next ? next.uri : null, folderId));
return dispatch(expandBookmarkedStatusesSuccess(response.json, next || null, folderId));
}).catch(error => {
dispatch(expandBookmarkedStatusesFail(error, folderId));
});

View file

@ -1,6 +1,6 @@
import { isLoggedIn } from 'soapbox/utils/auth';
import api, { getLinks } from '../api';
import api, { getNextLink } from '../api';
import {
importFetchedAccounts,
@ -55,11 +55,11 @@ const expandConversations = ({ maxId }: Record<string, any> = {}) => (dispatch:
api(getState)('/api/v1/conversations', { params })
.then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json.reduce((aggr: Array<APIEntity>, item: APIEntity) => aggr.concat(item.accounts), [])));
dispatch(importFetchedStatuses(response.json.map((item: Record<string, any>) => item.last_status).filter((x?: APIEntity) => !!x)));
dispatch(expandConversationsSuccess(response.json, next ? next.uri : null, isLoadingRecent));
dispatch(expandConversationsSuccess(response.json, next || null, isLoadingRecent));
})
.catch(err => dispatch(expandConversationsFail(err)));
};

View file

@ -1,7 +1,7 @@
import { Entities } from 'soapbox/entity-store/entities';
import { isLoggedIn } from 'soapbox/utils/auth';
import api, { getLinks } from '../api';
import api, { getNextLink } from '../api';
import type { EntityStore } from 'soapbox/entity-store/types';
import type { Account } from 'soapbox/schemas';
@ -101,8 +101,8 @@ const fetchDomainBlocks = () =>
dispatch(fetchDomainBlocksRequest());
api(getState)('/api/v1/domain_blocks').then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(fetchDomainBlocksSuccess(response.json, next ? next.uri : null));
const next = getNextLink(response);
dispatch(fetchDomainBlocksSuccess(response.json, next || null));
}).catch(err => {
dispatch(fetchDomainBlocksFail(err));
});
@ -136,8 +136,8 @@ const expandDomainBlocks = () =>
dispatch(expandDomainBlocksRequest());
api(getState)(url).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(expandDomainBlocksSuccess(response.json, next ? next.uri : null));
const next = getNextLink(response);
dispatch(expandDomainBlocksSuccess(response.json, next || null));
}).catch(err => {
dispatch(expandDomainBlocksFail(err));
});

View file

@ -1,6 +1,6 @@
import { defineMessages, IntlShape } from 'react-intl';
import api, { getLinks } from 'soapbox/api';
import api, { getNextLink } from 'soapbox/api';
import toast from 'soapbox/toast';
import { importFetchedAccounts, importFetchedStatus, importFetchedStatuses } from './importer';
@ -344,9 +344,9 @@ const fetchEventParticipations = (id: string) =>
dispatch(fetchEventParticipationsRequest(id));
return api(getState)(`/api/v1/pleroma/events/${id}/participations`).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json));
return dispatch(fetchEventParticipationsSuccess(id, response.json, next ? next.uri : null));
return dispatch(fetchEventParticipationsSuccess(id, response.json, next || null));
}).catch(error => {
dispatch(fetchEventParticipationsFail(id, error));
});
@ -381,9 +381,9 @@ const expandEventParticipations = (id: string) =>
dispatch(expandEventParticipationsRequest(id));
return api(getState)(url).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json));
return dispatch(expandEventParticipationsSuccess(id, response.json, next ? next.uri : null));
return dispatch(expandEventParticipationsSuccess(id, response.json, next || null));
}).catch(error => {
dispatch(expandEventParticipationsFail(id, error));
});
@ -412,9 +412,9 @@ const fetchEventParticipationRequests = (id: string) =>
dispatch(fetchEventParticipationRequestsRequest(id));
return api(getState)(`/api/v1/pleroma/events/${id}/participation_requests`).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json.map(({ account }: APIEntity) => account)));
return dispatch(fetchEventParticipationRequestsSuccess(id, response.json, next ? next.uri : null));
return dispatch(fetchEventParticipationRequestsSuccess(id, response.json, next || null));
}).catch(error => {
dispatch(fetchEventParticipationRequestsFail(id, error));
});
@ -449,9 +449,9 @@ const expandEventParticipationRequests = (id: string) =>
dispatch(expandEventParticipationRequestsRequest(id));
return api(getState)(url).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json.map(({ account }: APIEntity) => account)));
return dispatch(expandEventParticipationRequestsSuccess(id, response.json, next ? next.uri : null));
return dispatch(expandEventParticipationRequestsSuccess(id, response.json, next || null));
}).catch(error => {
dispatch(expandEventParticipationRequestsFail(id, error));
});
@ -580,12 +580,12 @@ const fetchRecentEvents = () =>
dispatch({ type: RECENT_EVENTS_FETCH_REQUEST });
api(getState)('/api/v1/timelines/public?only_events=true').then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedStatuses(response.json));
dispatch({
type: RECENT_EVENTS_FETCH_SUCCESS,
statuses: response.json,
next: next ? next.uri : null,
next: next || null,
});
}).catch(error => {
dispatch({ type: RECENT_EVENTS_FETCH_FAIL, error });
@ -601,12 +601,12 @@ const fetchJoinedEvents = () =>
dispatch({ type: JOINED_EVENTS_FETCH_REQUEST });
api(getState)('/api/v1/pleroma/events/joined_events').then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedStatuses(response.json));
dispatch({
type: JOINED_EVENTS_FETCH_SUCCESS,
statuses: response.json,
next: next ? next.uri : null,
next: next || null,
});
}).catch(error => {
dispatch({ type: JOINED_EVENTS_FETCH_FAIL, error });

View file

@ -1,6 +1,6 @@
import { isLoggedIn } from 'soapbox/utils/auth';
import api, { getLinks } from '../api';
import api, { getNextLink } from '../api';
import { importFetchedStatuses } from './importer';
@ -34,9 +34,9 @@ const fetchFavouritedStatuses = () =>
dispatch(fetchFavouritedStatusesRequest());
api(getState)('/api/v1/favourites').then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedStatuses(response.json));
dispatch(fetchFavouritedStatusesSuccess(response.json, next ? next.uri : null));
dispatch(fetchFavouritedStatusesSuccess(response.json, next || null));
}).catch(error => {
dispatch(fetchFavouritedStatusesFail(error));
});
@ -73,9 +73,9 @@ const expandFavouritedStatuses = () =>
dispatch(expandFavouritedStatusesRequest());
api(getState)(url).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedStatuses(response.json));
dispatch(expandFavouritedStatusesSuccess(response.json, next ? next.uri : null));
dispatch(expandFavouritedStatusesSuccess(response.json, next || null));
}).catch(error => {
dispatch(expandFavouritedStatusesFail(error));
});
@ -107,9 +107,9 @@ const fetchAccountFavouritedStatuses = (accountId: string) =>
dispatch(fetchAccountFavouritedStatusesRequest(accountId));
api(getState)(`/api/v1/pleroma/accounts/${accountId}/favourites`).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedStatuses(response.json));
dispatch(fetchAccountFavouritedStatusesSuccess(accountId, response.json, next ? next.uri : null));
dispatch(fetchAccountFavouritedStatusesSuccess(accountId, response.json, next || null));
}).catch(error => {
dispatch(fetchAccountFavouritedStatusesFail(accountId, error));
});
@ -149,9 +149,9 @@ const expandAccountFavouritedStatuses = (accountId: string) =>
dispatch(expandAccountFavouritedStatusesRequest(accountId));
api(getState)(url).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedStatuses(response.json));
dispatch(expandAccountFavouritedStatusesSuccess(accountId, response.json, next ? next.uri : null));
dispatch(expandAccountFavouritedStatusesSuccess(accountId, response.json, next || null));
}).catch(error => {
dispatch(expandAccountFavouritedStatusesFail(accountId, error));
});

View file

@ -1,5 +1,5 @@
import api, { getLinks } from '../api';
import api, { getNextLink } from '../api';
import { importFetchedAccounts } from './importer';
@ -28,10 +28,10 @@ const fetchGroupBlocks = (id: string) =>
dispatch(fetchGroupBlocksRequest(id));
return api(getState)(`/api/v1/groups/${id}/blocks`).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json));
dispatch(fetchGroupBlocksSuccess(id, response.json, next ? next.uri : null));
dispatch(fetchGroupBlocksSuccess(id, response.json, next || null));
}).catch(error => {
dispatch(fetchGroupBlocksFail(id, error));
});

View file

@ -4,7 +4,7 @@ import toast, { type IToastOptions } from 'soapbox/toast';
import { isLoggedIn } from 'soapbox/utils/auth';
import { getFeatures } from 'soapbox/utils/features';
import api, { getLinks } from '../api';
import api, { getNextLink } from '../api';
import { fetchRelationships } from './accounts';
import { importFetchedAccounts, importFetchedStatus } from './importer';
@ -407,10 +407,10 @@ const fetchReblogs = (id: string) =>
dispatch(fetchReblogsRequest(id));
api(getState)(`/api/v1/statuses/${id}/reblogged_by`).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json));
dispatch(fetchRelationships(response.json.map((item: APIEntity) => item.id)));
dispatch(fetchReblogsSuccess(id, response.json, next ? next.uri : null));
dispatch(fetchReblogsSuccess(id, response.json, next || null));
}).catch(error => {
dispatch(fetchReblogsFail(id, error));
});
@ -437,10 +437,10 @@ const fetchReblogsFail = (id: string, error: unknown) => ({
const expandReblogs = (id: string, path: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
api(getState)(path).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json));
dispatch(fetchRelationships(response.json.map((item: APIEntity) => item.id)));
dispatch(expandReblogsSuccess(id, response.json, next ? next.uri : null));
dispatch(expandReblogsSuccess(id, response.json, next || null));
}).catch(error => {
dispatch(expandReblogsFail(id, error));
});
@ -466,10 +466,10 @@ const fetchFavourites = (id: string) =>
dispatch(fetchFavouritesRequest(id));
api(getState)(`/api/v1/statuses/${id}/favourited_by`).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json));
dispatch(fetchRelationships(response.json.map((item: APIEntity) => item.id)));
dispatch(fetchFavouritesSuccess(id, response.json, next ? next.uri : null));
dispatch(fetchFavouritesSuccess(id, response.json, next || null));
}).catch(error => {
dispatch(fetchFavouritesFail(id, error));
});
@ -496,10 +496,10 @@ const fetchFavouritesFail = (id: string, error: unknown) => ({
const expandFavourites = (id: string, path: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
api(getState)(path).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedAccounts(response.json));
dispatch(fetchRelationships(response.json.map((item: APIEntity) => item.id)));
dispatch(expandFavouritesSuccess(id, response.json, next ? next.uri : null));
dispatch(expandFavouritesSuccess(id, response.json, next || null));
}).catch(error => {
dispatch(expandFavouritesFail(id, error));
});

View file

@ -2,7 +2,7 @@ import IntlMessageFormat from 'intl-messageformat';
import 'intl-pluralrules';
import { defineMessages } from 'react-intl';
import api, { getLinks } from 'soapbox/api';
import api, { getNextLink } from 'soapbox/api';
import { getFilters, regexFromFilters } from 'soapbox/selectors';
import { isLoggedIn } from 'soapbox/utils/auth';
import { compareId } from 'soapbox/utils/comparators';
@ -272,7 +272,7 @@ const expandNotifications = ({ maxId }: Record<string, any> = {}, done: () => an
dispatch(expandNotificationsRequest(isLoadingMore));
return api(getState)('/api/v1/notifications', { params, signal: abortExpandNotifications.signal }).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
const entries = (response.json as APIEntity[]).reduce((acc, item) => {
if (item.account?.id) {
@ -296,7 +296,7 @@ const expandNotifications = ({ maxId }: Record<string, any> = {}, done: () => an
const deduplicatedNotifications = deduplicateNotifications(response.json);
dispatch(expandNotificationsSuccess(deduplicatedNotifications, next ? next.uri : null, isLoadingMore));
dispatch(expandNotificationsSuccess(deduplicatedNotifications, next || null, isLoadingMore));
fetchRelatedRelationships(dispatch, response.json);
done();
}).catch(error => {

View file

@ -1,6 +1,6 @@
import { getFeatures } from 'soapbox/utils/features';
import api, { getLinks } from '../api';
import api, { getNextLink } from '../api';
import type { AppDispatch, RootState } from 'soapbox/store';
import type { APIEntity } from 'soapbox/types/entities';
@ -33,8 +33,8 @@ const fetchScheduledStatuses = () =>
dispatch(fetchScheduledStatusesRequest());
api(getState)('/api/v1/scheduled_statuses').then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(fetchScheduledStatusesSuccess(response.json, next ? next.uri : null));
const next = getNextLink(response);
dispatch(fetchScheduledStatusesSuccess(response.json, next || null));
}).catch(error => {
dispatch(fetchScheduledStatusesFail(error));
});
@ -76,8 +76,8 @@ const expandScheduledStatuses = () =>
dispatch(expandScheduledStatusesRequest());
api(getState)(url).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(expandScheduledStatusesSuccess(response.json, next ? next.uri : null));
const next = getNextLink(response);
dispatch(expandScheduledStatusesSuccess(response.json, next || null));
}).catch(error => {
dispatch(expandScheduledStatusesFail(error));
});

View file

@ -1,4 +1,4 @@
import api, { getLinks } from '../api';
import api, { getNextLink } from '../api';
import { fetchRelationships } from './accounts';
import { importFetchedAccounts, importFetchedStatuses } from './importer';
@ -82,9 +82,9 @@ const submitSearch = (filter?: SearchFilter) =>
dispatch(importFetchedStatuses(response.json.statuses));
}
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(fetchSearchSuccess(response.json, value, type, next ? next.uri : null));
dispatch(fetchSearchSuccess(response.json, value, type, next || null));
dispatch(fetchRelationships(response.json.accounts.map((item: APIEntity) => item.id)));
}).catch(error => {
dispatch(fetchSearchFail(error));
@ -155,9 +155,9 @@ const expandSearch = (type: SearchFilter) => (dispatch: AppDispatch, getState: (
dispatch(importFetchedStatuses(data.statuses));
}
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(expandSearchSuccess(data, value, type, next ? next.uri : null));
dispatch(expandSearchSuccess(data, value, type, next || null));
dispatch(fetchRelationships(data.accounts.map((item: APIEntity) => item.id)));
}).catch(error => {
dispatch(expandSearchFail(error));

View file

@ -1,4 +1,4 @@
import api, { getLinks } from '../api';
import api, { getNextLink } from '../api';
import { importFetchedStatuses } from './importer';
@ -26,13 +26,13 @@ const fetchStatusQuotes = (statusId: string) =>
});
return api(getState)(`/api/v1/pleroma/statuses/${statusId}/quotes`).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedStatuses(response.json));
return dispatch({
type: STATUS_QUOTES_FETCH_SUCCESS,
statusId,
statuses: response.json,
next: next ? next.uri : null,
next: next || null,
});
}).catch(error => {
dispatch({
@ -57,13 +57,13 @@ const expandStatusQuotes = (statusId: string) =>
});
return api(getState)(url).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
const next = getNextLink(response);
dispatch(importFetchedStatuses(response.json));
dispatch({
type: STATUS_QUOTES_EXPAND_SUCCESS,
statusId,
statuses: response.json,
next: next ? next.uri : null,
next: next || null,
});
}).catch(error => {
dispatch({

View file

@ -1,7 +1,7 @@
import { isLoggedIn } from 'soapbox/utils/auth';
import { getFeatures } from 'soapbox/utils/features';
import api, { getLinks } from '../api';
import api, { getNextLink } from '../api';
import { fetchRelationships } from './accounts';
import { importFetchedAccounts } from './importer';
@ -42,7 +42,7 @@ const fetchSuggestionsV2 = (params: Record<string, any> = {}) =>
return api(getState)(next ? next : '/api/v2/suggestions', next ? {} : { params }).then((response) => {
const suggestions: APIEntity[] = response.json;
const accounts = suggestions.map(({ account }) => account);
const next = getLinks(response).refs.find(link => link.rel === 'next')?.uri;
const next = getNextLink(response) || null;
dispatch(importFetchedAccounts(accounts));
dispatch({ type: SUGGESTIONS_V2_FETCH_SUCCESS, suggestions, next, skipLoading: true });

View file

@ -1,4 +1,4 @@
import api, { getLinks } from '../api';
import api, { getNextLink } from '../api';
import type { AppDispatch, RootState } from 'soapbox/store';
import type { APIEntity } from 'soapbox/types/entities';
@ -106,8 +106,8 @@ const fetchFollowedHashtags = () => (dispatch: AppDispatch, getState: () => Root
dispatch(fetchFollowedHashtagsRequest());
api(getState)('/api/v1/followed_tags').then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(fetchFollowedHashtagsSuccess(response.json, next ? next.uri : null));
const next = getNextLink(response);
dispatch(fetchFollowedHashtagsSuccess(response.json, next || null));
}).catch(err => {
dispatch(fetchFollowedHashtagsFail(err));
});
@ -138,8 +138,8 @@ const expandFollowedHashtags = () => (dispatch: AppDispatch, getState: () => Roo
dispatch(expandFollowedHashtagsRequest());
api(getState)(url).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(expandFollowedHashtagsSuccess(response.json, next ? next.uri : null));
const next = getNextLink(response);
dispatch(expandFollowedHashtagsSuccess(response.json, next || null));
}).catch(error => {
dispatch(expandFollowedHashtagsFail(error));
});

View file

@ -2,7 +2,7 @@ import { useInfiniteQuery, useMutation, keepPreviousData } from '@tanstack/react
import { fetchRelationships } from 'soapbox/actions/accounts';
import { importFetchedAccounts } from 'soapbox/actions/importer';
import { getLinks } from 'soapbox/api';
import { getNextLink } from 'soapbox/api';
import { useApi, useAppDispatch } from 'soapbox/hooks';
import { PaginatedResult, removePageItem } from '../utils/queries';
@ -34,7 +34,7 @@ const useSuggestions = () => {
const endpoint = pageParam?.link || '/api/v2/suggestions';
const response = await api<Suggestion[]>(endpoint);
const hasMore = !!response.headers.get('link');
const nextLink = getLinks(response).refs.find(link => link.rel === 'next')?.uri;
const nextLink = getNextLink(response);
const accounts = response.json.map(({ account }) => account);
const accountIds = accounts.map((account) => account.id);
@ -92,7 +92,7 @@ const useOnboardingSuggestions = () => {
const link = pageParam?.link || '/api/v2/suggestions';
const response = await api<Suggestion[]>(link);
const hasMore = !!response.headers.get('link');
const nextLink = getLinks(response).refs.find(link => link.rel === 'next')?.uri;
const nextLink = getNextLink(response);
const accounts = response.json.map(({ account }) => account);
const accountIds = accounts.map((account) => account.id);