Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/admin-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Open **Calendar settings**, go to **Texts**, switch to `fr` or `en` and type. A

### Hide the calendar, change the year or the hour

Under **Behaviour**: **Visible** starts unticked, so visitors get a holding page until you tick it and save; you stay able to see everything either way. **Year** and **Opens at hour** (Paris time) decide when each door opens. **After 24 December** chooses between keeping every door open and showing the holding page.
Under **Behaviour**: **Visible** is ticked: the calendar opens to visitors by itself at midnight (Paris time) on 1 December of the **Year**, and a button on the home page links to it from 1 to 24 December. Before 1 December visitors get a holding page whatever the box says. Untick it and save to take the calendar down (visitors get the holding page); tick it again to bring it back. You stay able to see everything either way. **Year** and **Opens at hour** (Paris time) decide when each door opens. **After 24 December** chooses between keeping every door open and showing the holding page.

### Check the preview

Expand Down
34 changes: 34 additions & 0 deletions src/app/(frontend)/_components/CalendarButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use client";

import Link from "next/link";
import { useSyncExternalStore } from "react";
import { useLanguage } from "@/context/LanguageContext";
import { defaultYear } from "@/lib/calendar/defaults";
import { getCalendarDay } from "@/lib/calendar/schedule";

const subscribe = () => () => {};

const isCalendarSeason = () => {
const { today, ended } = getCalendarDay(new Date(), {
year: defaultYear,
opensAtHour: 0,
});
return today > 0 && !ended;
};

/** Shown from 1 to 24 December, Paris time. Checked in the browser so the home page stays static. */
export default function CalendarButton() {
const { isFrench } = useLanguage();
const inSeason = useSyncExternalStore(subscribe, isCalendarSeason, () => false);

if (!inSeason) return null;

return (
<Link
href={`/calendrier?isFrench=${isFrench}`}
className="absolute bottom-32 left-1/2 z-20 -translate-x-1/2 rounded-full bg-clarks-orange px-6 py-3 text-center font-bold text-black whitespace-nowrap hover:bg-white focus:outline-hidden focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-offset-2 focus-visible:ring-offset-black"
>
{isFrench ? "Le calendrier de l’Avent" : "The advent calendar"}
</Link>
);
}
3 changes: 3 additions & 0 deletions src/app/(frontend)/_components/HomeClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useLanguage } from "@/context/LanguageContext";
import { FaVolumeMute, FaVolumeUp, FaPause, FaPlay } from "react-icons/fa";
import dynamic from "next/dynamic";
import Image from "next/image";
import CalendarButton from "./CalendarButton";
import StaticLogo from "./StaticLogo";
import useHlsVideo, { HLS_SRC, HLS_TYPE } from "./useHlsVideo";
import useIsMounted from "@/utils/useIsMounted";
Expand Down Expand Up @@ -116,6 +117,8 @@ export default function HomeClient() {
<StaticLogo />
</div>

<CalendarButton />

{/* Video controls */}
<button
className="absolute top-5 left-16 md:top-auto md:left-auto md:bottom-5 md:right-5 z-20 text-white bg-transparent border-none cursor-pointer focus:outline-hidden focus-visible:ring-2 focus:ring-clarks-orange focus:ring-offset-2 focus:ring-offset-transparent rounded-full p-1 hover:text-clarks-orange motion-reduce:hidden"
Expand Down
4 changes: 2 additions & 2 deletions src/globals/CalendarSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ export const CalendarSettings: GlobalConfig = {
{
name: "visible",
type: "checkbox",
defaultValue: false,
defaultValue: true,
admin: {
description:
"Off: visitors get a holding page. Signed-in members still see the preview.",
"The calendar opens to visitors by itself on 1 December. Untick to take it down (visitors get a holding page); tick again to bring it back. Signed-in members always see the preview.",
},
},
{
Expand Down
7 changes: 5 additions & 2 deletions src/lib/calendar/doors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ export async function findDoors(
});
}

/** The settings and the open doors as a visitor, who sees nothing when the calendar is hidden. */
/** The settings and the open doors as a visitor, who sees nothing before 1 December (midnight Paris) or when the calendar is switched off. */
export async function getPublicState(now = new Date()) {
const settings = await getCalendarSettings();
const { today, ended } = getCalendarDay(now, settings);
const { today: started } = getCalendarDay(now, { ...settings, opensAtHour: 0 });
const open =
settings.visible && !(ended && settings.afterEnd === "holding");
settings.visible &&
started > 0 &&
!(ended && settings.afterEnd === "holding");
return { settings, today, open };
}
2 changes: 1 addition & 1 deletion src/lib/calendar/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function getCalendarSettings(): Promise<CalendarSettings> {
);

return {
visible: en.behaviour?.visible ?? false,
visible: en.behaviour?.visible ?? true,
year: en.behaviour?.year ?? defaultYear,
opensAtHour: en.behaviour?.opensAtHour ?? defaultHour,
afterEnd: en.behaviour?.afterEnd ?? "open",
Expand Down
Loading
Loading