Skip to content

Commit 3d03120

Browse files
committed
clean up css
1 parent 234d7e8 commit 3d03120

File tree

4 files changed

+102
-52
lines changed

4 files changed

+102
-52
lines changed

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"next": "13.1.6",
1717
"react": "18.2.0",
1818
"react-dom": "18.2.0",
19+
"react-icons": "^4.7.1",
1920
"sass": "^1.58.0"
2021
}
2122
}

src/pages/index.js

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect, useState, useRef } from "react";
2+
import { CiTrash } from "react-icons/ci";
23
import Head from "next/head";
34
import Image from "next/image";
45
import styles from "@/styles/Home.module.scss";
@@ -16,7 +17,7 @@ export default function Home() {
1617
const [deletedError, setDeletedError] = useState(false);
1718

1819
async function addProduct() {
19-
const productName = productNameRef.current.value;
20+
const productName = productNameRef.current.value.trim();
2021
if (productName.length < 3) return;
2122
const postData = {
2223
method: "POST",
@@ -62,16 +63,15 @@ export default function Home() {
6263
console.log(response);
6364
}
6465

65-
async function deleteProduct() {
66-
const productIDToDelete = productIDToDeleteRef.current.value;
67-
if (!productIDToDelete.length) return;
66+
async function deleteProduct(id) {
67+
if (!id) return;
6868
const postData = {
6969
method: "DELETE",
7070
headers: {
7171
"Content-Type": "application/json",
7272
},
7373
body: JSON.stringify({
74-
product_id: productIDToDelete,
74+
product_id: id,
7575
}),
7676
};
7777
const res = await fetch(
@@ -87,8 +87,8 @@ export default function Home() {
8787
}
8888

8989
async function updateProduct() {
90-
const productIDToUpdate = productIDToUpdateRef.current.value;
91-
const productNameToUpdate = productNameToUpdateRef.current.value;
90+
const productIDToUpdate = productIDToUpdateRef.current.value.trim();
91+
const productNameToUpdate = productNameToUpdateRef.current.value.trim();
9292
if (!productIDToUpdate.length) return;
9393
const postData = {
9494
method: "PATCH",
@@ -138,23 +138,45 @@ export default function Home() {
138138
<title>CRUD NEXT.JS Tutorial with Next JS API endpoints</title>
139139
</Head>
140140
<div className={styles.container}>
141-
<h1>CRUD Next.Js API Demo</h1>
142-
<p>
143-
Create, Read, Update, Delete database data in React, Node and Next.JS
144-
by Omar Elbaga{" "}
145-
<a
146-
href="https://github.com/oelbaga/nextjs-mysql"
147-
target="_blank"
148-
rel="noreferrer"
149-
>
150-
GitHub
151-
</a>
152-
</p>
153-
<div className={styles.heading}>
154-
<a href="/api/products" target="_blank" rel="noreferrer">
155-
Database API data
156-
</a>
157-
</div>
141+
<section className={styles.main}>
142+
<h1>CRUD Next.Js API Demo</h1>
143+
<p>
144+
Create, Read, Update, Delete database data in React, Node and
145+
Next.JS by Omar Elbaga{" "}
146+
<a
147+
href="https://github.com/oelbaga/nextjs-mysql"
148+
target="_blank"
149+
rel="noreferrer"
150+
>
151+
GitHub
152+
</a>
153+
</p>
154+
<div className={styles.heading}>
155+
<a href="/api/products" target="_blank" rel="noreferrer">
156+
Database API data
157+
</a>
158+
</div>
159+
</section>
160+
<section>
161+
<div className={styles.read}>
162+
<h2>Read</h2>
163+
<div className={styles.products}>
164+
{products.map((item, index) => {
165+
return (
166+
<div key={item.product_id} className={styles.product}>
167+
<span>product_id</span>: {item.product_id} <br />{" "}
168+
<span>product_name</span>: {item.product_name}{" "}
169+
<CiTrash
170+
className={styles.icons}
171+
onClick={() => deleteProduct(item.product_id)}
172+
/>
173+
</div>
174+
);
175+
})}
176+
{!products.length ? <>No products found</> : null}
177+
</div>
178+
</div>
179+
</section>
158180
<section>
159181
<div className={styles.create}>
160182
<h2>Create</h2>
@@ -173,21 +195,6 @@ export default function Home() {
173195
</div>
174196
</div>
175197
</section>
176-
<section>
177-
<div className={styles.read}>
178-
<h2>Read</h2>
179-
<div className={styles.products}>
180-
{products.map((item, index) => {
181-
return (
182-
<div key={item.product_id} className={styles.product}>
183-
<span>Id</span>:{item.product_id} <br /> <span>Name</span>:
184-
{item.product_name}
185-
</div>
186-
);
187-
})}
188-
</div>
189-
</div>
190-
</section>
191198
<section>
192199
<div className={styles.update}>
193200
<h2>Update</h2>
@@ -225,22 +232,26 @@ export default function Home() {
225232
className={`${styles.button} ${styles.warning}`}
226233
value="Delete"
227234
type="button"
228-
onClick={deleteProduct}
235+
onClick={() =>
236+
deleteProduct(productIDToDeleteRef.current.value)
237+
}
229238
/>
230239
</div>
231240
</div>
232241
</section>
233-
<p>
234-
Create, Read, Update, Delete database data in React, Node and Next.JS
235-
by Omar Elbaga{" "}
236-
<a
237-
href="https://github.com/oelbaga/nextjs-mysql"
238-
target="_blank"
239-
rel="noreferrer"
240-
>
241-
GitHub
242-
</a>
243-
</p>
242+
<footer>
243+
<p>
244+
Create, Read, Update, Delete database data in React, Node and
245+
Next.JS by Omar Elbaga{" "}
246+
<a
247+
href="https://github.com/oelbaga/nextjs-mysql"
248+
target="_blank"
249+
rel="noreferrer"
250+
>
251+
GitHub
252+
</a>
253+
</p>
254+
</footer>
244255
</div>
245256
</>
246257
);

src/styles/Home.module.scss

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,28 @@
2424
border-bottom: 1px solid black;
2525
}
2626
}
27+
footer {
28+
margin: 0 auto;
29+
padding: 1rem 1rem 1rem;
30+
max-width: 800px;
31+
}
2732
section {
33+
margin: 0 auto;
2834
padding: 1rem 1rem 1rem;
2935
max-width: 800px;
3036
border-top: 5px solid black;
37+
&.main {
38+
border-top: 0px;
39+
padding: 0rem 1rem 0.5rem;
40+
@include mixin.tablet {
41+
padding: 0rem 1rem 1rem;
42+
}
43+
}
3144
@include mixin.tablet {
32-
padding: 2.5rem 3rem 2.8rem;
45+
padding: 2.5rem 1rem 2.8rem;
46+
}
47+
.icons {
48+
cursor: pointer;
3349
}
3450
.success {
3551
margin-bottom: 1rem;
@@ -42,9 +58,13 @@
4258
color: rgb(175, 3, 3);
4359
}
4460
.products {
61+
height: 100px;
62+
overflow: scroll;
4563
.product {
4664
line-height: 1.5;
4765
margin-bottom: 1rem;
66+
padding-bottom: 0.4rem;
67+
border-bottom: 1px solid grey;
4868
span {
4969
font-weight: 600;
5070
}
@@ -97,6 +117,9 @@
97117
cursor: pointer;
98118
font-weight: 600;
99119
text-transform: uppercase;
120+
-webkit-appearance: none;
121+
-moz-appearance: none;
122+
appearance: none;
100123
@include mixin.tablet {
101124
letter-spacing: 0.56em;
102125
line-height: 2.7;

0 commit comments

Comments
 (0)