Compare commits
5 Commits
PIE-13
...
66567b9b68
| Author | SHA1 | Date | |
|---|---|---|---|
|
66567b9b68
|
|||
|
4451c95bf7
|
|||
|
5250d8c3b3
|
|||
|
eae36b8da5
|
|||
|
c25f95949b
|
@@ -1,5 +1,7 @@
|
|||||||
---
|
---
|
||||||
import client from "@/data/pocketbase"
|
import client from "@/data/pocketbase"
|
||||||
|
import TagRow from "./TagRow.astro"
|
||||||
|
|
||||||
const { recipe } = Astro.props;
|
const { recipe } = Astro.props;
|
||||||
|
|
||||||
const headerImage = await client.collection("images").getOne(recipe.images[0])
|
const headerImage = await client.collection("images").getOne(recipe.images[0])
|
||||||
@@ -12,16 +14,18 @@ const image = await client.files.getURL(headerImage, headerImage.image)
|
|||||||
src={ image }
|
src={ image }
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="absolute bottom-0 left-0 w-full p-2 h-25 backdrop-filter backdrop-blur-lg rounded-b-xl">
|
<div id="bottom-info-panel" class="absolute bottom-0 left-0 w-full p-2 h-25 backdrop-filter backdrop-blur-lg rounded-b-xl z-1">
|
||||||
<p class="text-[14pt] text-white opacity-90 font-bold" >{recipe.name}</p>
|
<p id="recipe-name" class="text-[14pt] text-white opacity-90 font-bold" >{recipe.name}</p>
|
||||||
<p class="text-white text-[10pt]"> {recipe.description} </p>
|
<p id="recipe-desc" class="text-white text-[10pt]"> {recipe.description} </p>
|
||||||
|
|
||||||
<div class="flex flex-row">
|
<div id="tag-row" class="">
|
||||||
{recipe.tags.map(async tag => (
|
<TagRow tagIds={recipe.tags}/>
|
||||||
<p class="text-white bg-white/20 px-2 mr-2 mt-2 rounded-md">{
|
|
||||||
(await client.collection("tags").getOne(tag)).name
|
|
||||||
}</p>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<a id="link" href={`/recipe/${recipe.id}`} class="absolute inset-0 z-0">
|
||||||
|
<span class="block w-full h-full hover:bg-black/10 transition-colors">
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
33
src/components/Card/TagRow.astro
Normal file
33
src/components/Card/TagRow.astro
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
---
|
||||||
|
import client from "../../data/pocketbase"
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
tagIds: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const { tagIds } = Astro.props
|
||||||
|
|
||||||
|
const tags = tagIds && tagIds.length > 0
|
||||||
|
? await Promise.all(tagIds.map(async (tagId: string) => {
|
||||||
|
try {
|
||||||
|
const tagData = await client.collection("tags").getOne(tagId)
|
||||||
|
return { name: tagData.name, id: tagId }
|
||||||
|
} catch (error) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
: []
|
||||||
|
---
|
||||||
|
|
||||||
|
<div class="">
|
||||||
|
{
|
||||||
|
tags.map(tag => (
|
||||||
|
<a
|
||||||
|
href={`/tag/${tag.id}`}
|
||||||
|
class="text-white bg-white/20 px-2 mr-2 mt-2 rounded-md inline-block hover:bg-white/30"
|
||||||
|
>
|
||||||
|
{tag.name}
|
||||||
|
</a>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</div>
|
||||||
47
src/components/Detail/ImageCarousel.astro
Normal file
47
src/components/Detail/ImageCarousel.astro
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
---
|
||||||
|
import client from "@/data/pocketbase";
|
||||||
|
const { recipe } = Astro.props
|
||||||
|
|
||||||
|
async function getLink(img: string) {
|
||||||
|
const record = await client.collection("images").getOne(img)
|
||||||
|
const link = await client.files.getURL(record, record.image)
|
||||||
|
return link
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use Promise.all to wait for all async operations to complete
|
||||||
|
const links = await Promise.all(
|
||||||
|
recipe.images.map((img: string) => getLink(img))
|
||||||
|
)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<script>
|
||||||
|
let pos = 0;
|
||||||
|
const dataElement = document.getElementById('carousel-data');
|
||||||
|
const links = dataElement ? JSON.parse(dataElement.textContent || '[]') : [];
|
||||||
|
const cap = links.length - 1;
|
||||||
|
const img = document.getElementById('carousel-img') as HTMLImageElement;
|
||||||
|
|
||||||
|
function inc() {
|
||||||
|
pos = pos === cap ? 0 : pos + 1;
|
||||||
|
if (img) img.src = links[pos];
|
||||||
|
}
|
||||||
|
|
||||||
|
function dec() {
|
||||||
|
pos = pos === 0 ? cap : pos - 1;
|
||||||
|
if (img) img.src = links[pos];
|
||||||
|
}
|
||||||
|
|
||||||
|
// make functions globally accessible
|
||||||
|
(window as any).inc = inc;
|
||||||
|
(window as any).dec = dec;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<!-- Hidden element to pass server data to client -->
|
||||||
|
<div class="hidden" id="carousel-data">{JSON.stringify(links)}</div>
|
||||||
|
|
||||||
|
<img id="carousel-img" src={links[0]} />
|
||||||
|
<button onclick="inc()">NEXT</button>
|
||||||
|
<button onclick="dec()">PREV</button>
|
||||||
|
</div>
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
<div class="flex w-full items-center bg-yellow-100 p-5">
|
<div class="flex w-full items-center bg-yellow-100 p-5">
|
||||||
<a class="flex" href="/">
|
<a class="flex" href="/">
|
||||||
<p class=" text-3xl">Reci</p>
|
<p class=" text-3xl">Recipie</p>
|
||||||
<p class=" text-3xl text-amber-500">pie</p>
|
<!-- <p class=" text-3xl text-amber-500">pie</p> -->
|
||||||
🥧
|
🥧
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import Header from "@/components/Header";
|
|||||||
<body>
|
<body>
|
||||||
<main id="main" class="flex-1">
|
<main id="main" class="flex-1">
|
||||||
<Header/>
|
<Header/>
|
||||||
|
<div class="px-5 pt-2">
|
||||||
<slot />
|
<slot />
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ const recipies = await client.collection("recipes").getFullList()
|
|||||||
---
|
---
|
||||||
|
|
||||||
<PageLayout>
|
<PageLayout>
|
||||||
<div id="content" class="p-5 pt-2">
|
|
||||||
<!-- <p class="pb-2">What would you like today?</p> -->
|
<!-- <p class="pb-2">What would you like today?</p> -->
|
||||||
|
|
||||||
<div class="grid gap-2 grid-cols-1 md:grid-cols-2 lg:grid-cols-4">
|
<div class="grid gap-2 grid-cols-1 md:grid-cols-2 lg:grid-cols-4">
|
||||||
@@ -17,6 +16,5 @@ const recipies = await client.collection("recipes").getFullList()
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
|
|||||||
16
src/pages/recipe/[slug].astro
Normal file
16
src/pages/recipe/[slug].astro
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
import client from "@/data/pocketbase";
|
||||||
|
import SiteLayout from "@/layouts/base";
|
||||||
|
import ImageCarousel from "@/components/Detail/ImageCarousel";
|
||||||
|
|
||||||
|
const { slug } = Astro.params;
|
||||||
|
|
||||||
|
const re = await client.collection("recipes").getOne(slug ?? "0");
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<SiteLayout>
|
||||||
|
<div class="flex">
|
||||||
|
<ImageCarousel recipe={re} />
|
||||||
|
</div>
|
||||||
|
</SiteLayout>
|
||||||
Reference in New Issue
Block a user