generated from goitacademy/react-homework-template
-
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.
- Loading branch information
1 parent
a17a5fb
commit f78450a
Showing
5 changed files
with
143 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { getMovieCredits } from '../../api'; | ||
import styles from './Cast.module.css'; | ||
|
||
const Cast = () => { | ||
const { movieId } = useParams(); | ||
const [cast, setCast] = useState([]); | ||
|
||
useEffect(() => { | ||
const fetchMovieCredits = async () => { | ||
try { | ||
const data = await getMovieCredits(movieId); | ||
setCast(data.cast); | ||
} catch (error) { | ||
console.error('Failed to fetch movie credits:', error); | ||
} | ||
}; | ||
|
||
fetchMovieCredits(); | ||
}, [movieId]); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<button onClick={() => window.history.back()} className={styles.button}> | ||
Go back | ||
</button> | ||
<h3>Cast</h3> | ||
<ul className={styles.list}> | ||
{cast.map(actor => ( | ||
<li key={actor.cast_id} className={styles.item}> | ||
<img | ||
src={`https://image.tmdb.org/t/p/w200${actor.profile_path}`} | ||
alt={actor.name} | ||
className={styles.image} | ||
/> | ||
<p>{actor.name}</p> | ||
<p>Character: {actor.character}</p> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Cast; |
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,22 @@ | ||
.container { | ||
padding: 20px; | ||
} | ||
|
||
.list { | ||
list-style: none; | ||
padding: 0; | ||
} | ||
|
||
.item { | ||
margin-bottom: 20px; | ||
} | ||
|
||
.image { | ||
width: 100px; | ||
margin-right: 20px; | ||
} | ||
|
||
.button { | ||
padding: 8px 16px; | ||
margin-bottom: 20px; | ||
} |
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,49 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { getMovieReviews } from '../../api'; | ||
import styles from './Reviews.module.css'; | ||
|
||
const Reviews = () => { | ||
const { movieId } = useParams(); | ||
const [reviews, setReviews] = useState([]); | ||
|
||
useEffect(() => { | ||
const fetchMovieReviews = async () => { | ||
try { | ||
const data = await getMovieReviews(movieId); | ||
setReviews(data.results); | ||
} catch (error) { | ||
console.error('Failed to fetch movie reviews:', error); | ||
} | ||
}; | ||
|
||
fetchMovieReviews(); | ||
}, [movieId]); | ||
|
||
if (reviews.length === 0) { | ||
return ( | ||
<p className={styles.message}> | ||
We don't have any reviews for this movie. | ||
</p> | ||
); | ||
} | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<button onClick={() => window.history.back()} className={styles.button}> | ||
Go back | ||
</button> | ||
<h3>Reviews</h3> | ||
<ul className={styles.list}> | ||
{reviews.map(review => ( | ||
<li key={review.id} className={styles.item}> | ||
<h4>{review.author}</h4> | ||
<p>{review.content}</p> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Reviews; |
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,22 @@ | ||
.container { | ||
padding: 20px; | ||
} | ||
|
||
.list { | ||
list-style: none; | ||
padding: 0; | ||
} | ||
|
||
.item { | ||
margin-bottom: 20px; | ||
} | ||
|
||
.message { | ||
padding: 20px; | ||
font-size: 18px; | ||
} | ||
|
||
.button { | ||
padding: 8px 16px; | ||
margin-bottom: 20px; | ||
} |