Skip to content

Commit 0c7148a

Browse files
committed
refactor(ListingComponent): implement fetch call optimization using useRef for latest fetch tracking
refactor(Sectors): update sector link query parameters for consistent pagination and sorting
1 parent cedba50 commit 0c7148a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

app/[locale]/(user)/components/ListingComponent.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useReducer, useState } from 'react';
1+
import React, { useEffect, useReducer, useRef, useState } from 'react';
22
import Image from 'next/image';
33
import { useRouter } from 'next/navigation';
44
import GraphqlPagination from '@/app/[locale]/dashboard/components/GraphqlPagination/graphqlPagination';
@@ -219,12 +219,18 @@ const ListingComponent: React.FC<ListingProps> = ({
219219
const datasetDetails = facets?.results ?? [];
220220

221221
useUrlParams(queryParams, setQueryParams, setVariables);
222+
const latestFetchId = useRef(0);
222223

223224
useEffect(() => {
224225
if (variables) {
226+
const currentFetchId = ++latestFetchId.current;
227+
225228
fetchDatasets(variables)
226229
.then((res) => {
227-
setFacets(res);
230+
// Only set if this is the latest call
231+
if (currentFetchId === latestFetchId.current) {
232+
setFacets(res);
233+
}
228234
})
229235
.catch((err) => {
230236
console.error(err);

app/[locale]/(user)/components/Sectors.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const Sectors = () => {
6363
<div className="mt-12 grid w-full grid-cols-1 gap-6 px-4 md:grid-cols-2 md:px-12 lg:grid-cols-3 lg:px-12">
6464
{data?.sectors.map((sectors: any) => (
6565
<Link
66-
href={`/sectors/${sectors.slug}?sectors=${capitalizeWords(sectors.slug)}`}
66+
href={`/sectors/${sectors.slug}?size=9&page=1&sort=recent&sectors=${capitalizeWords(sectors.slug)}`}
6767
key={sectors.id}
6868
>
6969
<div className="flex w-full items-center gap-5 rounded-4 bg-surfaceDefault p-7 shadow-card">

0 commit comments

Comments
 (0)