Done #1
13
package-lock.json
generated
13
package-lock.json
generated
|
@ -14,7 +14,8 @@
|
||||||
"axios": "^1.7.9",
|
"axios": "^1.7.9",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^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": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.17.0",
|
"@eslint/js": "^9.17.0",
|
||||||
|
@ -5219,6 +5220,16 @@
|
||||||
"react-dom": ">=18"
|
"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": {
|
"node_modules/react-transition-group": {
|
||||||
"version": "4.4.5",
|
"version": "4.4.5",
|
||||||
"resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.5.tgz",
|
"resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.5.tgz",
|
||||||
|
|
|
@ -16,7 +16,8 @@
|
||||||
"axios": "^1.7.9",
|
"axios": "^1.7.9",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^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": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.17.0",
|
"@eslint/js": "^9.17.0",
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
const Card = ({movie}) => {
|
const Card = ({ movie }) => {
|
||||||
const { Title, Year, imdbID, Poster } = movie
|
const { Title, Year, imdbID, Poster } = movie;
|
||||||
console.log("Card", Title, Year, imdbID, Poster)
|
|
||||||
return (
|
return (
|
||||||
<div className="h-16 w-10">
|
<div className="h-[30vh] w-[10vw] overflow-hidden border rounded-lg border-quadnary">
|
||||||
<img src={Poster} alt={Title} className="h-12 w-full" />
|
<img src={Poster} alt={Title} className="h-[85%] w-full" />
|
||||||
<h6 className="text-quadnary">{Title}</h6>
|
<div className="flex justify-between px-3 pt-1 text-sm">
|
||||||
<p className="text-quadnary">{Year}</p>
|
<h6 className="text-quadnary">{Title}</h6>
|
||||||
|
<p className="text-quadnary font-semibold">{Year}</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@ import React from 'react'
|
||||||
|
|
||||||
const Header = () => {
|
const Header = () => {
|
||||||
return (
|
return (
|
||||||
<header className="fixed w-full h-[5vh] py-3 px-6 bg-secondary">
|
<header className="fixed z-20 w-full h-[5vh] py-3 px-6 bg-secondary">
|
||||||
<a href="/">DigiFlix</a>
|
<a href="/">DigiFlix</a>
|
||||||
</header>
|
</header>
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,22 +3,24 @@ import { useState, useEffect } from "react";
|
||||||
|
|
||||||
const useFetch = (url) => {
|
const useFetch = (url) => {
|
||||||
const [data, setData] = useState({});
|
const [data, setData] = useState({});
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [error, setError] = useState({})
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// console.log("Inside fetch")
|
// console.log("Inside fetch")
|
||||||
const fetch = async () => {
|
const fetch = async () => {
|
||||||
let response;
|
let response;
|
||||||
try {
|
try {
|
||||||
|
setLoading(true);
|
||||||
response = await axios.get(url);
|
response = await axios.get(url);
|
||||||
// console.log("USEFETCH:", response?.data);
|
|
||||||
setData(response?.data);
|
setData(response?.data);
|
||||||
} catch {
|
setLoading(false);
|
||||||
console.log("Error in useFetch: ");
|
} catch(error) {
|
||||||
return "Error Fetching Data";
|
setError(error)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetch();
|
fetch();
|
||||||
}, [url]);
|
}, [url]);
|
||||||
return data;
|
return { data, loading, error};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useFetch;
|
export default useFetch;
|
||||||
|
|
|
@ -1,25 +1,34 @@
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useState } from "react";
|
||||||
import useFetch from "../hooks/useFetch";
|
import useFetch from "../hooks/useFetch";
|
||||||
|
|
||||||
|
import { Pagination } from "@mui/material";
|
||||||
|
import { ClipLoader } from "react-spinners";
|
||||||
rishav_dml marked this conversation as resolved
|
|||||||
|
|
||||||
import Card from "../components/Card";
|
import Card from "../components/Card";
|
||||||
|
|
||||||
const HomePage = () => {
|
const HomePage = () => {
|
||||||
|
const url = import.meta.env.VITE_BASE_URL;
|
||||||
|
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
const [searchValue, setSearchValue] = 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;
|
console.log(page);
|
||||||
const response = useFetch(url + "s=" + searchValue);
|
|
||||||
console.log(response)
|
const handlePageChange = (e) => {
|
||||||
useEffect(() => setData(response), [data]);
|
setPage(e?.target?.textContent);
|
||||||
|
};
|
||||||
const handleSearch = (event) => {
|
const handleSearch = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setSearchValue(inputValue);
|
setSearchValue(inputValue);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div className=" min-h-[90vh] w-full pt-[10vh] bg-primary flex justify-center">
|
<div className=" min-h-[90vh] w-full pt-[10vh] bg-primary flex flex-col items-center ">
|
||||||
<div>
|
<div>
|
||||||
<form className="">
|
<form className="flex gap-3 items-center">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="search"
|
name="search"
|
||||||
|
@ -32,18 +41,31 @@ const HomePage = () => {
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="text-quadnary"
|
className="px-4 h-full border border-quadnary text-quadnary"
|
||||||
onClick={handleSearch}
|
onClick={handleSearch}
|
||||||
>
|
>
|
||||||
Search
|
Search
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{data?.Search?.length > 0 &&
|
{data?.Search?.length > 0 && (
|
||||||
<div>
|
<div className="flex flex-col items-center m-10">
|
||||||
{data?.Search?.map((movie) => <Card key={movie?.imdbID} movie={movie}/>)}
|
<ClipLoader color="#fff" loading={loading} size={100} />
|
||||||
|
<div className="flex flex-wrap gap-4 mb-6 justify-center">
|
||||||
|
{data?.Search?.map((movie) => (
|
||||||
|
<Card key={movie?.imdbID} movie={movie} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<Pagination
|
||||||
|
sx={{ bgcolor: "#fff" }}
|
||||||
|
onChange={handlePageChange}
|
||||||
|
page={Number(page)}
|
||||||
|
count={Math.ceil(data?.totalResults / 10)}
|
||||||
|
variant="outlined"
|
||||||
|
shape="rounded"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue
Try to implement spinner loader from scratch- Mayank Review