make userprofiles rely on fetched data rather than local json

This commit is contained in:
2022-12-27 14:22:15 +01:00
parent 78cd106752
commit 362c829c13
2 changed files with 90 additions and 116 deletions

View File

@@ -1,58 +0,0 @@
[
{
"name": "jamesen",
"desc": "project pioneer.",
"img": "https://i.imgur.com/CBRxP3Z.png",
"devBadge": true,
"profile": {
"bigdesc": ["Tutaj będzie kiedyś opis profilu."],
"links": [
{
"resname": "Website",
"href": "https://manczak.net"
}
]
}
},
{
"name": "Mollin",
"desc": "porucznik essy.",
"img": "https://i.imgur.com/64sHQjM.jpg",
"profile": {
"bigdesc": ["Tutaj będzie kiedyś opis profilu."]
}
},
{
"name": "Elephant",
"desc": "osobnik demencyjny.",
"img": "https://i.imgur.com/INQM1Cd.png",
"profile": {
"bigdesc": ["Tutaj będzie kiedyś opis profilu."]
}
},
{
"name": "Dzioba",
"desc": "backend bastard.",
"img": "https://i.imgur.com/0gUirZH.png",
"devBadge": true,
"profile": {
"bigdesc": ["Tutaj będzie kiedyś opis profilu."]
}
},
{
"name": "KuOlek",
"desc": "duch. (bo go nie ma)",
"img": "https://i.imgur.com/SCTXTtz.png",
"profile": {
"bigdesc": ["Tutaj będzie kiedyś opis profilu."]
}
},
{
"name": "Bavil Gravlax",
"desc": "śpiący rękawek.",
"img": "https://i.imgur.com/6bxpBgK.png",
"profile": {
"bigdesc": ["Tutaj będzie kiedyś opis profilu."]
}
}
]

View File

@@ -1,71 +1,103 @@
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import administracja from "../../../data/administracja.json"; import { useEffect, useState } from "react";
import { SEO } from "../../../components/SEO";
const ProfilePage = () => { const ProfilePage = () => {
const router = useRouter(); const router = useRouter();
const profname = router.query.profname as string; const profname = router.query.profname as string;
if ( type personsSchema = {
administracja Id: string;
.map((el) => { Name: string;
return el.name.replaceAll(" ", "-").toLocaleLowerCase(); Desc?: string;
Img?: string;
IsAdmin?: boolean;
DevBadge?: boolean;
AssignedUser?: string;
};
const [persons, setPersons] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
fetch("https://gractwo.pl/api/v1/admincards")
.then((res) => {
return res.json();
}) })
.includes(profname) .then((data) => {
) { setPersons(data);
const person = administracja.filter((wpis) => { setLoading(false);
return wpis.name.replaceAll(" ", "-").toLocaleLowerCase() === profname; })
})[0]; .catch((err) => {
return ( console.log(err);
<main> });
<div }, []);
style={{ if (loading) {
display: "flex", return <main style={{ color: "grey" }}>Fetching data...</main>;
flexDirection: "row",
alignItems: "center",
gap: "1rem",
marginBottom: "1rem",
}}
>
<img
src={person.img}
alt={`${person.name} profile image`}
style={{
width: "128px",
aspectRatio: "1/1",
objectFit: "cover",
borderRadius: "50%",
}}
/>
<div>
<h1>{person.name}</h1>
<p>{person.desc}</p>
</div>
</div>
{person.profile?.bigdesc.map((el, index) => {
return <p key={index}>{el || <br />}</p>;
})}
</main>
);
} else { } else {
return ( if (
<main> persons
<h1>Sorki!{" :("}</h1> .map((el: personsSchema) => {
<p style={{ lineHeight: "30px" }}> return el.Name.replaceAll(" ", "-").toLocaleLowerCase();
Sprawdź pisownię: })
<span .includes(profname)
) {
const person: personsSchema = persons.filter((wpis: personsSchema) => {
return wpis.Name.replaceAll(" ", "-").toLocaleLowerCase() === profname;
})[0];
return (
<main>
<SEO title={person.Name} />
<div
style={{ style={{
background: "var(--black1)", display: "flex",
boxShadow: "var(--shadow0)", flexDirection: "row",
padding: "8px", alignItems: "center",
margin: "10px", gap: "1rem",
borderRadius: "4px", marginBottom: "1rem",
}} }}
> >
{`/profile/${profname}`} <img
</span> src={person.Img}
nie jest poprawnym lokatorem profilu. alt={`${person.Name} profile image`}
</p> style={{
</main> width: "128px",
); aspectRatio: "1/1",
objectFit: "cover",
borderRadius: "50%",
}}
/>
<div>
<h1>{person.Name}</h1>
<p>{person.Desc}</p>
</div>
</div>
{/* FOR LATER BIGDESC DATASET */}
{/* {person.profile?.bigdesc.map((el, index) => {
return <p key={index}>{el || <br />}</p>;
})} */}
</main>
);
} else {
return (
<main>
<SEO title="nieznany profil" />
<h1>Sorki!{" :("}</h1>
<p style={{ lineHeight: "30px" }}>
Sprawdź pisownię:
<span
style={{
background: "var(--black1)",
boxShadow: "var(--shadow0)",
padding: "8px",
margin: "10px",
borderRadius: "4px",
}}
>
{`/profile/${profname}`}
</span>
nie jest poprawnym lokatorem profilu.
</p>
</main>
);
}
} }
}; };