feat: Add 'Would Play' and 'Would Not Play' buttons to game list items and update button styling.

This commit is contained in:
code002lover 2025-12-04 21:27:27 +01:00
parent 03de073692
commit e63f1a45cf
3 changed files with 85 additions and 23 deletions

View File

@ -5,6 +5,7 @@ import {
GameList as GameListProto, GameList as GameListProto,
Person as PersonProto, Person as PersonProto,
Opinion, Opinion,
AddOpinionRequest,
} from "../items"; } from "../items";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { apiFetch, get_auth_status } from "./api"; import { apiFetch, get_auth_status } from "./api";
@ -457,7 +458,34 @@ export function GameList() {
<ul className="grid-container"> <ul className="grid-container">
{games.map((game) => { {games.map((game) => {
const opinion = opinions.find((op) => op.title === game.title); const opinion = opinions.find((op) => op.title === game.title);
function handleOpinion(title: string, wouldPlay: boolean): void {
apiFetch(`/api/opinion`, {
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
},
body: AddOpinionRequest.encode(
AddOpinionRequest.create({
gameTitle: title,
wouldPlay,
})
).finish(),
})
.then((res) => res.arrayBuffer())
.then((resBuffer) => {
const response = PersonProto.decode(
new Uint8Array(resBuffer)
);
setOpinions(response.opinion);
})
.catch((err) => {
console.error(err);
});
}
return ( return (
<div>
<Link <Link
to={`/game/${encodeURIComponent(game.title)}`} to={`/game/${encodeURIComponent(game.title)}`}
key={game.title} key={game.title}
@ -478,6 +506,34 @@ export function GameList() {
<strong>{game.title}</strong> <strong>{game.title}</strong>
<GameImage game={game.title} /> <GameImage game={game.title} />
</Link> </Link>
<div
style={{
display: "flex",
gap: "1rem",
marginTop: "1rem",
width: "100%",
}}
>
<button
onClick={() => handleOpinion(game.title, true)}
style={{
width: "50%",
borderColor: "#4caf50",
}}
>
Would Play
</button>
<button
onClick={() => handleOpinion(game.title, false)}
style={{
width: "50%",
borderColor: "#f44336",
}}
>
Would Not Play
</button>
</div>
</div>
); );
})} })}
</ul> </ul>

View File

@ -167,7 +167,13 @@ export const PersonDetails = () => {
Would Play Would Play
</label> </label>
</div> </div>
<button onClick={handleAddOpinion} style={{ marginBottom: "2px" }}> <button
onClick={handleAddOpinion}
style={{
marginBottom: "2px",
backgroundColor: "var(--accent-color)",
}}
>
Add Add
</button> </button>
</div> </div>

View File

@ -54,14 +54,14 @@ button {
font-size: 1em; font-size: 1em;
font-weight: 500; font-weight: 500;
font-family: inherit; font-family: inherit;
background-color: var(--accent-color); background-color: var(--secondary-bg);
color: white; color: white;
cursor: pointer; cursor: pointer;
transition: background-color 0.25s, transform 0.1s; transition: background-color 0.25s, transform 0.1s;
} }
button:hover { button:hover {
background-color: #0b7dda; background-color: var(--tertiary-bg);
} }
button:active { button:active {