forked from b00tc4mp/isdi-bootcamp-202405
-
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.
implement search game logic and react components b00tc4mp#84
- Loading branch information
Showing
8 changed files
with
96 additions
and
8 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,27 @@ | ||
import Container from '../library/Container' | ||
import Image from '../library/Image' | ||
import Paragraph from '../library/Paragraph' | ||
|
||
export default function Game({ game }) { | ||
const handleGameClick = () => { | ||
window.location.href = game.link | ||
} | ||
|
||
return <article className='flex flex-row items-center border border-solid border-slate-700 dark:bg-black'> | ||
<button className='bg-transparent border-0' onClick={handleGameClick}> | ||
<Container className='flex flex-col'> | ||
<Container className='flex flex-row items-center'> | ||
<Image className='w-2/12 h-2/12' src={game.image} /> | ||
<Paragraph>{game.name}</Paragraph> | ||
</Container> | ||
<Container> | ||
<Paragraph>{game.description}</Paragraph> | ||
</Container> | ||
</Container> | ||
</button> | ||
<Container className='flex flex-col gap-2 mr-2'> | ||
<button className='bg-gray-500 rounded'>Add</button> | ||
<button className='bg-green-300 rounded'>Fav</button> | ||
</Container> | ||
</article> | ||
} |
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
48 changes: 48 additions & 0 deletions
48
staff/marti-herms/project/V-HUB/app/src/home/GameSearchResults.jsx
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,48 @@ | ||
import { useState, useEffect } from 'react' | ||
import { useSearchParams } from 'react-router-dom' | ||
|
||
import logic from '../../logic' | ||
import Game from './Game' | ||
|
||
export default function GameSearchResults({ refreshStamp }) { | ||
const [searchParams] = useSearchParams() | ||
|
||
const q = searchParams.get('q') || '' | ||
|
||
const [games, setGames] = useState([]) | ||
|
||
useEffect(() => { | ||
loadGames() | ||
}, [refreshStamp, q]) | ||
|
||
const loadGames = () => { | ||
try { | ||
logic.searchGame(q) | ||
.then(games => setGames(games)) | ||
.catch(error => { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
}) | ||
} catch { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
const maxView = 5 | ||
|
||
let count = 0 | ||
|
||
return <section className='flex flex-col gap-4'> | ||
{games.map(game => { | ||
count++ | ||
|
||
if (count <= maxView) | ||
return <Game key={game.id} game={game} /> | ||
|
||
return | ||
})} | ||
</section> | ||
} |
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,3 @@ | ||
export default function Image(props) { | ||
return <img {...props} /> | ||
} |
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