From 62b2581000c1e7337dde718142f5766bd374209d Mon Sep 17 00:00:00 2001 From: jakubmanczak Date: Mon, 26 Dec 2022 13:06:29 +0100 Subject: [PATCH] switch index splashes from json to api fetch --- data/splashes.json | 42 ------------------------------------------ pages/index.tsx | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 47 deletions(-) delete mode 100644 data/splashes.json diff --git a/data/splashes.json b/data/splashes.json deleted file mode 100644 index 7ce24a7..0000000 --- a/data/splashes.json +++ /dev/null @@ -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ń" - } -] diff --git a/pages/index.tsx b/pages/index.tsx index b7e7af3..7768e16 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -2,7 +2,6 @@ import styles from "../styles/Index.module.scss"; import { useEffect, useState } from "react"; import { SEO } from "../components/SEO"; import { Icon } from "../components/Icon"; -import splashes from "../data/splashes.json"; import Link from "next/link"; import { IndexGallery } from "../components/IndexGallery/IndexGallery"; @@ -10,12 +9,20 @@ const PageIndex = () => { const [splash, setSplash] = useState(""); const [memberCount, setMemberCount] = useState(""); 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(() => { randomizeSplash(); - }, []); - useEffect(() => { fetch("https://gractwo.pl/api/members") .then((res) => { return res.text(); @@ -26,7 +33,7 @@ const PageIndex = () => { .catch((err) => { console.log(err); }); - }); + }, []); const welcometext: string = "Witamy na witrynie internetowej Gractwa."; // Mamy nadzieję że odnajdziesz czego szukasz, zbłąkana duszo."; return ( <>