-
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
Bob Liu
authored and
Bob Liu
committed
Mar 27, 2023
1 parent
76dbada
commit 0f6c5d3
Showing
10 changed files
with
138 additions
and
119 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 |
---|---|---|
@@ -1,39 +1,48 @@ | ||
import React, {useEffect, useState} from "react" | ||
import "./gameList.css" | ||
import { useParams } from "react-router-dom" | ||
import Cards from "../card/card" | ||
import React, { useEffect, useState } from "react"; | ||
import "./gameList.css"; | ||
import { useParams } from "react-router-dom"; | ||
import Cards from "../card/card"; | ||
import Papa from "papaparse"; | ||
import gameDataCSV from "../../database/gamedb.csv"; | ||
|
||
const GameList = () => { | ||
|
||
const [gameList, setGameList] = useState([]) | ||
const {type} = useParams() | ||
|
||
useEffect(() => { | ||
getData() | ||
}, []) | ||
|
||
useEffect(() => { | ||
getData() | ||
}, [type]) | ||
const [gameList, setGameList] = useState([]); | ||
const { type } = useParams(); | ||
|
||
useEffect(() => { | ||
const getData = () => { | ||
fetch(`https://api.themoviedb.org/3/movie/${type ? type : "popular"}?api_key=4e44d9029b1270a757cddc766a1bcb63&language=en-US`) | ||
.then(res => res.json()) | ||
.then(data => setGameList(data.results)) | ||
} | ||
Papa.parse(gameDataCSV, { | ||
header: true, | ||
download: true, | ||
dynamicTyping: true, | ||
complete: (results) => { | ||
let data = results.data; | ||
if (type) { | ||
if (type.toLowerCase() === "popular" || type.toLowerCase() === "top_rated") { | ||
data.sort((a, b) => b.rating - a.rating); | ||
data = data.slice(0, 50); // Show top 50 games | ||
} else { | ||
data = data.filter((game) => game.genre.toLowerCase() === type.toLowerCase()); | ||
} | ||
} | ||
setGameList(data); | ||
}, | ||
}); | ||
}; | ||
|
||
getData(); | ||
}, [type]); | ||
|
||
return ( | ||
<div className="game__list"> | ||
<h2 className="list__title">{(type ? type : "POPULAR").toUpperCase()}</h2> | ||
<div className="list__cards"> | ||
{ | ||
gameList.map(game => ( | ||
<Cards game={game} /> | ||
)) | ||
} | ||
</div> | ||
</div> | ||
) | ||
} | ||
return ( | ||
<div className="game__list"> | ||
<h2 className="list__title">{(type ? type : "ALL").toUpperCase()}</h2> | ||
<div className="list__cards"> | ||
{gameList.map((game) => ( | ||
<Cards key={game.game_id} game={game} /> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GameList | ||
export default GameList; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
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,90 +1,78 @@ | ||
import React, {useEffect, useState} from "react" | ||
import "./game.css" | ||
import { useParams } from "react-router-dom" | ||
import React, { useEffect, useState } from "react"; | ||
import "./game.css"; | ||
import { useParams } from "react-router-dom"; | ||
import Papa from "papaparse"; | ||
import gameDataCSV from "../../database/gamedb.csv"; | ||
|
||
const Game = () => { | ||
const [currentGameDetail, setGame] = useState() | ||
const { id } = useParams() | ||
const [currentGameDetail, setGame] = useState(); | ||
const { id } = useParams(); | ||
|
||
useEffect(() => { | ||
getData() | ||
window.scrollTo(0,0) | ||
}, []) | ||
useEffect(() => { | ||
getData(); | ||
window.scrollTo(0, 0); | ||
}, []); | ||
|
||
const getData = () => { | ||
fetch(`https://api.themoviedb.org/3/movie/${id}?api_key=4e44d9029b1270a757cddc766a1bcb63&language=en-US`) | ||
.then(res => res.json()) | ||
.then(data => setGame(data)) | ||
} | ||
const getData = () => { | ||
Papa.parse(gameDataCSV, { | ||
header: true, | ||
download: true, | ||
dynamicTyping: true, | ||
complete: (results) => { | ||
const game = results.data.find((game) => game.game_id === parseInt(id)); | ||
setGame(game); | ||
}, | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className="game"> | ||
<div className="game__intro"> | ||
<img className="game__backdrop" src={`https://image.tmdb.org/t/p/original${currentGameDetail ? currentGameDetail.backdrop_path : ""}`} /> | ||
return ( | ||
<div className="game"> | ||
<div className="game__intro"> | ||
<img | ||
className="game__backdrop" | ||
src={currentGameDetail ? currentGameDetail.game_image : ""} | ||
/> | ||
</div> | ||
<div className="game__detail"> | ||
<div className="game__detailLeft"> | ||
<div className="game__posterBox"> | ||
<img | ||
className="game__poster" | ||
src={currentGameDetail ? currentGameDetail.game_image : ""} | ||
/> | ||
</div> | ||
</div> | ||
<div className="game__detailRight"> | ||
<div className="game__detailRightTop"> | ||
<div className="game__name"> | ||
{currentGameDetail ? currentGameDetail.name : ""} | ||
</div> | ||
<div className="game__genre"> | ||
{currentGameDetail ? currentGameDetail.genre : ""} | ||
</div> | ||
<div className="game__rating"> | ||
{currentGameDetail ? currentGameDetail.rating : ""} | ||
<i className="fas fa-star" /> | ||
</div> | ||
<div className="game__detail"> | ||
<div className="game__detailLeft"> | ||
<div className="game__posterBox"> | ||
<img className="game__poster" src={`https://image.tmdb.org/t/p/original${currentGameDetail ? currentGameDetail.poster_path : ""}`} /> | ||
</div> | ||
</div> | ||
<div className="game__detailRight"> | ||
<div className="game__detailRightTop"> | ||
<div className="game__name">{currentGameDetail ? currentGameDetail.original_title : ""}</div> | ||
<div className="game__tagline">{currentGameDetail ? currentGameDetail.tagline : ""}</div> | ||
<div className="game__rating"> | ||
{currentGameDetail ? currentGameDetail.vote_average: ""} <i class="fas fa-star" /> | ||
<span className="game__voteCount">{currentGameDetail ? "(" + currentGameDetail.vote_count + ") votes" : ""}</span> | ||
</div> | ||
<div className="game__runtime">{currentGameDetail ? currentGameDetail.runtime + " mins" : ""}</div> | ||
<div className="game__releaseDate">{currentGameDetail ? "Release date: " + currentGameDetail.release_date : ""}</div> | ||
<div className="game__genres"> | ||
{ | ||
currentGameDetail && currentGameDetail.genres | ||
? | ||
currentGameDetail.genres.map(genre => ( | ||
<><span className="game__genre" id={genre.id}>{genre.name}</span></> | ||
)) | ||
: | ||
"" | ||
} | ||
</div> | ||
</div> | ||
<div className="game__detailRightBottom"> | ||
<div className="synopsisText">Synopsis</div> | ||
<div>{currentGameDetail ? currentGameDetail.overview : ""}</div> | ||
</div> | ||
|
||
</div> | ||
<div className="game__developer"> | ||
{currentGameDetail ? currentGameDetail.developer : ""} | ||
</div> | ||
<div className="game__links"> | ||
<div className="game__heading">Useful Links</div> | ||
{ | ||
currentGameDetail && currentGameDetail.homepage && <a href={currentGameDetail.homepage} target="_blank" style={{textDecoration: "none"}}><p><span className="game__homeButton game__Button">Homepage <i className="newTab fas fa-external-link-alt"></i></span></p></a> | ||
} | ||
{ | ||
currentGameDetail && currentGameDetail.imdb_id && <a href={"https://www.imdb.com/title/" + currentGameDetail.imdb_id} target="_blank" style={{textDecoration: "none"}}><p><span className="game__steamButton game__Button">Steam<i className="newTab fas fa-external-link-alt"></i></span></p></a> | ||
} | ||
<div className="game__releaseDate"> | ||
{currentGameDetail | ||
? `Release date: ${currentGameDetail.release_year}-${currentGameDetail.release_month}-${currentGameDetail.release_day}` | ||
: ""} | ||
</div> | ||
<div className="game__heading">Production companies</div> | ||
<div className="game__production"> | ||
{ | ||
currentGameDetail && currentGameDetail.production_companies && currentGameDetail.production_companies.map(company => ( | ||
<> | ||
{ | ||
company.logo_path | ||
&& | ||
<span className="productionCompanyImage"> | ||
<img className="game__productionComapany" src={"https://image.tmdb.org/t/p/original" + company.logo_path} /> | ||
<span>{company.name}</span> | ||
</span> | ||
} | ||
</> | ||
)) | ||
} | ||
</div> | ||
<div className="game__detailRightBottom"> | ||
<div className="synopsisText">Synopsis</div> | ||
<div> | ||
{currentGameDetail ? currentGameDetail.description : ""} | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Game | ||
export default Game; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
{ | ||
"dependencies": { | ||
"papaparse": "^5.4.1" | ||
} | ||
} |