-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,61 @@ | ||
--- | ||
import MainLayout from "../layouts/MainLayout.astro"; | ||
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro"; | ||
import { Icon } from "astro-icon/components"; | ||
import Image from "astro:assets"; | ||
import logo from "../assets/logo.png"; | ||
import { getAllEpisodesQuery } from "../queries/get-episodes"; | ||
import { type Episode, type Character } from "../models/rick-morty"; | ||
import { getAllCharactersQuery } from "../queries/get-episodes"; | ||
import { type Character } from "../models/rick-morty"; | ||
export const prerender = false; | ||
const response = await fetch("https://rickandmortyapi.com/graphql", { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
query: getAllEpisodesQuery, | ||
query: getAllCharactersQuery, | ||
}), | ||
}); | ||
const { | ||
data: { | ||
episodes: { results }, | ||
characters: { results }, | ||
}, | ||
} = await response.json(); | ||
console.log("First episode name:", results[0].name); | ||
console.log("Third episode details:", results[2]); | ||
console.log("First episode name:", results); | ||
--- | ||
|
||
<MainLayout> | ||
<div class="container mx-auto my-1 text-center text-justify-center"> | ||
<a href="/" class="flex mr-auto"> | ||
<img | ||
src="/src/assets/logo.png" | ||
alt="logo" | ||
class="w-40 h-40 object-contain" | ||
/> | ||
<a> | ||
<h1 class="text-3xl mb-12">Example Rick and Morty Page</h1> | ||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"> | ||
{ | ||
results.map((result: Episode) => ( | ||
<div class="flex flex-col gap-3 "> | ||
{result.characters.map((char: Character) => ( | ||
<div class="border rounded-lg"> | ||
<img | ||
src={char.image} | ||
alt={char.name} | ||
class="w-full h-64 object-cover rounded-lg" | ||
/> | ||
<div class=" p-2"> | ||
<div class="bg-green-200 rounded-md p-2 mb-2 text-xl"> | ||
<span class="font-bold">Episode name: </span> | ||
<span>{result.name}</span> | ||
</div> | ||
<div> | ||
<span>Details: </span> | ||
<span class=" font-semibold">{result.episode}</span> | ||
</div> | ||
<div class="text-sm text-gray-600 mt-6"> | ||
<span class="">Aired on: </span> | ||
<span> {result.air_date} </span> | ||
</div> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
)) | ||
} | ||
</div> | ||
</a> | ||
</a> | ||
</div></MainLayout | ||
<StarlightPage | ||
frontmatter={{ | ||
title: "Rick and Morty Character Explorer", | ||
template: "splash", | ||
}} | ||
> | ||
<div class="container mx-auto my-1 text-center text-justify-center"> | ||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"> | ||
{ | ||
results.map((character: Character) => ( | ||
<div class="border rounded-lg"> | ||
<img | ||
src={character.image} | ||
alt={character.name} | ||
class="w-full h-64 object-contain rounded-lg" | ||
/> | ||
<div class="flex flex-row items-center justify-center gap-4 px-2"> | ||
<p class="">{character.name}</p> | ||
<a | ||
href="/rick-morty-exp/xx" | ||
rel="noopener noreferrer" | ||
class="text-black" | ||
> | ||
<Icon | ||
name="arrow" | ||
size={24} | ||
class=" cursor-pointer rotate-90" | ||
/> | ||
</a> | ||
</div> | ||
</div> | ||
)) | ||
} | ||
</div> | ||
</div> | ||
</StarlightPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters