switch index splashes from json to api fetch

This commit is contained in:
2022-12-26 13:06:29 +01:00
parent 8452f4733e
commit 62b2581000
2 changed files with 12 additions and 47 deletions

View File

@@ -1,42 +0,0 @@
[
{
"body": "ona jest narysowana debilu",
"author": "jamesen"
},
{
"body": "idą jak surykatki na śmierć puszczone",
"author": "mollin"
},
{
"body": "jak spotkam stacha będziemy się napierdalać",
"author": "KuOlek"
},
{
"body": "to nie kwestia fetyszu, to kwestia prawa izraela",
"author": "stachowiak"
},
{
"body": "czemu ten szkielet ma oczy i czilluje",
"author": "stachowiak"
},
{
"body": "decymalizacja człowieka",
"author": "elephant / suoń"
},
{
"body": "pizdeczka... z całym szacunkiem",
"author": "bavil gravlax"
},
{
"body": "mam dwunastometrowego kija w dupie",
"author": "stachowiak"
},
{
"body": "pamięć wody o jabłku",
"author": "maciuś"
},
{
"body": "właśnie piszę biblię",
"author": "elephant / suoń"
}
]

View File

@@ -2,7 +2,6 @@ import styles from "../styles/Index.module.scss";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { SEO } from "../components/SEO"; import { SEO } from "../components/SEO";
import { Icon } from "../components/Icon"; import { Icon } from "../components/Icon";
import splashes from "../data/splashes.json";
import Link from "next/link"; import Link from "next/link";
import { IndexGallery } from "../components/IndexGallery/IndexGallery"; import { IndexGallery } from "../components/IndexGallery/IndexGallery";
@@ -10,12 +9,20 @@ const PageIndex = () => {
const [splash, setSplash] = useState(""); const [splash, setSplash] = useState("");
const [memberCount, setMemberCount] = useState(""); const [memberCount, setMemberCount] = useState("");
function randomizeSplash(): void { function randomizeSplash(): void {
setSplash(splashes[Math.floor(Math.random() * splashes.length)].body); fetch("https://gractwo.pl/api/v1/splash")
.then((res) => {
return res.json();
})
.then((data) => {
console.log(data);
setSplash(data.Splash);
})
.catch((err) => {
console.log(err);
});
} }
useEffect(() => { useEffect(() => {
randomizeSplash(); randomizeSplash();
}, []);
useEffect(() => {
fetch("https://gractwo.pl/api/members") fetch("https://gractwo.pl/api/members")
.then((res) => { .then((res) => {
return res.text(); return res.text();
@@ -26,7 +33,7 @@ const PageIndex = () => {
.catch((err) => { .catch((err) => {
console.log(err); console.log(err);
}); });
}); }, []);
const welcometext: string = "Witamy na witrynie internetowej Gractwa."; // Mamy nadzieję że odnajdziesz czego szukasz, zbłąkana duszo."; const welcometext: string = "Witamy na witrynie internetowej Gractwa."; // Mamy nadzieję że odnajdziesz czego szukasz, zbłąkana duszo.";
return ( return (
<> <>