Replaced Array.at() for better browser compatibility (#20315)

fixes https://linear.app/tryghost/issue/SLO-125

- Array.at() has been introduced in ECMAScript 2022 and is currently not
supported by older browsers, e.g. Safari < 15.4
This commit is contained in:
Sag 2024-06-04 08:20:32 +02:00 committed by GitHub
parent 72a00b5fcc
commit 9b7f1be740
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 5 additions and 5 deletions

View File

@ -78,7 +78,7 @@ export const useBrowseActions = createInfiniteQuery<ActionsList>({
}
});
const meta = pages.at(-1)!.meta;
const meta = pages[pages.length - 1].meta;
return {
actions: actions.reverse(),

View File

@ -61,7 +61,7 @@ export const useBrowseNewsletters = createInfiniteQuery<NewslettersResponseType
returnData: (originalData) => {
const {pages} = originalData as InfiniteData<NewslettersResponseType>;
const newsletters = pages.flatMap(page => page.newsletters);
const meta = pages.at(-1)!.meta;
const meta = pages[pages.length - 1].meta;
return {
newsletters: newsletters,

View File

@ -41,7 +41,7 @@ export const useBrowseTiers = createInfiniteQuery<TiersResponseType & {isEnd: bo
returnData: (originalData) => {
const {pages} = originalData as InfiniteData<TiersResponseType>;
const tiers = pages.flatMap(page => page.tiers);
const meta = pages.at(-1)!.meta;
const meta = pages[pages.length - 1].meta;
return {
tiers,

View File

@ -76,7 +76,7 @@ export const useBrowseUsers = createInfiniteQuery<UsersResponseType & {isEnd: bo
returnData: (originalData) => {
const {pages} = originalData as InfiniteData<UsersResponseType>;
const users = pages.flatMap(page => page.users);
const meta = pages.at(-1)!.meta;
const meta = pages[pages.length - 1].meta;
return {
users: users,

View File

@ -10,7 +10,7 @@ export const insertToQueryCache = <ResponseData>(field: string, recordsToInsert?
if (typeof currentData === 'object' && 'pages' in currentData) {
const {pages} = currentData as InfiniteData<ResponseData>;
const lastPage = pages.at(-1)!;
const lastPage = pages[pages.length - 1];
return {
...currentData,
pages: pages.slice(0, -1).concat({