From 971d1846979760bb3bea73d3c7c802d76d46b7f6 Mon Sep 17 00:00:00 2001 From: keannu125 Date: Fri, 3 Mar 2023 12:05:29 +0800 Subject: [PATCH] Added toggle view for table or blob in Products page --- src/Components/Products/BlobView/BlobView.tsx | 29 ++++++++++ .../Products/TableView/TableView.tsx | 45 ++++++++++++++++ src/Interfaces/Interfaces.tsx | 9 ++++ src/Routes/Products/Products.tsx | 53 +++++-------------- 4 files changed, 97 insertions(+), 39 deletions(-) create mode 100644 src/Components/Products/BlobView/BlobView.tsx create mode 100644 src/Components/Products/TableView/TableView.tsx create mode 100644 src/Interfaces/Interfaces.tsx diff --git a/src/Components/Products/BlobView/BlobView.tsx b/src/Components/Products/BlobView/BlobView.tsx new file mode 100644 index 0000000..3a0cbe0 --- /dev/null +++ b/src/Components/Products/BlobView/BlobView.tsx @@ -0,0 +1,29 @@ +import * as React from "react"; + +import styles from "../../../styles"; +import { ProductList } from "../../../Interfaces/Interfaces"; + +export default function BlobView({ Products }: ProductList) { + return ( +
+ {Products.map((row) => ( +
+

{row.name}

+

ID: {row.id}

+

Last Modified: {row.last_modified}

+
+ ))} +
+ ); +} diff --git a/src/Components/Products/TableView/TableView.tsx b/src/Components/Products/TableView/TableView.tsx new file mode 100644 index 0000000..8cfda06 --- /dev/null +++ b/src/Components/Products/TableView/TableView.tsx @@ -0,0 +1,45 @@ +import * as React from "react"; +import { + Button, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, +} from "@mui/material"; +import styles from "../../../styles"; +import { ProductList } from "../../../Interfaces/Interfaces"; + +export default function TableView({ Products }: ProductList) { + return ( + + + + + Product ID + Product + Last Modified + + + + {Products.map((row) => ( + + {row.id} + {row.name} + {row.last_modified} + + ))} + +
+
+ ); +} diff --git a/src/Interfaces/Interfaces.tsx b/src/Interfaces/Interfaces.tsx new file mode 100644 index 0000000..13037cf --- /dev/null +++ b/src/Interfaces/Interfaces.tsx @@ -0,0 +1,9 @@ +export interface ProductList { + Products: Product[]; +} + +export interface Product { + id: number; + name: string; + last_modified: string; +} diff --git a/src/Routes/Products/Products.tsx b/src/Routes/Products/Products.tsx index b651bb7..bf51052 100644 --- a/src/Routes/Products/Products.tsx +++ b/src/Routes/Products/Products.tsx @@ -1,22 +1,23 @@ -import React from "react"; +import React, { useState } from "react"; import styles from "../../styles"; import { useNavigate } from "react-router-dom"; import ProductsIcon from "../../Components/Icons/ProductsIcon/ProductsIcon"; import AddIcon from "../../Components/Icons/AddIcon/AddIcon"; -import { - Button, - Table, - TableBody, - TableCell, - TableContainer, - TableHead, - TableRow, -} from "@mui/material"; +import { Button, Switch } from "@mui/material"; import { SampleProducts } from "../../Components/SampleData/SampleData"; +import TableView from "../../Components/Products/TableView/TableView"; +import BlobView from "../../Components/Products/BlobView/BlobView"; export default function Products() { const navigate = useNavigate(); - + const [tableView, toggleTableView] = useState(false); + function view() { + if (tableView) { + return ; + } else { + return ; + } + } return (
@@ -41,34 +42,8 @@ export default function Products() {
- - - - - Product ID - Product - Last Modified - - - - {SampleProducts.map((row) => ( - - {row.id} - {row.name} - {row.last_modified} - - ))} - -
-
+ toggleTableView(!tableView)} /> + {view()} ); }