From 8e6152106e8a9d011a1562972c8a4edff5cdc17a Mon Sep 17 00:00:00 2001 From: Dlurak <84224239+Dlurak@users.noreply.github.com> Date: Mon, 30 Oct 2023 23:18:14 +0100 Subject: [PATCH] :lipstick: :jack_o_lantern: Add a halloween logo --- src/constants/dates.ts | 38 ++++++++++++ src/lib/navbar/Navbar.svelte | 14 ++++- .../seasons/halloween/halloweenLogo.svelte | 51 ++++++++++++++++ src/lib/specialDates/isInRange.ts | 39 ++++++++++++ static/assets/pumpkin.svg | 60 +++++++++++++++++++ tests/settings.test.ts | 13 +++- 6 files changed, 209 insertions(+), 6 deletions(-) create mode 100644 src/constants/dates.ts create mode 100644 src/lib/seasons/halloween/halloweenLogo.svelte create mode 100644 src/lib/specialDates/isInRange.ts create mode 100644 static/assets/pumpkin.svg diff --git a/src/constants/dates.ts b/src/constants/dates.ts new file mode 100644 index 0000000..98def5c --- /dev/null +++ b/src/constants/dates.ts @@ -0,0 +1,38 @@ +import type { IntRange } from '../types/utils'; + +export type SpecialDate = { + month: IntRange<0, 13>; + day: IntRange<0, 32>; +}; + +export type specialDateRange = { + start: SpecialDate; + end: SpecialDate; +}; + +const specialDateNames = ['helloween', 'christmas'] as const; + +export type SpecialDates = (typeof specialDateNames)[number]; + +export const dates: Record = { + helloween: { + start: { + month: 10, + day: 29 + }, + end: { + month: 11, + day: 1 + } + }, + christmas: { + start: { + month: 12, + day: 22 + }, + end: { + month: 12, + day: 26 + } + } +}; diff --git a/src/lib/navbar/Navbar.svelte b/src/lib/navbar/Navbar.svelte index ddbd99d..f0a6b52 100644 --- a/src/lib/navbar/Navbar.svelte +++ b/src/lib/navbar/Navbar.svelte @@ -1,5 +1,7 @@ + + +
(showTooltip = false)} + on:mouseenter={() => (showTooltip = true)} + role="img" + aria-label="Halloween" + > + Halloween +
+
+ +
+

+ " + かぼけゃ + " is marked with + CC0 1.0. +

+
diff --git a/src/lib/specialDates/isInRange.ts b/src/lib/specialDates/isInRange.ts new file mode 100644 index 0000000..1219ded --- /dev/null +++ b/src/lib/specialDates/isInRange.ts @@ -0,0 +1,39 @@ +import { + dates, + type SpecialDate, + type specialDateRange, + type SpecialDates +} from '../../constants/dates'; + +const isAfterDate = (date: SpecialDate): boolean => { + const currentDay = new Date().getDate(); + const currentMonth = new Date().getMonth() + 1; + return currentMonth > date.month || (currentMonth === date.month && currentDay >= date.day); +}; + +const isBeforeDate = (date: SpecialDate): boolean => { + const currentDay = new Date().getDate(); + const currentMonth = new Date().getMonth() + 1; + return currentMonth < date.month || (currentMonth === date.month && currentDay <= date.day); +}; + +const isDate = (date: SpecialDate): boolean => { + const currentDay = new Date().getDate(); + const currentMonth = new Date().getMonth() + 1; + return currentMonth === date.month && currentDay === date.day; +}; + +const isInRange = (date: specialDateRange): boolean => { + const { start, end } = date; + return (isAfterDate(start) && isBeforeDate(end)) || isDate(start) || isDate(end); +}; + +export const currentSpecialDates = (d: Record = dates) => { + const currentDates = Object.values(d).filter(isInRange); + const currentDatesNames = Object.keys(d).filter((key) => + currentDates.includes(d[key as SpecialDates]) + ); + return currentDatesNames as SpecialDates[]; +}; + +export const isSpecialDate = (date: SpecialDates): boolean => currentSpecialDates().includes(date); diff --git a/static/assets/pumpkin.svg b/static/assets/pumpkin.svg new file mode 100644 index 0000000..e8a5d9f --- /dev/null +++ b/static/assets/pumpkin.svg @@ -0,0 +1,60 @@ + + + + +Created by potrace 1.15, written by Peter Selinger 2001-2017 + + + + + + + + + + diff --git a/tests/settings.test.ts b/tests/settings.test.ts index 3de876e..fa82a46 100644 --- a/tests/settings.test.ts +++ b/tests/settings.test.ts @@ -66,7 +66,12 @@ test('the text in navigion can be toggled and is saved', async ({ page }) => { for (let i = 0; i < navItemsArray.length; i++) { const navItem = navItemsArray[i]; - await expect(navItem).toHaveText(/.*/); + const navItemHasImg = (await navItem.locator('img').count()) > 0; + if (navItemHasImg) { + await expect(navItem).toHaveText(''); + } else { + await expect(navItem).toHaveText(/.*/); + } } await page.waitForTimeout(300); @@ -82,7 +87,8 @@ test('the text in navigion can be toggled and is saved', async ({ page }) => { for (let i = 0; i < navItemsArray.length; i++) { const navItem = navItemsArray[i]; - await expect(navItem).toHaveText(''); + const navItemHasImg = (await navItem.locator('img').count()) > 0; + if (navItemHasImg) await expect(navItem).toHaveText(''); } await page.reload(); @@ -94,7 +100,8 @@ test('the text in navigion can be toggled and is saved', async ({ page }) => { for (let i = 0; i < navItemsArray.length; i++) { const navItem = navItemsArray[i]; - await expect(navItem).toHaveText(''); + const navItemHasBxIcon = (await navItem.locator('i.bx').count()) > 0; + if (navItemHasBxIcon) await expect(navItem).toHaveText(''); } localator = await page.getByRole('switch');