From b62a160f882080381e9f75a6a83b56534f8465d5 Mon Sep 17 00:00:00 2001 From: keannu125 Date: Mon, 6 Mar 2023 00:04:25 +0800 Subject: [PATCH] Shortened code for amount change color in Logs.tsx and polished some other stuff --- src/Components/ProductsPage/ViewManager.tsx | 27 ++++++++++ src/Routes/Logs/Logs.tsx | 56 ++++++++++++++------- src/Routes/Products/Products.tsx | 19 ++----- 3 files changed, 69 insertions(+), 33 deletions(-) create mode 100644 src/Components/ProductsPage/ViewManager.tsx diff --git a/src/Components/ProductsPage/ViewManager.tsx b/src/Components/ProductsPage/ViewManager.tsx new file mode 100644 index 0000000..0ef4659 --- /dev/null +++ b/src/Components/ProductsPage/ViewManager.tsx @@ -0,0 +1,27 @@ +import * as React from "react"; +import { useState } from "react"; +import { Switch } from "@mui/material"; +import TableView from "../../Components/ProductsPage/TableView/TableView"; +import BlobView from "../../Components/ProductsPage/BlobView/BlobView"; +import { ProductList } from "../../Interfaces/Interfaces"; + +export interface props {} + +export default function ViewManager(props: ProductList) { + const [tableView, toggleTableView] = useState(false); + if (tableView) { + return ( +
+ toggleTableView(!tableView)} /> + +
+ ); + } else { + return ( +
+ toggleTableView(!tableView)} /> + +
+ ); + } +} diff --git a/src/Routes/Logs/Logs.tsx b/src/Routes/Logs/Logs.tsx index 7650b5b..ea53b52 100644 --- a/src/Routes/Logs/Logs.tsx +++ b/src/Routes/Logs/Logs.tsx @@ -12,18 +12,11 @@ import { import { SampleLogData } from "../../Components/SampleData/SampleData"; export default function Logs() { - function change_color(amount: number) { - if (amount > 0) { - return {amount}; - } else { - return {amount}; - } - } return (
-

Logs

+

Logs

- Log ID - Product ID - Product - Amount Change - Timestamp + + Log ID + + + Product ID + + + Product + + + Amount Change + + + Timestamp + @@ -47,11 +50,28 @@ export default function Logs() { key={row.id} sx={{ "&:last-child td, &:last-child th": { border: 0 } }} > - {row.id} - {row.p_id} - {row.p_name} - {change_color(row.amount_changed)} - {row.timestamp} + + {row.id} + + + {row.p_id} + + + {row.p_name} + + + {row.amount_changed} + + + {row.timestamp} + ))} diff --git a/src/Routes/Products/Products.tsx b/src/Routes/Products/Products.tsx index 916da6f..03162d3 100644 --- a/src/Routes/Products/Products.tsx +++ b/src/Routes/Products/Products.tsx @@ -3,21 +3,12 @@ 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, Switch } from "@mui/material"; +import { Button } from "@mui/material"; import { SampleProducts } from "../../Components/SampleData/SampleData"; -import TableView from "../../Components/ProductsPage/TableView/TableView"; -import BlobView from "../../Components/ProductsPage/BlobView/BlobView"; +import ViewManager from "../../Components/ProductsPage/ViewManager"; export default function Products() { const navigate = useNavigate(); - const [tableView, toggleTableView] = useState(false); - function view() { - if (tableView) { - return ; - } else { - return ; - } - } return (
@@ -31,10 +22,9 @@ export default function Products() {
- toggleTableView(!tableView)} />
- - {view()} +
); }