feat(specials): add launch and end dates for scheduling
This commit is contained in:
@@ -14,10 +14,45 @@ interface PageProps {
|
||||
export default async function SpecialPage({ params }: PageProps) {
|
||||
const { name } = await params;
|
||||
const decodedName = decodeURIComponent(name);
|
||||
|
||||
const currentSpecial = await prisma.special.findUnique({
|
||||
where: { name: decodedName }
|
||||
});
|
||||
|
||||
const now = new Date();
|
||||
const isStarted = currentSpecial && (!currentSpecial.launchDate || currentSpecial.launchDate <= now);
|
||||
const isEnded = currentSpecial && (currentSpecial.endDate && currentSpecial.endDate < now);
|
||||
|
||||
if (!currentSpecial || !isStarted) {
|
||||
return (
|
||||
<div style={{ textAlign: 'center', padding: '2rem' }}>
|
||||
<h1>Special Not Available</h1>
|
||||
<p>This special has not launched yet or does not exist.</p>
|
||||
<Link href="/">Go Home</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (isEnded) {
|
||||
return (
|
||||
<div style={{ textAlign: 'center', padding: '2rem' }}>
|
||||
<h1>Special Ended</h1>
|
||||
<p>This special event has ended.</p>
|
||||
<Link href="/">Go Home</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const dailyPuzzle = await getOrCreateSpecialPuzzle(decodedName);
|
||||
const genres = await prisma.genre.findMany({ orderBy: { name: 'asc' } });
|
||||
const specials = await prisma.special.findMany({ orderBy: { name: 'asc' } });
|
||||
|
||||
const activeSpecials = specials.filter(s => {
|
||||
const sStarted = !s.launchDate || s.launchDate <= now;
|
||||
const sEnded = s.endDate && s.endDate < now;
|
||||
return sStarted && !sEnded;
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<div style={{ textAlign: 'center', padding: '1rem', background: '#fce7f3' }}>
|
||||
@@ -39,12 +74,12 @@ export default async function SpecialPage({ params }: PageProps) {
|
||||
))}
|
||||
|
||||
{/* Separator if both exist */}
|
||||
{genres.length > 0 && specials.length > 0 && (
|
||||
{genres.length > 0 && activeSpecials.length > 0 && (
|
||||
<span style={{ color: '#d1d5db' }}>|</span>
|
||||
)}
|
||||
|
||||
{/* Specials */}
|
||||
{specials.map(s => (
|
||||
{activeSpecials.map(s => (
|
||||
<Link
|
||||
key={s.id}
|
||||
href={`/special/${s.name}`}
|
||||
|
||||
Reference in New Issue
Block a user