feat: Add 'Would Play' and 'Would Not Play' buttons to game list items and update button styling.
This commit is contained in:
parent
03de073692
commit
e63f1a45cf
@ -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,27 +458,82 @@ 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 (
|
||||||
<Link
|
<div>
|
||||||
to={`/game/${encodeURIComponent(game.title)}`}
|
<Link
|
||||||
key={game.title}
|
to={`/game/${encodeURIComponent(game.title)}`}
|
||||||
className="list-item"
|
key={game.title}
|
||||||
style={{
|
className="list-item"
|
||||||
textDecoration: "none",
|
style={{
|
||||||
color: "inherit",
|
textDecoration: "none",
|
||||||
display: "flex",
|
color: "inherit",
|
||||||
justifyContent: "space-between",
|
display: "flex",
|
||||||
alignItems: "center",
|
justifyContent: "space-between",
|
||||||
borderColor: opinion
|
alignItems: "center",
|
||||||
? opinion.wouldPlay
|
borderColor: opinion
|
||||||
? "#4caf50" // would play (green)
|
? opinion.wouldPlay
|
||||||
: "#f44336" // would not play (red)
|
? "#4caf50" // would play (green)
|
||||||
: "#191f2e", // no opinion (bg-2)
|
: "#f44336" // would not play (red)
|
||||||
}}
|
: "#191f2e", // no opinion (bg-2)
|
||||||
>
|
}}
|
||||||
<strong>{game.title}</strong>
|
>
|
||||||
<GameImage game={game.title} />
|
<strong>{game.title}</strong>
|
||||||
</Link>
|
<GameImage game={game.title} />
|
||||||
|
</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>
|
||||||
|
|||||||
@ -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>
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user