| 1 |
--- |
| 2 |
import { API, useAPI } from "../../../lib/hooks/useAPI.astro"; |
| 3 |
import Spinner from "../../components/other/Spinner.astro"; |
| 4 |
import Layout from "../../layouts/Layout.astro"; |
| 5 |
|
| 6 |
const announcement_title = (Astro.url.pathname.split("/").pop() as string).replace(/-/g, " "); |
| 7 |
let announcement: ({ id: number; title: string; date: number; content: string; views: number } & { images: string[] }) | undefined; |
| 8 |
try { |
| 9 |
const res_announcement = await useAPI(API.Announcements.getByTitle, { UrlArgs: { title: announcement_title } }); |
| 10 |
announcement = res_announcement.data; |
| 11 |
if (!announcement) return Astro.redirect("/404"); |
| 12 |
} catch (e) { |
| 13 |
return Astro.redirect("/404"); |
| 14 |
} |
| 15 |
const imgSrc = "/anakoinoseis/images/" + announcement.id + "/"; |
| 16 |
const imgThumbSrc = "/anakoinoseis/images/" + announcement.id + "/thumb_"; |
| 17 |
--- |
| 18 |
|
| 19 |
<Layout title={announcement.title} imageUrl={announcement.images[0]}> |
| 20 |
<section class="relative flex flex-col p-12 max-sm:p-4 overflow-auto items-center gap-y-6"> |
| 21 |
<h1 |
| 22 |
class="heading w-[25ch] max-sm:w-[25ch] text-5xl max-sm:text-3xl text-center font-bold text-red-900 font-anaktoria drop-shadow-[-1px_2px_1px_rgba(0,0,0,0.25)]" |
| 23 |
> |
| 24 |
{announcement.title} |
| 25 |
</h1> |
| 26 |
<div class="max-w-[720px] h-[360px] shadow-lg shadow-slate-800"> |
| 27 |
<img src={imgSrc + announcement.images[1]} alt={announcement?.title as string} class="w-[720px] object-cover h-full" /> |
| 28 |
</div> |
| 29 |
<div class="text-xl mt-4 self-start"> |
| 30 |
{announcement.content} |
| 31 |
</div> |
| 32 |
<div id="imgContainer" class="flex items-center"> |
| 33 |
<div class="flex flex-row flex-wrap mt-4 gap-y-6 loading items-center justify-evenly self-center"> |
| 34 |
{ |
| 35 |
announcement.images.map((image, i) => ( |
| 36 |
<div class="imgLoader group/img"> |
| 37 |
<div class="hidden group-[:is(.loading)]/img:block w-[320px] h-[240px] "> |
| 38 |
<Spinner /> |
| 39 |
</div> |
| 40 |
<div class="hidden group-[:is(.loaded)]/img:block max-w-[320px] h-[240px] transition-shadow hover:shadow-lg !shadow-slate-800"> |
| 41 |
<img |
| 42 |
data-src={imgThumbSrc + image} |
| 43 |
alt={announcement?.title as string} |
| 44 |
class="w-[400px] object-cover h-full" |
| 45 |
/> |
| 46 |
</div> |
| 47 |
</div> |
| 48 |
)) |
| 49 |
} |
| 50 |
</div> |
| 51 |
</div> |
| 52 |
</section> |
| 53 |
<!-- <div id="imageCarouselContainer" class="fixed inset-0 bg-[rgba(40,10,10,0.4)] backdrop-blur-[3px] grid place-content-center"> |
| 54 |
<div |
| 55 |
id="controlsContainer" |
| 56 |
class="grid grid-cols-[max-content,1fr,max-content] justify-center items-center p-8 bg-[rgba(40,10,10,0.75)] rounded-md shadow-lg shadow-[rgba(40,10,10,1)] backdrop-blur-[3px]" |
| 57 |
> |
| 58 |
<i class="pr-8 fa-solid fa-chevron-left font-bold text-2xl text-white max-sm:text-xs max-sm:px-2 max-3xs:text-xs"></i> |
| 59 |
<div id="imageCarousel" data-index="0"> |
| 60 |
<div class="imgLoader group/img"> |
| 61 |
<div class="hidden group-[:is(.loading)]/img:block w-[320px] h-[240px]"> |
| 62 |
<Spinner /> |
| 63 |
</div> |
| 64 |
<div |
| 65 |
class="hidden group-[:is(.loaded)]/img:block max-w-[320px] h-[240px] transition-shadow hover:shadow-lg !shadow-slate-800" |
| 66 |
> |
| 67 |
<img alt={announcement.title} class="w-[400px] object-cover h-full" /> |
| 68 |
</div> |
| 69 |
</div> |
| 70 |
<div id="thumbContainer" class="flex flex-row pt-8"> |
| 71 |
<img alt={announcement.title}/> |
| 72 |
<img alt={announcement.title}/> |
| 73 |
<img alt={announcement.title}/> |
| 74 |
<img alt={announcement.title}/> |
| 75 |
<img alt={announcement.title}/> |
| 76 |
</div> |
| 77 |
</div> |
| 78 |
<i class="pl-8 fa-solid fa-chevron-right font-bold text-2xl text-white max-sm:text-xs max-sm:px-2 max-3xs:text-xs"></i> |
| 79 |
</div> |
| 80 |
</div> --> |
| 81 |
</Layout> |
| 82 |
<script> |
| 83 |
import { onElementMount, asyncQueue, sleep } from "../../../lib/utils.client"; |
| 84 |
onElementMount("#imgContainer", async el => { |
| 85 |
const imgs = [...el.querySelectorAll("img")]; |
| 86 |
const imgContainers = [...el.querySelectorAll(".imgLoader")]; |
| 87 |
const jobs = imgs.map((img, i) => async () => { |
| 88 |
let loaded = false; |
| 89 |
imgContainers[i].classList.add("loading"); |
| 90 |
img.addEventListener("load", () => { |
| 91 |
loaded = true; |
| 92 |
imgContainers[i].classList.remove("loading"); |
| 93 |
imgContainers[i].classList.add("loaded"); |
| 94 |
}); |
| 95 |
img.src = img.dataset.src as string; |
| 96 |
while (!loaded) { |
| 97 |
await sleep(20); |
| 98 |
} |
| 99 |
}); |
| 100 |
await asyncQueue(jobs, 5); |
| 101 |
}); |
| 102 |
</script> |