diff --git a/package-lock.json b/package-lock.json
index 8cc2d13..7dcc4be 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -14,7 +14,8 @@
"axios": "^1.7.9",
"react": "^18.3.1",
"react-dom": "^18.3.1",
- "react-router-dom": "^7.1.1"
+ "react-router-dom": "^7.1.1",
+ "react-spinners": "^0.15.0"
},
"devDependencies": {
"@eslint/js": "^9.17.0",
@@ -5219,6 +5220,16 @@
"react-dom": ">=18"
}
},
+ "node_modules/react-spinners": {
+ "version": "0.15.0",
+ "resolved": "https://registry.npmjs.org/react-spinners/-/react-spinners-0.15.0.tgz",
+ "integrity": "sha512-ZO3/fNB9Qc+kgpG3SfdlMnvTX6LtLmTnOogb3W6sXIaU/kZ1ydEViPfZ06kSOaEsor58C/tzXw2wROGQu3X2pA==",
+ "license": "MIT",
+ "peerDependencies": {
+ "react": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
+ "react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
+ }
+ },
"node_modules/react-transition-group": {
"version": "4.4.5",
"resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.5.tgz",
diff --git a/package.json b/package.json
index be42d8c..936f843 100644
--- a/package.json
+++ b/package.json
@@ -16,7 +16,8 @@
"axios": "^1.7.9",
"react": "^18.3.1",
"react-dom": "^18.3.1",
- "react-router-dom": "^7.1.1"
+ "react-router-dom": "^7.1.1",
+ "react-spinners": "^0.15.0"
},
"devDependencies": {
"@eslint/js": "^9.17.0",
diff --git a/src/components/Card.jsx b/src/components/Card.jsx
index 245a292..a06131a 100644
--- a/src/components/Card.jsx
+++ b/src/components/Card.jsx
@@ -1,13 +1,14 @@
import React from "react";
-const Card = ({movie}) => {
- const { Title, Year, imdbID, Poster } = movie
- console.log("Card", Title, Year, imdbID, Poster)
+const Card = ({ movie }) => {
+ const { Title, Year, imdbID, Poster } = movie;
return (
-
-
-
{Title}
-
{Year}
+
+
+
);
};
diff --git a/src/components/Header.jsx b/src/components/Header.jsx
index 109f016..4954f4e 100644
--- a/src/components/Header.jsx
+++ b/src/components/Header.jsx
@@ -2,7 +2,7 @@ import React from 'react'
const Header = () => {
return (
-
+
)
diff --git a/src/hooks/useFetch.jsx b/src/hooks/useFetch.jsx
index a8f8036..c132583 100644
--- a/src/hooks/useFetch.jsx
+++ b/src/hooks/useFetch.jsx
@@ -3,22 +3,24 @@ import { useState, useEffect } from "react";
const useFetch = (url) => {
const [data, setData] = useState({});
+ const [loading, setLoading] = useState(false)
+ const [error, setError] = useState({})
useEffect(() => {
// console.log("Inside fetch")
const fetch = async () => {
let response;
try {
+ setLoading(true);
response = await axios.get(url);
- // console.log("USEFETCH:", response?.data);
setData(response?.data);
- } catch {
- console.log("Error in useFetch: ");
- return "Error Fetching Data";
+ setLoading(false);
+ } catch(error) {
+ setError(error)
}
};
fetch();
}, [url]);
- return data;
+ return { data, loading, error};
};
export default useFetch;
diff --git a/src/pages/HomePage.jsx b/src/pages/HomePage.jsx
index 1ff1706..55981c6 100644
--- a/src/pages/HomePage.jsx
+++ b/src/pages/HomePage.jsx
@@ -1,25 +1,34 @@
-import React, { useEffect, useState } from "react";
+import React, { useState } from "react";
import useFetch from "../hooks/useFetch";
+import { Pagination } from "@mui/material";
+import { ClipLoader } from "react-spinners";
+
import Card from "../components/Card";
const HomePage = () => {
+ const url = import.meta.env.VITE_BASE_URL;
+
const [inputValue, setInputValue] = useState("");
const [searchValue, setSearchValue] = useState("");
- const [data, setData] = useState("");
+ const [page, setPage] = useState(1);
+ const { data, loading, error } = useFetch(
+ url + "&s=" + searchValue + "&page=" + page
+ );
- const url = import.meta.env.VITE_BASE_URL;
- const response = useFetch(url + "s=" + searchValue);
- console.log(response)
- useEffect(() => setData(response), [data]);
+ console.log(page);
+
+ const handlePageChange = (e) => {
+ setPage(e?.target?.textContent);
+ };
const handleSearch = (event) => {
event.preventDefault();
setSearchValue(inputValue);
};
return (
-
+
-
- {data?.Search?.length > 0 &&
-
- {data?.Search?.map((movie) =>
)}
+ {data?.Search?.length > 0 && (
+
+
+
+ {data?.Search?.map((movie) => (
+
+ ))}
+
+
- }
+ )}
);
};