From 362c829c135598cbd2cd2e9332f83b16b8c8d615 Mon Sep 17 00:00:00 2001 From: jakubmanczak Date: Tue, 27 Dec 2022 14:22:15 +0100 Subject: [PATCH] make userprofiles rely on fetched data rather than local json --- data/administracja.json | 58 ----------- pages/profile/[profname]/index.tsx | 148 ++++++++++++++++++----------- 2 files changed, 90 insertions(+), 116 deletions(-) delete mode 100644 data/administracja.json diff --git a/data/administracja.json b/data/administracja.json deleted file mode 100644 index a6b4c85..0000000 --- a/data/administracja.json +++ /dev/null @@ -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."] - } - } -] diff --git a/pages/profile/[profname]/index.tsx b/pages/profile/[profname]/index.tsx index 21f684d..cc4a8be 100644 --- a/pages/profile/[profname]/index.tsx +++ b/pages/profile/[profname]/index.tsx @@ -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 ( -
-
- {`${person.name} -
-

{person.name}

-

{person.desc}

-
-
- {person.profile?.bigdesc.map((el, index) => { - return

{el ||
}

; - })} -
- ); + .then((data) => { + setPersons(data); + setLoading(false); + }) + .catch((err) => { + console.log(err); + }); + }, []); + if (loading) { + return
Fetching data...
; } else { - return ( -
-

Sorki!{" :("}

-

- Sprawdź pisownię: - { + return el.Name.replaceAll(" ", "-").toLocaleLowerCase(); + }) + .includes(profname) + ) { + const person: personsSchema = persons.filter((wpis: personsSchema) => { + return wpis.Name.replaceAll(" ", "-").toLocaleLowerCase() === profname; + })[0]; + return ( +

+ +
- {`/profile/${profname}`} - - nie jest poprawnym lokatorem profilu. -

-
- ); + {`${person.Name} +
+

{person.Name}

+

{person.Desc}

+
+ + {/* FOR LATER BIGDESC DATASET */} + {/* {person.profile?.bigdesc.map((el, index) => { + return

{el ||
}

; + })} */} +
+ ); + } else { + return ( +
+ +

Sorki!{" :("}

+

+ Sprawdź pisownię: + + {`/profile/${profname}`} + + nie jest poprawnym lokatorem profilu. +

+
+ ); + } } };