-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: revert LazyImage component performance issue
- Loading branch information
Showing
13 changed files
with
227 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,40 @@ | ||
const PersonCard = ({ personDetails }: any) => { | ||
return <div className="p-2">PersonCard</div>; | ||
import React from "react"; | ||
|
||
interface PersonDetails { | ||
profile_path?: string; | ||
name: string; | ||
roles: { character: string }[]; | ||
department?: string; | ||
} | ||
|
||
interface PersonCardProps { | ||
personDetails: PersonDetails; | ||
} | ||
|
||
const PersonCard: React.FC<PersonCardProps> = ({ personDetails }) => { | ||
return ( | ||
<div className="p-2 w-fit bg-gradient-to-br from-white/20 to-transparent rounded-2xl flex space-x-2 shadow-[inset_0_1px_0_0_#ffffff1a] transition-all bg-size-200 bg-pos-100 hover:bg-pos-0"> | ||
<div className="!w-[60px] rounded-lg overflow-hidden aspect-square flex items-center justify-center bg-zinc-600/80"> | ||
{personDetails.profile_path ? ( | ||
<img | ||
className="w-full h-full object-cover" | ||
src={`https://image.tmdb.org/t/p/w1280${personDetails.profile_path}`} | ||
alt={personDetails.name} | ||
/> | ||
) : ( | ||
<div className="text-xs uppercase text-center">Image Not Found</div> | ||
)} | ||
</div> | ||
<div className="px-2 flex-1 whitespace-nowrap"> | ||
<div className="font-semibold">{personDetails.name}</div> | ||
<div className="text-xs"> | ||
{personDetails.roles?.[0]?.character || | ||
personDetails.department || | ||
"N/A"} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PersonCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useNavigate, useRouteError } from "react-router-dom"; | ||
|
||
const ErrorPage = () => { | ||
const navigate = useNavigate(); | ||
const error: any = useRouteError(); | ||
|
||
return ( | ||
<div className="flex justify-center items-center p-10 h-screen w-full bg-gradient-to-tl from-blue-500/20 via-indigo-500/20 to-pink-500/20"> | ||
<div className="p-2 rounded-2xl bg-white/10 text-sm text-center max-w-[600px] space-y-2 shadow-[inset_0_1px_0_0_#ffffff1a]"> | ||
<div className="font-semibold text-xl">{error.status}</div> | ||
<div>{error.statusText}</div> | ||
<div className="p-2 bg-white/20 rounded-lg w-full">{error.data}</div> | ||
<button | ||
className="p-2 bg-emerald-500 hover:bg-emerald-400 rounded-lg w-full font-semibold transition-colors" | ||
onClick={() => navigate("/")} | ||
> | ||
RETURN HOME | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ErrorPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,83 @@ | ||
import { useLoaderData } from "react-router-dom"; | ||
import TransitionWrapper from "./TransitionWrapper"; | ||
import useColorExtractor from "../hooks/useColorExtractor"; | ||
import { motion } from "framer-motion"; | ||
import { APP_CONFIG, APP_PATHS } from "../../config/config"; | ||
import LazyImage from "../components/LazyImage"; | ||
import Button from "../components/Button"; | ||
import IconButton from "../components/IconButton"; | ||
import PersonCard from "../components/Cards/PersonCard"; | ||
|
||
const MovieInfoPage = () => { | ||
const movie = useLoaderData(); | ||
return <div>{JSON.stringify(movie)}</div>; | ||
const movie: any = useLoaderData(); | ||
|
||
const { colors } = useColorExtractor( | ||
`${APP_PATHS.image}${movie.backdrop_path}`, | ||
APP_CONFIG.optimization | ||
); | ||
|
||
const bgColor = colors.length > 0 ? colors[0] : "#0E0E0E"; | ||
|
||
return ( | ||
<motion.div | ||
animate={{ backgroundColor: bgColor }} | ||
className="w-full h-screen overflow-y-auto overscroll-none pb-12 space-y-12" | ||
> | ||
<div className="relative"> | ||
<LazyImage | ||
className="aspect-[21/9]" | ||
src={`${APP_PATHS.image}${movie.backdrop_path}`} | ||
alt="backdrop" | ||
/> | ||
<motion.div | ||
animate={{ | ||
background: `linear-gradient(to top, ${bgColor}, transparent)`, | ||
}} | ||
className="absolute top-0 left-0 bottom-0 right-0 w-full h-full" | ||
></motion.div> | ||
<div className="absolute bottom-0 px-[4.5rem] flex items-end space-x-4"> | ||
<LazyImage | ||
className="w-[200px] rounded-xl overflow-hidden aspect-[9/12]" | ||
src={`${APP_PATHS.image}${movie.poster_path}`} | ||
alt="poster" | ||
/> | ||
<div className="space-y-4 flex-1"> | ||
<div> | ||
<div className="text-4xl font-bold">{movie.title}</div> | ||
</div> | ||
<div className="line-clamp-2 max-w-[700px] text-sm"> | ||
{movie.overview} | ||
</div> | ||
<div className="flex space-x-4"> | ||
<Button icon="PlayIcon" size="large"> | ||
Play Now | ||
</Button> | ||
<IconButton | ||
variant="secondary" | ||
icon="VideoCameraIcon" | ||
iconType="outline" | ||
size="large" | ||
/> | ||
<IconButton | ||
variant="secondary" | ||
icon="BookmarkIcon" | ||
iconType="outline" | ||
size="large" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="px-[4.5rem] space-y-12"> | ||
<div className="text-2xl">Cast</div> | ||
<div className="flex space-x-4 overflow-x-scroll"> | ||
{movie.credits.cast.map((cast: any, index: number) => ( | ||
<PersonCard key={index} personDetails={cast} /> | ||
))} | ||
</div> | ||
</div> | ||
</motion.div> | ||
); | ||
}; | ||
|
||
export default TransitionWrapper(MovieInfoPage); |
Oops, something went wrong.