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 administracja from "../../../data/administracja.json";
import { useEffect, useState } from "react";
import { SEO } from "../../../components/SEO";
const ProfilePage = () => {
const router = useRouter();
const profname = router.query.profname as string;
if (
administracja
.map((el) => {
return el.name.replaceAll(" ", "-").toLocaleLowerCase();
type personsSchema = {
Id: string;
Name: string;
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)
) {
const person = administracja.filter((wpis) => {
return wpis.name.replaceAll(" ", "-").toLocaleLowerCase() === profname;
})[0];
return (
<main>
<div
style={{
display: "flex",
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>
);
.then((data) => {
setPersons(data);
setLoading(false);
})
.catch((err) => {
console.log(err);
});
}, []);
if (loading) {
return <main style={{ color: "grey" }}>Fetching data...</main>;
} else {
return (
<main>
<h1>Sorki!{" :("}</h1>
<p style={{ lineHeight: "30px" }}>
Sprawdź pisownię:
<span
if (
persons
.map((el: personsSchema) => {
return el.Name.replaceAll(" ", "-").toLocaleLowerCase();
})
.includes(profname)
) {
const person: personsSchema = persons.filter((wpis: personsSchema) => {
return wpis.Name.replaceAll(" ", "-").toLocaleLowerCase() === profname;
})[0];
return (
<main>
<SEO title={person.Name} />
<div
style={{
background: "var(--black1)",
boxShadow: "var(--shadow0)",
padding: "8px",
margin: "10px",
borderRadius: "4px",
display: "flex",
flexDirection: "row",
alignItems: "center",
gap: "1rem",
marginBottom: "1rem",
}}
>
{`/profile/${profname}`}
</span>
nie jest poprawnym lokatorem profilu.
</p>
</main>
);
<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>
{/* 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>
);
}
}
};