From 0bfd81dd450eac5b636e71d779b0f7490642e5ff Mon Sep 17 00:00:00 2001 From: jakubmanczak Date: Mon, 26 Dec 2022 23:00:07 +0100 Subject: [PATCH] fetch gallery images from api instead of json --- components/IndexGallery/IndexGallery.tsx | 53 +++++++++++++++++++----- data/gallery.json | 32 -------------- 2 files changed, 43 insertions(+), 42 deletions(-) delete mode 100644 data/gallery.json diff --git a/components/IndexGallery/IndexGallery.tsx b/components/IndexGallery/IndexGallery.tsx index 9814751..0d643b2 100644 --- a/components/IndexGallery/IndexGallery.tsx +++ b/components/IndexGallery/IndexGallery.tsx @@ -1,25 +1,58 @@ import styles from "./IndexGallery.module.scss"; -import gallery from "../../data/gallery.json"; import Link from "next/link"; +import { useEffect, useState } from "react"; const IndexGallery = () => { + type apiResType = { + Id: string; + Title: string; + Link: string; + Description?: string; + Place?: string; + Date?: string; + }; + const [data, setData] = useState([]); + useEffect(() => { + fetch("https://gractwo.pl/api/v1/images") + .then((res) => { + return res.json(); + }) + .then((data) => { + setData(data); + }) + .catch((err) => { + console.log(err); + }); + }, []); return ( <>

galeria zdjęć idących mocno

- {gallery.map((entry) => { + {data.map((el: apiResType) => { return ( - - {entry.description} + + {el.Description
-

{entry.title}

-

{entry.meta}

+

{el.Title}

+

+ {el.Place || ""} + {el.Place && el.Date ? ", " : ""} + {el.Date + ? new Date(el.Date).getDate().toString().length == 2 + ? new Date(el.Date).getDate() + : "0" + new Date(el.Date).getDate() + : ""} + {"."} + {el.Date + ? (new Date(el.Date).getMonth() + 1).toString().length == 2 + ? new Date(el.Date).getMonth() + 1 + : "0" + (new Date(el.Date).getMonth() + 1) + : ""} + {"."} + {el.Date ? new Date(el.Date).getFullYear() : ""} +

); diff --git a/data/gallery.json b/data/gallery.json deleted file mode 100644 index 0b2f2ef..0000000 --- a/data/gallery.json +++ /dev/null @@ -1,32 +0,0 @@ -[ - { - "title": "RemCon 2022", - "description": "Bavil, Dzioba, Mollin i BeElephant pozują nad morzem.", - "meta": "Gdynia, 25.02.2022", - "link": "https://media.discordapp.net/attachments/719165033090908190/946703702864060466/20220225_104137.jpg" - }, - { - "title": "Mollin Stream II", - "description": "BeElephant i Mollin w kompromitujących przebraniach.", - "meta": "Poznań, 02.12.2022", - "link": "https://media.discordapp.net/attachments/719166032714924045/1048341477329227847/image.png" - }, - { - "title": "Morasko Chill", - "description": "Album cover dla nieistniejącej (jeszcze) płyty, featuring BeElephant, J4roid, Mollin i MrMichal564.", - "meta": "Poznań, 11.2022", - "link": "https://media.discordapp.net/attachments/434626765768491008/1052985575642239017/Pamiec_wody_o_jabku.jpg" - }, - { - "title": "OP pojawił się za jamesenem", - "description": "Poprzez całkowity przypadek BeElephant pojawia się za jamesenem w tramwaju.", - "meta": "Poznań, 15.11.2022", - "link": "https://media.discordapp.net/attachments/719166032714924045/1055549275825766471/20221115_183021.jpg" - }, - { - "title": "Ceremonia przekazania skarpety", - "description": "Ceremonialne pzekazanie Skarpety Stachowiaka jej prawowitemu właścicielowi w trzech aktach", - "meta": "Poznań, 9.2022", - "link": "https://cdn.discordapp.com/attachments/788182003098583070/1055542425592012810/Untitled164_20221222184347.png" - } -]