@@ -52,7 +51,7 @@ const Layout = () => {
diff --git a/src/Component/Pagination.js b/src/Component/Pagination.js
index d0d4c68..057301a 100644
--- a/src/Component/Pagination.js
+++ b/src/Component/Pagination.js
@@ -1,5 +1,5 @@
-import React from 'react';
-import "../styleing/pagination.css"
+import React from "react";
+import "../styleing/pagination.css";
const Pagination = ({ currentPage, totalPages, onPageChange }) => {
const handlePageChange = (page) => {
onPageChange(page);
@@ -7,11 +7,19 @@ const Pagination = ({ currentPage, totalPages, onPageChange }) => {
return (
-
diff --git a/src/Component/SearchBar.js b/src/Component/SearchBar.js
index b4a549c..4bfa190 100644
--- a/src/Component/SearchBar.js
+++ b/src/Component/SearchBar.js
@@ -1,13 +1,13 @@
-import React, { useState } from 'react';
-import '../styleing/SearchBar.css';
+import React, { useState } from "react";
+import "../styleing/SearchBar.css";
const SearchBar = ({ onSearch }) => {
- const [searchTerm, setSearchTerm] = useState('');
+ const [searchTerm, setSearchTerm] = useState("");
const handleInputChange = (event) => {
const value = event?.target?.value;
setSearchTerm(value);
- onSearch(value);
+ onSearch(value);
};
return (
diff --git a/src/Component/addPost.js b/src/Component/addPost.js
index 04d0aef..37a5a66 100644
--- a/src/Component/addPost.js
+++ b/src/Component/addPost.js
@@ -1,32 +1,34 @@
-
-import React, { useState } from 'react';
-import "../styleing/addPost.css"
+import React, { useState } from "react";
+import "../styleing/addPost.css";
const AddPostForm = ({ onAddPost }) => {
- const [newPost, setNewPost] = useState({ title: '', body: '' });
+ const [newPost, setNewPost] = useState({ title: "", body: "" });
const handleSubmit = (e) => {
e.preventDefault();
if (newPost.title && newPost.body) {
- onAddPost(newPost);
- setNewPost({ title: '', body: '' });
+ onAddPost(newPost);
+ setNewPost({ title: "", body: "" });
} else {
- alert('Title and Body are required!');
+ alert("Title and Body are required!");
}
};
+
+
return (
setNewPost({ ...newPost, title: e.target.value })}
+ onChange={(e) => setNewPost((prevState)=>({ ...prevState, title: e.target.value }))}
/>
);
diff --git a/src/env.js b/src/env.js
deleted file mode 100644
index 2bdd03f..0000000
--- a/src/env.js
+++ /dev/null
@@ -1 +0,0 @@
-export const api_url = "https://jsonplaceholder.typicode.com/posts";
\ No newline at end of file
diff --git a/src/hooks/useFetch.js b/src/hooks/useFetch.js
new file mode 100644
index 0000000..b9a5f8e
--- /dev/null
+++ b/src/hooks/useFetch.js
@@ -0,0 +1,28 @@
+import { useState, useEffect } from "react";
+
+const useFetch = (url) => {
+ const [data, setData] = useState([]);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState(null);
+
+ useEffect(() => {
+ const fetchData = async () => {
+ setLoading(true);
+ try {
+ const res = await fetch(url);
+ if (!res.ok) {
+ throw new Error("Failed to fetch data");
+ }
+ const result = await res.json();
+ setData(result);
+ } catch (err) {
+ setError(err.message);
+ } finally {
+ setLoading(false);
+ }
+ };
+ fetchData();
+ }, [url]);
+ return { data, loading, error };
+};
+export default useFetch;
diff --git a/src/styleing/SearchBar.css b/src/styleing/SearchBar.css
index 7a4f675..a5e0cf0 100644
--- a/src/styleing/SearchBar.css
+++ b/src/styleing/SearchBar.css
@@ -1,31 +1,32 @@
-
+:root {
+ --borderColor: #ccc;
+ --bgColor: #f9f9f9;
+ --bFocus: #4caf50;
+}
.searchBar {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin: 20px 0;
- }
-
- .search {
- padding: 10px;
- font-size: 1.2em;
- width: 300px;
- border: 1px solid #ccc;
- border-radius: 4px;
- background-color: #f9f9f9;
- }
-
- .search:focus {
- border-color: #4CAF50;
- outline: none;
- }
- .search{
- display: flex;
- margin-left: 85cap;
- padding: 10px;
- border: 1px solid black;
- border-radius: 10px ;
-
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin: 20px 0;
}
-
\ No newline at end of file
+.search {
+ padding: 10px;
+ font-size: 1.2em;
+ width: 300px;
+ border: 1px solid var(--borderColor);
+ border-radius: 4px;
+ background-color: var(--bgColor);
+}
+
+.search:focus {
+ border-color: var(--bFocus);
+ outline: none;
+}
+.search {
+ position: absolute;
+ margin-left: 50cap;
+ padding: 10px;
+ border: 1px solid var(black);
+ border-radius: 10px;
+}
diff --git a/src/styleing/addPost.css b/src/styleing/addPost.css
index 33e998f..686d01b 100644
--- a/src/styleing/addPost.css
+++ b/src/styleing/addPost.css
@@ -1,36 +1,40 @@
-
+:root {
+ --borderColor: #ccc;
+ --bgColor: #f9f9f9;
+ --bgCol: #4caf50;
+ --bgColHover: #45a049;
+}
.addPostForm {
- display: flex;
- flex-direction: column;
- margin: 20px 0;
- }
-
- .addPostForm input,
- .addPostForm textarea {
- padding: 12px;
- margin-bottom: 15px;
- border: 1px solid #ccc;
- border-radius: 4px;
- font-size: 1.1em;
- width: 100%;
- }
-
- .addPostForm button {
- padding: 12px;
- background-color: #4CAF50;
- color: white;
- font-size: 1.1em;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- }
-
- .addPostForm button:hover {
- background-color: #45a049;
- }
-
- .addPostForm input:focus,
- .addPostForm textarea:focus {
- border-color: #4CAF50;
- }
-
\ No newline at end of file
+ display: flex;
+ flex-direction: column;
+ margin: 20px 0;
+}
+
+.addPostForm input,
+.addPostForm textarea {
+ padding: 12px;
+ margin-bottom: 15px;
+ border: 1px solid var(--borderColor);
+ border-radius: 4px;
+ font-size: 1.1em;
+ width: 100%;
+}
+
+.addPostForm button {
+ padding: 12px;
+ background-color: var(--bgCol);
+ color: var(--bgColor);
+ font-size: 1.1em;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+}
+
+.addPostForm button:hover {
+ background-color: var(--bgColHover);
+}
+
+.addPostForm input:focus,
+.addPostForm textarea:focus {
+ border-color: var(--bgCol);
+}
diff --git a/src/styleing/body.css b/src/styleing/body.css
index ebc0a7e..22303ce 100644
--- a/src/styleing/body.css
+++ b/src/styleing/body.css
@@ -1,17 +1,27 @@
-.App{
-
- /* background-image: linear-gradient(to right, rgba(255,0,0,0), rgba(255, 0, 0, 0.163)); */
+:root {
+ --borderColor: black;
+}
+ul {
+ list-style-type: none;
+ display: grid;
+ grid-template-columns: auto auto auto;
+ gap: 20px;
+
+}
+li {
+ border: 2px solid var(--borderColor);
+ background-image: linear-gradient(rgba(135, 207, 235, 0.588),rgba(230, 116, 116, 0.295));
+ font-family: Georgia, 'Times New Roman', Times, serif;
+ border-radius: 15px;
+ padding: 5px;
+
+}
+button{
+ background-color: skyblue;
+ border-radius: 10px;
-
}
-ul{
- list-style-type: none;
- display: grid;
- grid-template-columns: auto auto auto;
- gap: 20px;
-
-}
-li{
- border: 2px solid black;
-}
+button:hover{
+ background-color: rgba(230, 116, 116, 0.632);
+}
\ No newline at end of file
diff --git a/src/styleing/layout.css b/src/styleing/layout.css
index a77a8da..530f3be 100644
--- a/src/styleing/layout.css
+++ b/src/styleing/layout.css
@@ -1,13 +1,18 @@
-.header{
- background-image:linear-gradient(skyblue,rgb(230, 116, 116)) ;
- height: auto;
- width: 100%;
- padding: 5px;
- margin-top: -16px;
+:root {
+ --imgBG_LG1: skyblue;
+ --imgBG_LG2: rgb(230, 116, 116);
+ --headingColor: black;
}
-.heading{
- text-align: center;
- font-family: Arial, Helvetica, sans-serif;
- font-size: xx-large;
- color: black;
+.header {
+ background-image: linear-gradient(var(--imgBG_LG1), var(--imgBG_LG2));
+ height: auto;
+ width: 100%;
+ padding: 5px;
+ margin-top: -16px;
+}
+.heading {
+ text-align: center;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: xx-large;
+ color: var(--headingColor);
}
diff --git a/src/styleing/pagination.css b/src/styleing/pagination.css
index 7611c55..a1cf3c7 100644
--- a/src/styleing/pagination.css
+++ b/src/styleing/pagination.css
@@ -1,30 +1,35 @@
-
+:root {
+ --border: #ccc;
+ --bgColor: #f9f9f9;
+ --bgHover: #ddd;
+ --paginationBG: #4caf50;
+ --paginationCol: white;
+}
.pagination {
- display: flex;
- justify-content: center;
- margin-top: 20px;
- }
-
- .pagination button {
- padding: 8px 12px;
- margin: 0 5px;
- border: 1px solid #ccc;
- border-radius: 4px;
- background-color: #f9f9f9;
- cursor: pointer;
- }
-
- .pagination button:hover {
- background-color: #ddd;
- }
-
- .pagination .active {
- background-color: #4CAF50;
- color: white;
- }
-
- .pagination .disabled {
- background-color: #f2f2f2;
- cursor: not-allowed;
- }
-
\ No newline at end of file
+ display: flex;
+ justify-content: center;
+ margin-top: 20px;
+}
+
+.pagination button {
+ padding: 8px 12px;
+ margin: 0 5px;
+ border: 1px solid var(--border);
+ border-radius: 4px;
+ background-color: var(--bgColor);
+ cursor: pointer;
+}
+
+.pagination button:hover {
+ background-color: var(--bgHover);
+}
+
+.pagination .active {
+ background-color: var(--paginationBG);
+ color: var(--paginationCol);
+}
+
+.pagination .disabled {
+ background-color: var(--bgColor);
+ cursor: not-allowed;
+}