Skip to content

Commit

Permalink
Merge pull request #114 from TKOaly/rolling-ads
Browse files Browse the repository at this point in the history
Add rollings ads
  • Loading branch information
Jokauppi authored Sep 24, 2024
2 parents 793d1e0 + 24aa063 commit 810358b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
Binary file added public/fuksiaiset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 43 additions & 2 deletions src/app/(infoscreen)/@ad/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,55 @@
'use client';

import { Slide } from '@/components/Carousel';
import Logo from '@/components/Logo';
import Image from 'next/image';
import { useEffect, useState } from 'react';

type AdType = {
url: string;
from?: Date;
until: Date;
};

const ads: AdType[] = [
{ url: '/fuksiaiset.png', until: new Date(2024, 9, 29) },
{ url: '/atkytp.png', until: new Date(2024, 10, 15) },
];

const Ad = () => {
const [ad, setAd] = useState<AdType | undefined>(undefined);

useEffect(() => {
const getAd = () => {
const validAds = ads.filter(
(ad) =>
ad.until > new Date() && (!ad.from || ad.from < new Date())
);

setAd(validAds[new Date().getMinutes() % validAds.length]);
};

getAd();

const interval = setInterval(() => getAd(), 60 * 1000);
return () => clearInterval(interval);
}, [setAd]);

// Fallback to spinning logo if no valid ads are available
if (ads.length === 0 || !ad)
return (
<Slide className="items-center justify-center bg-black text-yellow-400">
<Logo />
</Slide>
);

const Ad = async () => {
return (
<Slide>
<div className="relative size-full">
<Image
fill
className="object-cover"
src={'/atkytp.png'}
src={ad.url}
alt={'Ad picture'}
/>
</div>
Expand Down
11 changes: 4 additions & 7 deletions src/app/(infoscreen)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Carousel, Slide, type SlideElement } from '@/components/Carousel';
import Logo from '@/components/Logo';
import { Carousel, type SlideElement } from '@/components/Carousel';

type CarouselLayoutProps = Record<string, SlideElement>;

const CarouselLayout = ({
events,
restaurants,
ad,
transit,
lectures,
ilotalo,
children,
Expand All @@ -15,12 +15,9 @@ const CarouselLayout = ({
<main className="flex max-h-screen min-h-screen">
<Carousel loop duration={40} delay={20000}>
{events}
<Slide className="items-center justify-center bg-black text-yellow-400">
<Logo />
</Slide>
{/* transit */}
{restaurants}
{ad}
{restaurants}
{transit}
{lectures}
{ilotalo}
{children}
Expand Down

0 comments on commit 810358b

Please sign in to comment.