feat: add current user detection and conditional routing for PersonList items, removing refresh functionality.

This commit is contained in:
code002lover 2025-12-05 14:51:25 +01:00
parent 44989f1889
commit b1b6b0ce4d

View File

@ -1,12 +1,19 @@
import { Person } from "../items"; import { Person } from "../items";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { useState } from "react";
import { get_auth_status } from "./api";
interface Props { interface Props {
people: Person[]; people: Person[];
onRefresh: () => void;
} }
export const PersonList = ({ people, onRefresh }: Props) => { export const PersonList = ({ people }: Props) => {
const [current_user, set_current_user] = useState<string>("");
get_auth_status().then((res) => {
if (res) {
set_current_user(res.username);
}
});
return ( return (
<div> <div>
<div <div
@ -18,35 +25,41 @@ export const PersonList = ({ people, onRefresh }: Props) => {
}} }}
> >
<h2>People List</h2> <h2>People List</h2>
<button onClick={onRefresh} className="btn-secondary">
Refresh List
</button>
</div> </div>
<div className="grid-container"> <div className="grid-container">
{people.map((person, index) => ( {people.map((person, index) => {
<Link if (person.name == current_user) {
to={`/person/${person.name}`} return (
key={index} <Link
className="list-item" to={`/games`}
style={{ key={index}
textDecoration: "none", className="list-item"
color: "inherit", style={{
display: "block", textDecoration: "none",
}} color: "inherit",
> display: "block",
<h3>{person.name}</h3> }}
<ul> >
{person.opinion.map((op, i) => ( <h3>{person.name}</h3>
<li </Link>
key={i} );
style={{ color: op.wouldPlay ? "#4caf50" : "#f44336" }} }
>
{op.title} - {op.wouldPlay ? "Would Play" : "Would Not Play"} return (
</li> <Link
))} to={`/person/${person.name}`}
</ul> key={index}
</Link> className="list-item"
))} style={{
textDecoration: "none",
color: "inherit",
display: "block",
}}
>
<h3>{person.name}</h3>
</Link>
);
})}
</div> </div>
</div> </div>
); );