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