Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Movies Sofie #67

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
56c7bee
startup code for project
SofieFerrari Apr 3, 2024
e7ea0ee
getting components and routes in place and playing with colors
SofieFerrari Apr 3, 2024
425fef0
pushing before starting to fetch API
SofieFerrari Apr 3, 2024
1b80757
fetched the data from the movieAPI
SofieFerrari Apr 3, 2024
b91bf2b
working on components
SofieFerrari Apr 3, 2024
1851161
worked on loading animation and tried to fix setTimeout
SofieFerrari Apr 3, 2024
e03572f
working on rendering data from api to moviecard
SofieFerrari Apr 4, 2024
2cb7821
wrapped app.jsx in route
SofieFerrari Apr 4, 2024
366775f
formatting code after lecture
SofieFerrari Apr 4, 2024
fdfb810
working with moviecard
SofieFerrari Apr 4, 2024
bda5d30
something
SofieFerrari Apr 5, 2024
915d1eb
got help from the moons
SofieFerrari Apr 5, 2024
8722dc4
got fetch to work, rendered data to movielist
SofieFerrari Apr 5, 2024
a828182
sucessfully rendered data from detail-api
SofieFerrari Apr 5, 2024
069a5e1
added a notfound-page. working on adding info to detailslist
SofieFerrari Apr 5, 2024
2c28160
got backgroundpic in place for detaillist
SofieFerrari Apr 5, 2024
8c47c74
all elements to second page -details - are in place
SofieFerrari Apr 5, 2024
0b86e37
hover in place
SofieFerrari Apr 5, 2024
7c215c1
working on styling mobile
SofieFerrari Apr 5, 2024
262187b
working on responsiveness
SofieFerrari Apr 5, 2024
58ff6dd
made placeholder button, will put icon there later
SofieFerrari Apr 5, 2024
2919289
finally finished project
SofieFerrari Apr 13, 2024
a75d66b
changed loader lottie, added backarrow lottie, fixed la
SofieFerrari May 24, 2024
89f5c85
fixed minor bug
SofieFerrari Jun 16, 2024
5e294b2
added env-file and toml-file for deploy
SofieFerrari Jun 20, 2024
7dd6d64
cleaned and formatted code
SofieFerrari Jun 20, 2024
8cefaba
formatted code
SofieFerrari Jun 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="icon" type="image/svg+xml" href="/movie.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Movie Site Project</title>
</head>
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
"preview": "vite preview"
},
"dependencies": {
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-lottie": "^1.2.4",
"react-router-dom": "^6.22.3"
},
"devDependencies": {
"@types/react": "^18.2.15",
Expand Down
21 changes: 21 additions & 0 deletions public/movie.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion public/vite.svg

This file was deleted.

23 changes: 21 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
import { BrowserRouter, Routes, Route } from 'react-router-dom'
import { useParams } from 'react-router-dom'
import { Movies } from './components/FirstPage.jsx'
import { Details } from './components/SecondPage.jsx'
import { Nav } from './components/Nav'
import { useEffect, useState } from 'react'
import { NotFound } from './components/NotFound.jsx'

export const App = () => {
return <div>Find me in src/app.jsx!</div>;
};
return (
<BrowserRouter>
<main>
{/* <Nav /> */}
<Routes>
<Route path="/" element={<Movies />} />
<Route path="/details/:slug" element={<Details />} />
<Route path="/notfound/" element={<NotFound />} />
</Routes>
</main>
</BrowserRouter>
)
}
23 changes: 23 additions & 0 deletions src/components/BackImage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Lottie from 'react-lottie'
import animationData from '../lotties/backanimation.json'

export const BackImage = () => {
const defaultOptions = {
loop: true,
autoplay: true,
animationData: animationData,
rendererSettings: {
preserveAspectRatio: 'xMidYMid slice',
},
}

return (
<div>
<Lottie
options={defaultOptions}
height={200}
width={200}
/>
</div>
)
}
39 changes: 39 additions & 0 deletions src/components/DetailList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Link } from 'react-router-dom'
import '../styling/DetailList.css'
import { BackImage } from './BackImage'

export const DetailList = ({ detailData }) => {
console.log('check data in DetailList', detailData)
return (
<>
{/* {detailData &&
detailData.results.map((detail) => ( */}
<div className="detail-wrapper">
<div
className="detail-background"
style={{
backgroundImage: `url(https://media.themoviedb.org/t/p/w780${detailData.backdrop_path})`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are screens that are bigger than 780; maybe next time you could consider on taking 1280px for background images.
-Izabel&Etna

backgroundRepeat: 'no-repeat',
backgroundSize: 'cover',
minWidth: '100VW',
}}>
<div className="details-card">
<Link to={'/'}>
<BackImage className="back-btn" />
</Link>
<img
className="poster-image"
src={`https://image.tmdb.org/t/p/w342${detailData.poster_path}`}
alt={`Movie poster for ${detailData.title}`}
/>
<div className="poster-text">
<h1>{detailData.title}</h1>
<h2>⭐ {detailData.vote_average.toFixed(1)}</h2>
<p>{detailData.overview}</p>
</div>
</div>
</div>
</div>
</>
)
}
34 changes: 34 additions & 0 deletions src/components/FirstPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useState, useEffect } from 'react'
import { PopularList } from './PopularList.jsx'
import { Loader } from './Loader'

export const Movies = () => {
const [movieData, setMovieData] = useState(null)
const [isLoading, setIsLoading] = useState(true)

const BASE_URL = 'https://api.themoviedb.org/3/movie/'
const API_KEY = '23ace2b0c27910f5cec13f5bdb014044'
// const urlMovies = `${BASE_URL}popular?api_key=${API_KEY}&language=en-US&page=1`

const testUrl =
'https://api.themoviedb.org/3/movie/popular?api_key=23ace2b0c27910f5cec13f5bdb014044&language=en-US&page=1'

useEffect(() => {
fetch(testUrl)
.then((result) => result.json())
.then((json) => {
setMovieData(json)
setIsLoading(false)
})
.catch((error) => {
console.error(error)
})
}, [testUrl])
console.log('moviedata firstpage', movieData)
return (
<>
{isLoading && <Loader />}
<PopularList movieData={movieData} />
</>
)
}
5 changes: 5 additions & 0 deletions src/components/Images.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const Images = ({ url, altText }) => {
return (
<img className="images" src=""
)
}
29 changes: 29 additions & 0 deletions src/components/Loader.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Lottie from 'react-lottie'
import animationData from '../lotties/animation.json'

export const Loader = () => {


const defaultOptions = {
loop: true,
autoplay: true,
animationData: animationData,
rendererSettings: {
preserveAspectRatio: 'xMidYMid slice',
},
}

return (
<div>
<Lottie options={defaultOptions} height={300} width={300} />
</div>
)
}

//nedan är försök att få animationen att visas längre.

// useEffect(() => {
// export const DelayLottie = setTimeout(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the next time you might want to consider creating the function "DelayLottie" before (for example, around line 5) and then you can call the function inside of the useEffect. 👍
-Izabel&Etna

// setLoading(true)
// }, 3000)
// })
21 changes: 21 additions & 0 deletions src/components/Nav.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react'
import { Link, NavLink } from 'react-router-dom'
import '../styling/Nav.css'

export const Nav = () => {
return (
<>
<div className="navbar-title">
<h1>RomComs</h1>
</div>
<ul className="navbar">
<li>
<NavLink to="/">Movies</NavLink>
</li>
<li>
<NavLink to="/details">Details</NavLink>
</li>
</ul>
</>
)
}
5 changes: 5 additions & 0 deletions src/components/NotFound.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const NotFound = () => {
return (
<div>Page not found</div>
)
}
47 changes: 47 additions & 0 deletions src/components/PopularList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import '../styling/PopularList.css'
import { Link } from 'react-router-dom'

//functional component
export const PopularList = ({ movieData }) => {
console.log('moviedata popularLIst', movieData)

return (
<div className="movie-wrapper">
<div className="movie-list">
{movieData &&
movieData.results.map((movie) => (
<Link key={movie.id} to={`/details/${movie.id}`}>
<div className="movie-card" key={movie.id}>
<div className="hover-text">
<h1 className="title">{movie.title}</h1>
<h2 className="release-date">
Released {movie.release_date}
</h2>
</div>
<div className="poster">
<img
className="movie-image"
src={`https://image.tmdb.org/t/p/w342${movie.poster_path}`}
alt={`Movie poster for ${movie.title}`}
/>
</div>
</div>
</Link>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks great but it gets a bit complicated to read due to the unorganised set up.
-Izabel&Etna

))}
</div>
</div>
)
}



// return (
// <>
// {jsonMovies.map((movie) => (
// <article className="movie-card" key={movie.id}>
// <Link to={`/details/${movie.id}`}></Link>
// </article>
// ))}
// </>
// )
// }
45 changes: 45 additions & 0 deletions src/components/SecondPage.jsx

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is interesting how you split in two different components the fetching and the data rendering. Maybe you can explain us why you choose that logic 😊.
-Izabel&Etna

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import '../styling/SecondPage.css'
import { useState, useEffect } from 'react'
import { Loader } from './Loader'
import {NotFound} from './NotFound'
import {Link, useParams} from 'react-router-dom'
import { DetailList } from './DetailList'

export const Details = () => {
const [detailData, setDetailData] = useState(null)
const [isLoading, setIsLoading] = useState(true)

const params = useParams()
const movieId = params.slug
const API_KEY = '23ace2b0c27910f5cec13f5bdb014044'

const listUrl =
`https://api.themoviedb.org/3/movie/${movieId}?api_key=${API_KEY}&language=en-US`

useEffect(() => {
fetch(listUrl)
.then((result) => result.json())
.then((json) => {
setDetailData(json)
setIsLoading(false)
})
.catch((error) => {
console.error(error)
})
}, [listUrl])

if (!detailData || detailData === undefined) {
return <Loader />
}

if (detailData.success === false) {
return <NotFound />
}
console.log('detailtdata secondpage', detailData)
return (
<>
{isLoading && <Loader />}
<DetailList detailData={detailData} />
</>
)
}
1 change: 1 addition & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background-color: rgb(252, 213, 220);
}

code {
Expand Down
Loading