diff --git a/src/pages/Products/components/ProductData.tsx b/src/pages/Products/components/ProductData.tsx
new file mode 100644
index 0000000..cea69bb
--- /dev/null
+++ b/src/pages/Products/components/ProductData.tsx
@@ -0,0 +1,48 @@
+import { Table } from '../../../components';
+import { Product } from '../types';
+
+export const ProductTable = ({ product }: { product: Product }) => (
+
+
+
+ Product Properties
+
+ Property Values
+
+
+
+
+ Countries
+
+ {product.countries.split(',').join(', ')}
+
+
+
+ Brands
+
+ {product.brands}
+
+
+
+ Ingredients
+
+
+ {product.ingredients_text_en || product.ingredients_text}
+
+
+
+
+ Macro Elements
+
+
+
+ - Prots - {product.nutriments.proteins_100g}
+ - Carbs - {product.nutriments.carbohydrates_100g}
+ - Fats - {product.nutriments.fat_100g}
+ - Energy - {product.nutriments['energy-kcal_100g']}
+
+
+
+
+
+);
diff --git a/src/pages/Products/components/ProductDetails.tsx b/src/pages/Products/components/ProductDetails.tsx
index 4d12a80..6f910d4 100644
--- a/src/pages/Products/components/ProductDetails.tsx
+++ b/src/pages/Products/components/ProductDetails.tsx
@@ -6,100 +6,28 @@ import {
useSearchParams,
} from 'react-router-dom';
import ApiClient from '../../../app/ApiClient';
-import { Table } from '../../../components';
+import { FlexContainer } from '../../../components';
+import { ProductTable } from './ProductData';
import { Product } from '../types';
-import { useMemo } from 'react';
+
export const ProductDetails = () => {
const { product } = useLoaderData() as { product: Product };
const navigation = useNavigation();
+ const isLoading = navigation.state === 'loading';
const navigator = useNavigate();
const [searchParams] = useSearchParams();
-
- const formattedData = useMemo(() => {
- return [
- [
- { id: '1', value: 'Countries' },
- { id: '2', value: product.countries.split(',').join(', ') },
- ],
- [
- { id: 1, value: 'Brands' },
- { id: 2, value: product.brands },
- ],
- [
- { id: 1, value: 'Ingredients' },
- {
- id: 2,
- value: product.ingredients_text_en || product.ingredients_text,
- },
- ],
- [
- { id: 1, value: 'Macro Elements' },
- {
- id: 2,
- value: (
-
- - Prots - {product.nutriments.proteins_100g}
- - Carbs - {product.nutriments.carbohydrates_100g}
- - Fats - {product.nutriments.fat_100g}
- - Energy - {product.nutriments['energy-kcal_100g']}
-
- ),
- },
- ],
- ];
- }, [product]);
-
+ if (isLoading && product) {
+ return;
+ }
return (
-
-
- {!product ? (
-
Product details are not available
- ) : (
- <>
-
-
- {product.product_name}
-
-
-
- {navigation.state === 'loading' ? (
-
- Searching ...
-
- ) : (
-
- )}
- >
- )}
-
-
+
navigator(`/products?${searchParams.toString()}`)}
+ >
+ {isLoading && !product && 'Loading...'}
+ {!isLoading && !product && 'Data is not available'}
+ {!isLoading && product && }
+
);
};
diff --git a/src/pages/Products/components/ProductsContainer.tsx b/src/pages/Products/components/ProductsContainer.tsx
index 1382a66..552a2ef 100644
--- a/src/pages/Products/components/ProductsContainer.tsx
+++ b/src/pages/Products/components/ProductsContainer.tsx
@@ -1,5 +1,5 @@
import { Link, useSearchParams, useParams } from 'react-router-dom';
-import { Card, Container } from '../../../components';
+import { Card, GridContainer } from '../../../components';
import { Product } from '../types';
export const ProductsContainer = (props: {
@@ -17,31 +17,25 @@ export const ProductsContainer = (props: {
return
{props.error}
;
}
+ const getNextUrl = (productId: string) => {
+ return `${
+ productId === id ? `/products` : `/products/${productId}`
+ }?${searchParams.toString()}`;
+ };
+
return (
-
+
{!props.data.length && No results
}
- {props.data.map((product) =>
- String(product.id) !== id ? (
-
-
-
- ) : (
+ {props.data.map((product) => (
+
- )
- )}
-
+
+ ))}
+
);
};