feat: seasonal features

This commit is contained in:
Kieran 2023-10-18 11:39:15 +01:00
parent ab50afe917
commit c4bbafb9d7
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
3 changed files with 31 additions and 5 deletions

View File

@ -1,5 +1,6 @@
.logo { .logo {
cursor: pointer; cursor: pointer;
text-wrap: nowrap;
} }
.logo h1 { .logo h1 {

View File

@ -12,7 +12,7 @@ import useLoginFeed from "Feed/LoginFeed";
import { mapPlanName } from "./subscribe"; import { mapPlanName } from "./subscribe";
import useLogin from "Hooks/useLogin"; import useLogin from "Hooks/useLogin";
import Avatar from "Element/User/Avatar"; import Avatar from "Element/User/Avatar";
import { isFormElement } from "SnortUtils"; import { isHalloween, isFormElement, isStPatricksDay, isChristmas } from "SnortUtils";
import { getCurrentSubscription } from "Subscription"; import { getCurrentSubscription } from "Subscription";
import Toaster from "Toaster"; import Toaster from "Toaster";
import Spinner from "Icons/Spinner"; import Spinner from "Icons/Spinner";
@ -204,9 +204,15 @@ function LogoHeader() {
const { subscriptions } = useLogin(); const { subscriptions } = useLogin();
const currentSubscription = getCurrentSubscription(subscriptions); const currentSubscription = getCurrentSubscription(subscriptions);
const extra = () => {
if (isHalloween()) return "🎃";
if (isStPatricksDay()) return "🍀";
if (isChristmas()) return "🎄";
}
return ( return (
<Link to="/" className="logo"> <Link to="/" className="logo">
<h1>{CONFIG.appName}</h1> <h1>{extra()}{CONFIG.appName}</h1>
{currentSubscription && ( {currentSubscription && (
<small className="flex items-center g4"> <small className="flex items-center g4">
<Icon name="diamond" size={10} /> <Icon name="diamond" size={10} />

View File

@ -15,6 +15,7 @@ import {
MetadataCache, MetadataCache,
NostrLink, NostrLink,
} from "@snort/system"; } from "@snort/system";
import { Day } from "Const";
export const sha256 = (str: string | Uint8Array): u256 => { export const sha256 = (str: string | Uint8Array): u256 => {
return utils.bytesToHex(hash(str)); return utils.bytesToHex(hash(str));
@ -469,7 +470,7 @@ export function kvToObject<T>(o: string, sep?: string) {
} }
export function defaultAvatar(input?: 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 { export function isFormElement(target: HTMLElement): boolean {
@ -480,7 +481,25 @@ export function isFormElement(target: HTMLElement): boolean {
return false; return false;
} }
export const IsHalloween = () => { const ThisYear = new Date().getFullYear();
const SeasonalEventsWindow = 7; // n days before
const IsTheSeason = (target: Date) => {
const now = new 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);
}; };