generated from jbohde/vite-apollo-mongo
-
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
Showing
6 changed files
with
90 additions
and
145 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,78 +1,25 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
const Results = (props) => { | ||
|
||
const { gameId } = useParams(); | ||
|
||
const Results = ({ game }) => { | ||
return ( | ||
<div className="results-container"> | ||
<ul> | ||
<div className='results-container'> | ||
{ | ||
props.gameResults.map(game => ( | ||
<li key={game.id}> | ||
|
||
<Link to={{ | ||
pathname: `/game/${gameId}`, | ||
gameProps:{ | ||
game: game | ||
} | ||
}}> | ||
<div> | ||
<Link | ||
to={{ | ||
pathname: `/game/${game.id}`, | ||
gameProps: { | ||
game: game, | ||
}, | ||
}} | ||
> | ||
<h3>{game.name}</h3> | ||
<img src={game.background_image} alt="game"/> | ||
</Link> | ||
|
||
</li> | ||
)) | ||
<img src={game.background_image} alt='game' /> | ||
</Link> | ||
</div> | ||
} | ||
</ul> | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
export default Results; | ||
|
||
// import { useParams } from 'react-router-dom'; | ||
// import { useEffect, useState } from 'react'; | ||
// import ResultsPage from '../pages/Results/ResultsPage' | ||
// import ResultsBackground from '../assets/results-background.png' | ||
|
||
// const Results = () => { | ||
|
||
// const { gameId } = useParams(); | ||
|
||
// useEffect(() => { | ||
// fetchGame(); | ||
// }, []); | ||
|
||
// const [game, setGame] = useState([]); | ||
|
||
// const fetchGame = async () => { | ||
// await fetch( | ||
// `https://api.rawg.io/api/games/${gameId}?key=bf22dc51e531456db8bc42a19dac9897` | ||
// ) | ||
// .then((resp) => resp.json()) | ||
// .then((results) => setGame(results)); | ||
// }; | ||
|
||
// return ( | ||
// <div | ||
// className='results' | ||
// style={{ | ||
// width: '100%', | ||
// minHeight: '100vh', | ||
// backgroundImage: `url(${ResultsBackground})`, | ||
// backgroundSize: 'cover', | ||
// backgroundPosition: 'center', | ||
// overflow: 'hidden', | ||
// }} | ||
// > | ||
// <div className='results-info'> | ||
// <ResultsPage game={game} /> | ||
// </div> | ||
// </div> | ||
// ); | ||
// } | ||
|
||
// export default Results; |
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 |
---|---|---|
@@ -1,42 +1,30 @@ | ||
import Results from '../../components/Results'; | ||
import { useParams } from 'react-router-dom'; | ||
import { useEffect, useState } from 'react'; | ||
import { useLocation } from 'react-router-dom'; | ||
import ResultsBackground from '../../assets/results-background.png'; | ||
|
||
const GameResults = () => { | ||
const { gameId } = useParams(); | ||
|
||
useEffect(() => { | ||
fetchGame(); | ||
}, []); | ||
|
||
const [game, setGame] = useState([]); | ||
|
||
const fetchGame = async () => { | ||
await fetch( | ||
`https://api.rawg.io/api/games/${gameId}?key=bf22dc51e531456db8bc42a19dac9897` | ||
) | ||
.then((resp) => resp.json()) | ||
.then((results) => setGame(results)); | ||
}; | ||
|
||
return ( | ||
<div | ||
className='results' | ||
style={{ | ||
width: '100%', | ||
minHeight: '100vh', | ||
backgroundImage: `url(${ResultsBackground})`, | ||
backgroundSize: 'cover', | ||
backgroundPosition: 'center', | ||
overflow: 'hidden', | ||
}} | ||
> | ||
<div className='game-info'> | ||
<Results game={game} /> | ||
</div> | ||
const location = useLocation(); | ||
const gameResults = location.state.results; | ||
|
||
return ( | ||
<div | ||
className='results' | ||
style={{ | ||
width: '100%', | ||
minHeight: '100vh', | ||
backgroundImage: `url(${ResultsBackground})`, | ||
backgroundSize: 'cover', | ||
backgroundPosition: 'center', | ||
overflow: 'hidden', | ||
}} | ||
> | ||
<div className='game-info'> | ||
{gameResults.map((game, index) => ( | ||
<Results key={index} game={game} /> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default GameResults; | ||
</div> | ||
); | ||
}; | ||
|
||
export default GameResults; |