From c3c90d575182d64b0e679e8da81a6d4f3559cf1f Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Tue, 28 Mar 2023 19:26:30 +0200 Subject: Working app --- pages/api/avatars/[id].js | 10 ++++++++++ pages/api/avatars/avatars.json | 37 +++++++++++++++++++++++++++++++++++++ pages/api/avatars/index.js | 6 ++++++ pages/av/[id].js | 30 ++++++++++++++++++++++++++++++ pages/index.js | 20 ++++++++++++++++++++ 5 files changed, 103 insertions(+) create mode 100644 pages/api/avatars/[id].js create mode 100644 pages/api/avatars/avatars.json create mode 100644 pages/api/avatars/index.js create mode 100644 pages/av/[id].js create mode 100644 pages/index.js (limited to 'pages') diff --git a/pages/api/avatars/[id].js b/pages/api/avatars/[id].js new file mode 100644 index 0000000..cacdedd --- /dev/null +++ b/pages/api/avatars/[id].js @@ -0,0 +1,10 @@ +import avatars from "./avatars.json" + +export default function(req, res) { + let id = req.query.id; + const result = avatars.filter(av => av.id == id) + if (result.length > 0) + res.status(200).json(result[0]) + else + res.status(404).json({ message: 'brak avatara o takim id' }) +} diff --git a/pages/api/avatars/avatars.json b/pages/api/avatars/avatars.json new file mode 100644 index 0000000..b5a9cd7 --- /dev/null +++ b/pages/api/avatars/avatars.json @@ -0,0 +1,37 @@ +[ + { + "id": "aatrox", + "name": "Aatrox", + "title": "the Darkin Blade", + "icon": "http://ddragon.leagueoflegends.com/cdn/10.23.1/img/champion/Aatrox.png", + "description": "Once honored defenders of Shurima against the Void, Aatrox and his brethren would eventually become an even greater threat to Runeterra, and were defeated only by cunning mortal sorcery. But after centuries of imprisonment, Aatrox was the first to find..." + }, + { + "id": "ahri", + "name": "Ahri", + "title": "the Nine-Tailed Fox", + "icon": "http://ddragon.leagueoflegends.com/cdn/10.23.1/img/champion/Ahri.png", + "description": "Innately connected to the latent power of Runeterra, Ahri is a vastaya who can reshape magic into orbs of raw energy. She revels in toying with her prey by manipulating their emotions before devouring their life essence. Despite her predatory nature..." + }, + { + "id": "akali", + "name": "Akali", + "title": "the Rogue Assassin", + "icon": "http://ddragon.leagueoflegends.com/cdn/10.23.1/img/champion/Akali.png", + "description": "Abandoning the Kinkou Order and her title of the Fist of Shadow, Akali now strikes alone, ready to be the deadly weapon her people need. Though she holds onto all she learned from her master Shen, she has pledged to defend Ionia from its enemies, one..." + }, + { + "id": "alistar", + "name": "Alistar", + "title": "the Minotaur", + "icon": "http://ddragon.leagueoflegends.com/cdn/10.23.1/img/champion/Alistar.png", + "description": "Always a mighty warrior with a fearsome reputation, Alistar seeks revenge for the death of his clan at the hands of the Noxian empire. Though he was enslaved and forced into the life of a gladiator, his unbreakable will was what kept him from truly..." + }, + { + "id": "amumu", + "name": "Amumu", + "title": "the Sad Mummy", + "icon": "http://ddragon.leagueoflegends.com/cdn/10.23.1/img/champion/Amumu.png", + "description": "Legend claims that Amumu is a lonely and melancholy soul from ancient Shurima, roaming the world in search of a friend. Doomed by an ancient curse to remain alone forever, his touch is death, his affection ruin. Those who claim to have seen him describe..." + } +] \ No newline at end of file diff --git a/pages/api/avatars/index.js b/pages/api/avatars/index.js new file mode 100644 index 0000000..b14d180 --- /dev/null +++ b/pages/api/avatars/index.js @@ -0,0 +1,6 @@ +import avatars from "./avatars.json" +console.log(avatars); + +export default function(req, res) { + res.status(200).json(avatars) +} diff --git a/pages/av/[id].js b/pages/av/[id].js new file mode 100644 index 0000000..36db22d --- /dev/null +++ b/pages/av/[id].js @@ -0,0 +1,30 @@ +import Link from "next/link"; +import Avatar from "../../components/Avatar" + +export default function Av(props) { + console.log(props) + return ( + <> +

Go back home

+ {} + + ) +} + +export async function getStaticProps({ params }) { + const av = await fetch(`http://localhost:3000/api/avatars/${params.id}`).then(res => res.json()); + return { + props: { + av + } + } +} + +export async function getStaticPaths() { + const res = await fetch(`http://localhost:3000/api/avatars`).then(res => res.json()); + console.log("getStaticPaths ", res) + return { + paths: res.map(av => `/av/${av.id}`), + fallback: true, + } +} diff --git a/pages/index.js b/pages/index.js new file mode 100644 index 0000000..9974583 --- /dev/null +++ b/pages/index.js @@ -0,0 +1,20 @@ +import Avatar from "../components/Avatar" + +export default function Avs(props) { + return ( + <> +

Avatars

+ {props.avs.map(data => )} + + ) +} + +export const getStaticProps = async () => { + const res = await fetch(`http://localhost:3000/api/avatars`); + const avs = await res.json(); + return { + props: { + avs + } + } +} -- cgit v1.3.1