mirror of
https://github.com/lemeow125/Ivy-Frontend.git
synced 2024-11-17 06:39:25 +08:00
Cleaned up new delete/new product query refresh and added search to products page
This commit is contained in:
parent
c51c36c367
commit
46ddb25709
3 changed files with 73 additions and 6 deletions
|
@ -10,6 +10,7 @@ export interface props {}
|
||||||
|
|
||||||
export default function ViewManager(props: ProductList) {
|
export default function ViewManager(props: ProductList) {
|
||||||
const [tableView, toggleTableView] = useState(true);
|
const [tableView, toggleTableView] = useState(true);
|
||||||
|
const [searchTerm, setSearchTerm] = useState("");
|
||||||
if (props.Products.length === 0) {
|
if (props.Products.length === 0) {
|
||||||
return (
|
return (
|
||||||
<div style={{ ...styles.content_column, ...{ alignItems: "center" } }}>
|
<div style={{ ...styles.content_column, ...{ alignItems: "center" } }}>
|
||||||
|
@ -22,15 +23,81 @@ export default function ViewManager(props: ProductList) {
|
||||||
if (tableView) {
|
if (tableView) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Switch onClick={() => toggleTableView(!tableView)} />
|
<div style={styles.content_row}>
|
||||||
<TableView Products={props.Products} />
|
<Switch
|
||||||
|
style={{ flex: 1 }}
|
||||||
|
onClick={() => toggleTableView(!tableView)}
|
||||||
|
/>
|
||||||
|
<div style={{ flex: 8 }} />
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
...styles.content_row,
|
||||||
|
...{ flex: 1, justifyContent: "flex-end" },
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<p style={{ ...styles.text_white, ...styles.text_S }}>
|
||||||
|
Search
|
||||||
|
</p>
|
||||||
|
<input
|
||||||
|
style={{
|
||||||
|
...{
|
||||||
|
flex: 5,
|
||||||
|
height: "2rem",
|
||||||
|
},
|
||||||
|
...styles.text_S,
|
||||||
|
}}
|
||||||
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setSearchTerm(e.target.value);
|
||||||
|
}}
|
||||||
|
maxLength={20}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<TableView
|
||||||
|
Products={props.Products.filter((Product) =>
|
||||||
|
Product.name.toLowerCase().includes(searchTerm)
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Switch onClick={() => toggleTableView(!tableView)} />
|
<div style={styles.content_row}>
|
||||||
<BlobView Products={props.Products} />
|
<Switch
|
||||||
|
style={{ flex: 1 }}
|
||||||
|
onClick={() => toggleTableView(!tableView)}
|
||||||
|
/>
|
||||||
|
<div style={{ flex: 8 }} />
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
...styles.content_row,
|
||||||
|
...{ flex: 1, justifyContent: "flex-end" },
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<p style={{ ...styles.text_white, ...styles.text_S }}>
|
||||||
|
Search
|
||||||
|
</p>
|
||||||
|
<input
|
||||||
|
style={{
|
||||||
|
...{
|
||||||
|
flex: 5,
|
||||||
|
height: "2rem",
|
||||||
|
},
|
||||||
|
...styles.text_S,
|
||||||
|
}}
|
||||||
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setSearchTerm(e.target.value);
|
||||||
|
}}
|
||||||
|
maxLength={20}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<BlobView
|
||||||
|
Products={props.Products.filter((Product) =>
|
||||||
|
Product.name.toLowerCase().includes(searchTerm)
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default function NewProduct() {
|
||||||
mutationFn: AddProduct,
|
mutationFn: AddProduct,
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries("products");
|
queryClient.invalidateQueries("products");
|
||||||
queryClient.invalidateQueries("logs");
|
queryClient.invalidateQueries("product");
|
||||||
queryClient.invalidateQueries("logs");
|
queryClient.invalidateQueries("logs");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
import styles from "../../styles";
|
import styles from "../../styles";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import ProductsIcon from "../../Components/Icons/ProductsIcon/ProductsIcon";
|
import ProductsIcon from "../../Components/Icons/ProductsIcon/ProductsIcon";
|
||||||
|
|
Loading…
Reference in a new issue