From 362c829c135598cbd2cd2e9332f83b16b8c8d615 Mon Sep 17 00:00:00 2001
From: jakubmanczak
Date: Tue, 27 Dec 2022 14:22:15 +0100
Subject: [PATCH 1/4] 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.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.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.
+
+
+ );
+ }
}
};
From 93d00d4634a5b08ecdb1ac45b6ae3848f586c901 Mon Sep 17 00:00:00 2001
From: jakubmanczak
Date: Tue, 27 Dec 2022 15:09:32 +0100
Subject: [PATCH 2/4] move /profile/ dir to /profil/
---
data/links.json | 2 +-
pages/o-gractwie.tsx | 2 +-
pages/{profile => profil}/[profname]/index.tsx | 0
3 files changed, 2 insertions(+), 2 deletions(-)
rename pages/{profile => profil}/[profname]/index.tsx (100%)
diff --git a/data/links.json b/data/links.json
index ccb77c2..3739a8f 100644
--- a/data/links.json
+++ b/data/links.json
@@ -29,7 +29,7 @@
},
{
"href": "/o-gractwie#sklad-administracji",
- "hrefalias": ["/profile"]
+ "hrefalias": ["/profil"]
},
{
"name": "Kod Źródłowy",
diff --git a/pages/o-gractwie.tsx b/pages/o-gractwie.tsx
index af60495..55dde0f 100644
--- a/pages/o-gractwie.tsx
+++ b/pages/o-gractwie.tsx
@@ -73,7 +73,7 @@ const PageInfo = () => {
return (
Date: Tue, 27 Dec 2022 15:21:21 +0100
Subject: [PATCH 3/4] fix bullshit hydration mismatch
---
pages/404.tsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pages/404.tsx b/pages/404.tsx
index 4b89920..325864d 100644
--- a/pages/404.tsx
+++ b/pages/404.tsx
@@ -33,7 +33,7 @@ const PageError404 = () => {
-
+
{
{useRouter().asPath}
{" "}
nie jest poprawnym adresem.
-
+
>
);
};
From 7639214b6322957ed21246e45e804cdaca3ae328 Mon Sep 17 00:00:00 2001
From: jakubmanczak
Date: Tue, 27 Dec 2022 15:32:21 +0100
Subject: [PATCH 4/4] patch hydration error
---
pages/404.tsx | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/pages/404.tsx b/pages/404.tsx
index 325864d..a8698f3 100644
--- a/pages/404.tsx
+++ b/pages/404.tsx
@@ -1,9 +1,13 @@
import { SEO } from "../components/SEO";
import { useRouter } from "next/router";
-import Link from "next/link";
+import { useEffect, useState } from "react";
const PageError404 = () => {
const router = useRouter();
+ const [badPath, setBadPath] = useState("");
+ useEffect(() => {
+ setBadPath(router.asPath);
+ }, [router.asPath]);
return (
<>
@@ -33,7 +37,7 @@ const PageError404 = () => {
-
+
{
boxShadow: "var(--shadow0)",
}}
>
- {useRouter().asPath}
+ {badPath}
{" "}
nie jest poprawnym adresem.
-
+
>
);
};