feat: add current user detection and conditional routing for PersonList items, removing refresh functionality.
This commit is contained in:
parent
44989f1889
commit
b1b6b0ce4d
@ -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,12 +25,27 @@ 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) => {
|
||||||
|
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
|
<Link
|
||||||
to={`/person/${person.name}`}
|
to={`/person/${person.name}`}
|
||||||
key={index}
|
key={index}
|
||||||
@ -35,18 +57,9 @@ export const PersonList = ({ people, onRefresh }: Props) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<h3>{person.name}</h3>
|
<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>
|
</Link>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user