Skip to content

Commit 939d75a

Browse files
committed
feat: refactor ListingComponent to use fetchData function and update props
1 parent 995ecec commit 939d75a

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client'
2+
13
import React, { useEffect, useReducer, useRef, useState } from 'react';
24
import Image from 'next/image';
35
import { useRouter } from 'next/navigation';
@@ -20,6 +22,7 @@ import { Icons } from '@/components/icons';
2022
import { Loading } from '@/components/loading';
2123
import Filter from '../datasets/components/FIlter/Filter';
2224
import Styles from '../datasets/dataset.module.scss';
25+
import { fetchData } from '@/fetch';
2326

2427
// Interfaces
2528
interface Bucket {
@@ -185,11 +188,7 @@ const useUrlParams = (
185188

186189
// Listing Component Props
187190
interface ListingProps {
188-
fetchDatasets: (variables: string) => Promise<{
189-
results: any[];
190-
total: number;
191-
aggregations: Aggregations;
192-
}>;
191+
type: string;
193192
breadcrumbData?: { href: string; label: string }[];
194193
headerComponent?: React.ReactNode;
195194
categoryName?: string;
@@ -200,7 +199,7 @@ interface ListingProps {
200199
}
201200

202201
const ListingComponent: React.FC<ListingProps> = ({
203-
fetchDatasets,
202+
type,
204203
breadcrumbData,
205204
headerComponent,
206205
categoryName,
@@ -229,7 +228,7 @@ const ListingComponent: React.FC<ListingProps> = ({
229228
if (variables) {
230229
const currentFetchId = ++latestFetchId.current;
231230

232-
fetchDatasets(variables)
231+
fetchData(type,variables)
233232
.then((res) => {
234233
// Only set if this is the latest call
235234
if (currentFetchId === latestFetchId.current) {
@@ -240,7 +239,7 @@ const ListingComponent: React.FC<ListingProps> = ({
240239
console.error(err);
241240
});
242241
}
243-
}, [variables, fetchDatasets]);
242+
}, [variables, type]);
244243

245244
const [hasMounted, setHasMounted] = useState(false);
246245

0 commit comments

Comments
 (0)