Skip to content

Commit

Permalink
feat(timer40k): add early release date
Browse files Browse the repository at this point in the history
  • Loading branch information
sabinmarcu committed Aug 16, 2024
1 parent a09b10e commit e4d5fd8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 24 deletions.
45 changes: 30 additions & 15 deletions apps/timer40k/app/Display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ import {
import dayjs from 'dayjs';

export type DisplayProperties = {
yes: Partial<ComponentProps<typeof Image>>,
no: Partial<ComponentProps<typeof Image>>,
releasedImage: Partial<ComponentProps<typeof Image>>,
earlyReleaseImage: Partial<ComponentProps<typeof Image>>,
upcomingImage: Partial<ComponentProps<typeof Image>>,
releaseDate: string,
earlyReleaseDate: string,
};
export function Display({
yes,
no,
releasedImage,
earlyReleaseImage,
upcomingImage,
releaseDate,
earlyReleaseDate,
}: DisplayProperties) {
const [
time,
Expand All @@ -32,22 +36,33 @@ export function Display({
},
[],
);
const diff = dayjs(time).diff(dayjs(releaseDate), 'day', true);
const isReleased = diff >= 0;
const toRender = (isReleased ? yes : no) as any;
const text = (isReleased
? String.raw`It's released, what are you doing here?`
: `Coming out in ${Number.parseInt(`${0 - diff}`, 10)} days`
)
const releaseDiff = dayjs(time).diff(dayjs(releaseDate), 'day', true);
const earlyReleaseDiff = earlyReleaseDate ? dayjs(time).diff(dayjs(earlyReleaseDate), 'day', true) : 0 - Infinity;
const imageToRender = (
(releaseDiff >= 0 && releasedImage)
|| (earlyReleaseDiff >= 0 && earlyReleaseImage)
|| upcomingImage
) as any;
return (
<>
<div className="background">
<Image {...toRender} alt="status-bg" />
<Image {...imageToRender} alt="status-bg" />
</div>
<div className="foreground">
<Image {...toRender} alt="status" />
<h1>{text}</h1>
<Image {...imageToRender} alt="status" />
<h1>
{releaseDiff >= 0
? String.raw`It's released, what are you doing here?`
: `Releasing in ${Number.parseInt(`${0 - releaseDiff}`, 10)} days`}
</h1>
{earlyReleaseDate && (
<h2>
{earlyReleaseDiff >= 0
? String.raw`It's in early release. Go have fun, you wealthy git.`
: `Early release in in ${Number.parseInt(`${0 - earlyReleaseDiff}`, 10)} days`}
</h2>
)}
</div>
</>
);
}
}
13 changes: 9 additions & 4 deletions apps/timer40k/app/env.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// eslint-disable-next-line unicorn/prevent-abbreviations
import { z } from 'zod';

const envSchema = z.object({
const environmentSchema = z.object({
TIMER_40K_RELEASE_DATE: z.string(),
TIMER_40K_GAME_NAME: z.string(),
TIMER_40K_EARLY_RELEASE_DATE: z.string().optional(),
});

export type EnvType = z.infer<typeof envSchema>;
export const env = envSchema.parse({
// eslint-disable-next-line unicorn/prevent-abbreviations
export type EnvType = z.infer<typeof environmentSchema>;
// eslint-disable-next-line unicorn/prevent-abbreviations
export const env = environmentSchema.parse({
TIMER_40K_RELEASE_DATE: process.env.TIMER_40K_RELEASE_DATE,
TIMER_40K_EARLY_RELEASE_DATE: process.env.TIMER_40K_EARLY_RELEASE_DATE,
TIMER_40K_GAME_NAME: process.env.TIMER_40K_GAME_NAME,
});
});
13 changes: 11 additions & 2 deletions apps/timer40k/app/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,23 @@ html, body, #root {
flex-flow: column nowrap;
}

.foreground h1 {
padding: 1.5rem;
.foreground :is(h1, h2) {
padding-block-start: 1.5rem;
text-transform: uppercase;
font-size: 2rem;
text-shadow: 0 1px 5px black;
}

.foreground h2 {
opacity: 0.6;
}

.foreground img {
box-shadow: 0px 0px 12px 0px black;
border-radius: 5px;
width: auto;
height: auto;
max-width: 75cqw;
min-height: 50cqh;
max-height: 60cqh;
}
12 changes: 9 additions & 3 deletions apps/timer40k/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ import { env as environment } from './env';
export default function Home() {
return (
<Display {...{
yes: {
releasedImage: {
src: '/yes.jpg',
width: '688',
height: '1159',
},
no: {
upcomingImage: {
src: '/no.jpg',
width: '800',
height: '518',
},
earlyReleaseImage: {
src: '/maybe.png',
width: '2062',
height: '1798',
},
releaseDate: environment.TIMER_40K_RELEASE_DATE,
earlyReleaseDate: environment.TIMER_40K_EARLY_RELEASE_DATE,
}}
/>
);
}
}
Binary file added apps/timer40k/public/maybe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e4d5fd8

Please sign in to comment.