diff --git a/pages/admin/daily-schedule-generator.tsx b/pages/admin/daily-schedule-generator.tsx new file mode 100644 index 0000000..984d57f --- /dev/null +++ b/pages/admin/daily-schedule-generator.tsx @@ -0,0 +1,100 @@ +import { useEffect, useState } from "react"; +import { NextPage } from "next"; +import { TfiReload, TfiDownload } from "react-icons/tfi"; +import { AiOutlineLoading3Quarters } from "react-icons/ai"; + +const ScheduleArtworkPage: NextPage & { + getLayout?: (page: React.ReactNode) => React.ReactNode; +} = () => { + const [imageUrl, setImageUrl] = useState(null); + const [loading, setLoading] = useState(false); + + const fetchImage = async () => { + setLoading(true); + const response = await fetch("/api/schedule-artwork"); + const blob = await response.blob(); + const url = URL.createObjectURL(blob); + setImageUrl(url); + setLoading(false); + }; + + const downloadImage = () => { + if (imageUrl) { + const link = document.createElement("a"); + link.href = imageUrl; + link.download = "schedule-artwork.png"; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + } + }; + + useEffect(() => { + fetchImage(); + }, []); + + return ( +
+
+ {imageUrl ? ( + Schedule Artwork + ) : ( +

Loading...

+ )} +
+
+
+ + {imageUrl && ( + + )} +
+
+ ); +}; + +// Custom layout function to avoid using the default layout +ScheduleArtworkPage.getLayout = (page: React.ReactNode) => page; + +export default ScheduleArtworkPage; diff --git a/pages/api/schedule-artwork.tsx b/pages/api/schedule-artwork.tsx new file mode 100644 index 0000000..e2e0905 --- /dev/null +++ b/pages/api/schedule-artwork.tsx @@ -0,0 +1,210 @@ +import { ImageResponse } from "@vercel/og"; +import dayjs from "dayjs"; + +export const config = { + runtime: "experimental-edge", +}; + +async function handle(request: Request) { + const BASE_URL = process.env.VERCEL_URL + ? `https://${process.env.VERCEL_URL}` + : "http://localhost:3000"; + + const stickers = Array.from( + { length: 20 }, + (_, i) => `${BASE_URL}/images/stickers/Stickers-${i}.svg` + ); + + const getRandomSticker = () => { + const randomIndex = Math.floor(Math.random() * stickers.length); + return stickers[randomIndex]; + }; + + const getRandomPosition = () => { + const topOrBottom = Math.random() < 0.5 ? "top" : "bottom"; + const rotation = Math.floor(Math.random() * (20 - -20 + 1)) + -20; + let left; + + if (topOrBottom === "bottom") { + // Ensure the sticker is not placed in the middle of the artwork + const side = Math.random() < 0.5 ? "left" : "right"; + if (side === "left") { + left = Math.floor(Math.random() * 309); + } else { + left = Math.floor(Math.random() * 309) + (1080 - 309); + } + } else { + left = Math.floor(Math.random() * (900 - 100 + 1)) + 100; + } + + return { left, topOrBottom, rotation }; + }; + + const randomSticker = getRandomSticker(); + const randomPosition = getRandomPosition(); + + const response = await fetch(`${BASE_URL}/api/schedule`); + const schedule = await response.json(); + + let todaysSchedule = []; + + schedule.schedule.forEach((show) => { + const date = dayjs(show.date); + const adjustedDate = date.subtract(5, "hour"); + if (adjustedDate.isSame(dayjs(), "day")) { + todaysSchedule.push(show); + } + }); + + const longSchedule = todaysSchedule.length > 10; + + const fontLight = await fetch( + new URL("../../assets/VisueltLight.otf", import.meta.url) + ).then((res) => res.arrayBuffer()); + + const fontMedium = await fetch( + new URL("../../assets/VisueltMedium.otf", import.meta.url) + ).then((res) => res.arrayBuffer()); + + const fontArizona = await fetch( + new URL("../../assets/ABCArizonaFlare.otf", import.meta.url) + ).then((res) => res.arrayBuffer()); + + return new ImageResponse( + ( +
+
+ Random Sticker +
+
+
+
+ Today On The Radio +
+
+ {dayjs().format("D MMMM YYYY")} +
+
+
+ + + + + + +
+
+
+ {todaysSchedule.map((item, index) => ( +
+
+ {dayjs(item.date).format("HH:mm")} +
+
+ {item.title} +
+
+ ))} +
+
+ {dayjs(todaysSchedule[todaysSchedule.length - 1].dateEnd).format( + "HH:mm" + )} +
+
+ Repeats Playlist +
+
+
+
+
+ refugeworldwide.com +
+
+
+ ), + { + width: 1080, + height: 1920, + headers: { + "Cache-Control": "no-store", + }, + fonts: [ + { + name: "Visuelt", + data: fontLight, + style: "normal", + }, + { + name: "VisueltMedium", + data: fontMedium, + style: "normal", + }, + { + name: "fontArizona", + data: fontArizona, + style: "normal", + }, + ], + // debug: true, + } + ); +} + +export default handle; diff --git a/public/images/stickers/Stickers-0.svg b/public/images/stickers/Stickers-0.svg new file mode 100644 index 0000000..c4b9292 --- /dev/null +++ b/public/images/stickers/Stickers-0.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-1.svg b/public/images/stickers/Stickers-1.svg new file mode 100644 index 0000000..05b0aa8 --- /dev/null +++ b/public/images/stickers/Stickers-1.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-10.svg b/public/images/stickers/Stickers-10.svg new file mode 100644 index 0000000..602da45 --- /dev/null +++ b/public/images/stickers/Stickers-10.svg @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-11.svg b/public/images/stickers/Stickers-11.svg new file mode 100644 index 0000000..690cf84 --- /dev/null +++ b/public/images/stickers/Stickers-11.svg @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-12.svg b/public/images/stickers/Stickers-12.svg new file mode 100644 index 0000000..8c3f888 --- /dev/null +++ b/public/images/stickers/Stickers-12.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/public/images/stickers/Stickers-13.svg b/public/images/stickers/Stickers-13.svg new file mode 100644 index 0000000..42c55b4 --- /dev/null +++ b/public/images/stickers/Stickers-13.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-14.svg b/public/images/stickers/Stickers-14.svg new file mode 100644 index 0000000..1a2fbac --- /dev/null +++ b/public/images/stickers/Stickers-14.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-15.svg b/public/images/stickers/Stickers-15.svg new file mode 100644 index 0000000..36e9c66 --- /dev/null +++ b/public/images/stickers/Stickers-15.svg @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-16.svg b/public/images/stickers/Stickers-16.svg new file mode 100644 index 0000000..71bc20b --- /dev/null +++ b/public/images/stickers/Stickers-16.svg @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-17.svg b/public/images/stickers/Stickers-17.svg new file mode 100644 index 0000000..0d0e6b9 --- /dev/null +++ b/public/images/stickers/Stickers-17.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/public/images/stickers/Stickers-18.svg b/public/images/stickers/Stickers-18.svg new file mode 100644 index 0000000..bfa0b7e --- /dev/null +++ b/public/images/stickers/Stickers-18.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-19.svg b/public/images/stickers/Stickers-19.svg new file mode 100644 index 0000000..24fe462 --- /dev/null +++ b/public/images/stickers/Stickers-19.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/public/images/stickers/Stickers-2.svg b/public/images/stickers/Stickers-2.svg new file mode 100644 index 0000000..99dd082 --- /dev/null +++ b/public/images/stickers/Stickers-2.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-20.svg b/public/images/stickers/Stickers-20.svg new file mode 100644 index 0000000..338ef94 --- /dev/null +++ b/public/images/stickers/Stickers-20.svg @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-3.svg b/public/images/stickers/Stickers-3.svg new file mode 100644 index 0000000..029b27e --- /dev/null +++ b/public/images/stickers/Stickers-3.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/public/images/stickers/Stickers-4.svg b/public/images/stickers/Stickers-4.svg new file mode 100644 index 0000000..f034e0f --- /dev/null +++ b/public/images/stickers/Stickers-4.svg @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-5.svg b/public/images/stickers/Stickers-5.svg new file mode 100644 index 0000000..a36322a --- /dev/null +++ b/public/images/stickers/Stickers-5.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-6.svg b/public/images/stickers/Stickers-6.svg new file mode 100644 index 0000000..f164a1f --- /dev/null +++ b/public/images/stickers/Stickers-6.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-7.svg b/public/images/stickers/Stickers-7.svg new file mode 100644 index 0000000..251c1d7 --- /dev/null +++ b/public/images/stickers/Stickers-7.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-8.svg b/public/images/stickers/Stickers-8.svg new file mode 100644 index 0000000..cfac726 --- /dev/null +++ b/public/images/stickers/Stickers-8.svg @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/stickers/Stickers-9.svg b/public/images/stickers/Stickers-9.svg new file mode 100644 index 0000000..0f0e2cf --- /dev/null +++ b/public/images/stickers/Stickers-9.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/views/admin/additionalMenu.tsx b/views/admin/additionalMenu.tsx index d2ff9b7..78083c6 100644 --- a/views/admin/additionalMenu.tsx +++ b/views/admin/additionalMenu.tsx @@ -10,6 +10,7 @@ import toast from "react-hot-toast"; import dayjs from "dayjs"; import { RxDotsVertical } from "react-icons/rx"; import CalendarInsta from "./calendarInsta"; +import Link from "next/link"; export default function ShowArtworkModal() { const [dialogOpen, setDialogOpen] = useState(false); @@ -111,6 +112,11 @@ export default function ShowArtworkModal() { e.preventDefault()}> + + + Daily Schedule Artwork + + );