diff --git a/src/actions/accounts.ts b/src/actions/accounts.ts index 04c88e8cb..da241ac9b 100644 --- a/src/actions/accounts.ts +++ b/src/actions/accounts.ts @@ -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))); }; diff --git a/src/actions/admin.ts b/src/actions/admin.ts index b2d53b2c5..c2af75466 100644 --- a/src/actions/admin.ts +++ b/src/actions/admin.ts @@ -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 }), ); diff --git a/src/actions/bookmarks.ts b/src/actions/bookmarks.ts index 25154bd6f..e418d295d 100644 --- a/src/actions/bookmarks.ts +++ b/src/actions/bookmarks.ts @@ -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)); }); diff --git a/src/actions/conversations.ts b/src/actions/conversations.ts index 4e9d4a8af..6a91a5ba9 100644 --- a/src/actions/conversations.ts +++ b/src/actions/conversations.ts @@ -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 = {}) => (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, item: APIEntity) => aggr.concat(item.accounts), []))); dispatch(importFetchedStatuses(response.json.map((item: Record) => 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))); }; diff --git a/src/actions/domain-blocks.ts b/src/actions/domain-blocks.ts index 455cd5363..9f597b957 100644 --- a/src/actions/domain-blocks.ts +++ b/src/actions/domain-blocks.ts @@ -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)); }); diff --git a/src/actions/events.ts b/src/actions/events.ts index 8d01c2ba6..6b0f313aa 100644 --- a/src/actions/events.ts +++ b/src/actions/events.ts @@ -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 }); diff --git a/src/actions/favourites.ts b/src/actions/favourites.ts index e3c225187..3cf175101 100644 --- a/src/actions/favourites.ts +++ b/src/actions/favourites.ts @@ -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)); }); diff --git a/src/actions/groups.ts b/src/actions/groups.ts index 9ec216210..9dc582b6b 100644 --- a/src/actions/groups.ts +++ b/src/actions/groups.ts @@ -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)); }); diff --git a/src/actions/interactions.ts b/src/actions/interactions.ts index 9534f5bba..fd8ff8ced 100644 --- a/src/actions/interactions.ts +++ b/src/actions/interactions.ts @@ -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)); }); diff --git a/src/actions/notifications.ts b/src/actions/notifications.ts index cc7a9419f..539bdbf80 100644 --- a/src/actions/notifications.ts +++ b/src/actions/notifications.ts @@ -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 = {}, 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 = {}, 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 => { diff --git a/src/actions/scheduled-statuses.ts b/src/actions/scheduled-statuses.ts index 83efee910..b33cc1e8f 100644 --- a/src/actions/scheduled-statuses.ts +++ b/src/actions/scheduled-statuses.ts @@ -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)); }); diff --git a/src/actions/search.ts b/src/actions/search.ts index 52d27cf1b..fc689ea03 100644 --- a/src/actions/search.ts +++ b/src/actions/search.ts @@ -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)); diff --git a/src/actions/status-quotes.ts b/src/actions/status-quotes.ts index d51afe7d9..796b46828 100644 --- a/src/actions/status-quotes.ts +++ b/src/actions/status-quotes.ts @@ -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({ diff --git a/src/actions/suggestions.ts b/src/actions/suggestions.ts index c3952b967..483c2f1cb 100644 --- a/src/actions/suggestions.ts +++ b/src/actions/suggestions.ts @@ -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 = {}) => 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 }); diff --git a/src/actions/tags.ts b/src/actions/tags.ts index 58fe94400..4cc4a1c96 100644 --- a/src/actions/tags.ts +++ b/src/actions/tags.ts @@ -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)); }); diff --git a/src/queries/suggestions.ts b/src/queries/suggestions.ts index 55f089d98..0d74f86d8 100644 --- a/src/queries/suggestions.ts +++ b/src/queries/suggestions.ts @@ -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(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(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);