From c4bbafb9d7df2e1b5bbaddbad322ed1449ad429e Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 18 Oct 2023 11:39:15 +0100 Subject: [PATCH] feat: seasonal features --- packages/app/src/Pages/Layout.css | 1 + packages/app/src/Pages/Layout.tsx | 10 ++++++++-- packages/app/src/SnortUtils/index.ts | 25 ++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/packages/app/src/Pages/Layout.css b/packages/app/src/Pages/Layout.css index 7b5e9897..337b8d55 100644 --- a/packages/app/src/Pages/Layout.css +++ b/packages/app/src/Pages/Layout.css @@ -1,5 +1,6 @@ .logo { cursor: pointer; + text-wrap: nowrap; } .logo h1 { diff --git a/packages/app/src/Pages/Layout.tsx b/packages/app/src/Pages/Layout.tsx index 57f6a7d4..49fe7539 100644 --- a/packages/app/src/Pages/Layout.tsx +++ b/packages/app/src/Pages/Layout.tsx @@ -12,7 +12,7 @@ import useLoginFeed from "Feed/LoginFeed"; import { mapPlanName } from "./subscribe"; import useLogin from "Hooks/useLogin"; import Avatar from "Element/User/Avatar"; -import { isFormElement } from "SnortUtils"; +import { isHalloween, isFormElement, isStPatricksDay, isChristmas } from "SnortUtils"; import { getCurrentSubscription } from "Subscription"; import Toaster from "Toaster"; import Spinner from "Icons/Spinner"; @@ -204,9 +204,15 @@ function LogoHeader() { const { subscriptions } = useLogin(); const currentSubscription = getCurrentSubscription(subscriptions); + const extra = () => { + if (isHalloween()) return "🎃"; + if (isStPatricksDay()) return "🍀"; + if (isChristmas()) return "🎄"; + } + return ( -

{CONFIG.appName}

+

{extra()}{CONFIG.appName}

{currentSubscription && ( diff --git a/packages/app/src/SnortUtils/index.ts b/packages/app/src/SnortUtils/index.ts index 48b6c679..acffbdda 100644 --- a/packages/app/src/SnortUtils/index.ts +++ b/packages/app/src/SnortUtils/index.ts @@ -15,6 +15,7 @@ import { MetadataCache, NostrLink, } from "@snort/system"; +import { Day } from "Const"; export const sha256 = (str: string | Uint8Array): u256 => { return utils.bytesToHex(hash(str)); @@ -469,7 +470,7 @@ export function kvToObject(o: string, sep?: string) { } export function defaultAvatar(input?: string) { - return `https://robohash.v0l.io/${input ?? "missing"}.png${IsHalloween() ? "?set=set2" : ""}`; + return `https://robohash.v0l.io/${input ?? "missing"}.png${isHalloween() ? "?set=set2" : ""}`; } export function isFormElement(target: HTMLElement): boolean { @@ -480,7 +481,25 @@ export function isFormElement(target: HTMLElement): boolean { return false; } -export const IsHalloween = () => { +const ThisYear = new Date().getFullYear(); +const SeasonalEventsWindow = 7; // n days before +const IsTheSeason = (target: Date) => { const now = new Date(); - return now.getMonth() === 9 && now.getDate() >= 17; + const days = (target.getTime() - now.getTime()) / (Day * 1000); + return days > 0 && days <= SeasonalEventsWindow; +}; + +export const isHalloween = () => { + const event = new Date(ThisYear, 9, 31); + return IsTheSeason(event); +}; + +export const isStPatricksDay = () => { + const event = new Date(ThisYear, 2, 17); + return IsTheSeason(event); +}; + +export const isChristmas = () => { + const event = new Date(ThisYear, 11, 25); + return IsTheSeason(event); };