diff --git a/frontend/src/PersonDetails.tsx b/frontend/src/PersonDetails.tsx index b55688a..240b3d5 100644 --- a/frontend/src/PersonDetails.tsx +++ b/frontend/src/PersonDetails.tsx @@ -1,44 +1,12 @@ import { useState, useEffect } from "react"; import { Link, useParams } from "react-router-dom"; -import { Person, AddOpinionRequest, Game, GameList } from "../items"; -import { apiFetch, get_auth_status } from "./api"; +import { Person } from "../items"; +import { apiFetch } from "./api"; import { GameImage } from "./GameImage"; export const PersonDetails = () => { const { name } = useParams<{ name: string }>(); const [person, setPerson] = useState(null); - const [games, setGames] = useState([]); - const [gameTitle, setGameTitle] = useState(""); - const [wouldPlay, setWouldPlay] = useState(false); - const [currentUser, setCurrentUser] = useState(""); - - useEffect(() => { - async function fetchUser() { - const token = localStorage.getItem("token"); - if (token) { - const authStatus = await get_auth_status(); - setCurrentUser(authStatus?.username || ""); - } - } - fetchUser(); - }, []); - - useEffect(() => { - apiFetch("/api/games") - .then((res) => res.arrayBuffer()) - .then((buffer) => { - try { - const list = GameList.decode(new Uint8Array(buffer)); - setGames(list.games); - if (list.games.length > 0) { - setGameTitle(list.games[0].title); - } - } catch (e) { - console.error("Failed to decode games:", e); - } - }) - .catch(console.error); - }, []); useEffect(() => { if (name) { @@ -55,36 +23,6 @@ export const PersonDetails = () => { } }, [name]); - const handleAddOpinion = async () => { - if (!person) return; - - const req = AddOpinionRequest.create({ - gameTitle, - wouldPlay, - }); - - const buffer = AddOpinionRequest.encode(req).finish(); - - try { - const res = await apiFetch("/api/opinion", { - method: "POST", - headers: { - "Content-Type": "application/octet-stream", - }, - body: buffer, - }); - - if (res.ok) { - const resBuffer = await res.arrayBuffer(); - setPerson(Person.decode(new Uint8Array(resBuffer))); - setGameTitle(""); - setWouldPlay(false); - } - } catch (e) { - console.error(e); - } - }; - if (!person) return
Loading...
; return ( @@ -113,89 +51,6 @@ export const PersonDetails = () => { ))} - - {currentUser === name && ( -
-

Add Opinion

-
-
- - -
-
- setWouldPlay(e.target.checked)} - id="wouldPlay" - /> - -
- -
-
- - {gameTitle} - - -
-
- )} ); };