From af9681476e4dedda3cd6e408bfd35f25dc7883a2 Mon Sep 17 00:00:00 2001 From: Mle225 Date: Thu, 28 Apr 2022 13:12:38 +0700 Subject: [PATCH 01/22] added common util folder, implemented isStringTruthy, added isPinned to acmEvent --- src/lib/common/utils.ts | 7 +++++++ src/lib/constants/index.ts | 4 +++- src/lib/ical/utils.ts | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/lib/common/utils.ts diff --git a/src/lib/common/utils.ts b/src/lib/common/utils.ts new file mode 100644 index 000000000..21bcf0627 --- /dev/null +++ b/src/lib/common/utils.ts @@ -0,0 +1,7 @@ +export function isStringTruthy(str: string) : boolean { + if (str === null) { + return false; + } + + return !['false', '0', ''].includes(str.toLowerCase()); +} \ No newline at end of file diff --git a/src/lib/constants/index.ts b/src/lib/constants/index.ts index 87f37e13c..aaf612a05 100644 --- a/src/lib/constants/index.ts +++ b/src/lib/constants/index.ts @@ -2,5 +2,7 @@ export * from './acm-paths'; export * from './links'; export * from './officers'; +import { isStringTruthy } from '../common/utils'; + // DEBUG flag is activated when anything besides '', '0', or 'false' is selected -export const DEBUG = !['', '0', 'false'].includes(String(import.meta.env.VITE_DEBUG).toLowerCase()); +export const DEBUG = isStringTruthy(import.meta.env.VITE_DEBUG); diff --git a/src/lib/ical/utils.ts b/src/lib/ical/utils.ts index 76dec3941..dff246669 100644 --- a/src/lib/ical/utils.ts +++ b/src/lib/ical/utils.ts @@ -2,6 +2,7 @@ import * as RRule from 'rrule/dist/es5/rrule.min.js'; import { Temporal } from '@js-temporal/polyfill'; import type { AcmPath } from '$lib/constants/acm-paths'; import { acmAlgo, acmCreate, acmDev, acmGeneral } from '$lib/constants/acm-paths'; +import { isStringTruthy } from '../common/utils'; export interface AcmEvent { month: string; @@ -9,6 +10,7 @@ export interface AcmEvent { time: string; hasStarted: boolean; hasEnded: boolean; + isPinned: boolean; duration: string; date: string; location: string; @@ -318,6 +320,8 @@ export function makeAcmEvent( variables.get('ACM_LOCATION') ); + const isPinned = isStringTruthy(variables.get('ACM_PINNED')); + const slug = makeEventSlug(title, dtStart); const selfLink = makeEventLink(slug); @@ -357,6 +361,7 @@ export function makeAcmEvent( date, hasStarted, hasEnded, + isPinned, duration, location, title, From 93dcbde6695db76caa22171e0ca611c5c31d1b26 Mon Sep 17 00:00:00 2001 From: Mle225 Date: Fri, 29 Apr 2022 03:47:59 +0700 Subject: [PATCH 02/22] cast DEBUG to string to check --- src/lib/common/utils.ts | 6 +++--- src/lib/constants/index.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/common/utils.ts b/src/lib/common/utils.ts index 21bcf0627..0531e8c12 100644 --- a/src/lib/common/utils.ts +++ b/src/lib/common/utils.ts @@ -1,7 +1,7 @@ -export function isStringTruthy(str: string) : boolean { - if (str === null) { +export function isStringTruthy(str: string): boolean { + if (str == null) { return false; } return !['false', '0', ''].includes(str.toLowerCase()); -} \ No newline at end of file +} diff --git a/src/lib/constants/index.ts b/src/lib/constants/index.ts index aaf612a05..a6cd0e31e 100644 --- a/src/lib/constants/index.ts +++ b/src/lib/constants/index.ts @@ -5,4 +5,4 @@ export * from './officers'; import { isStringTruthy } from '../common/utils'; // DEBUG flag is activated when anything besides '', '0', or 'false' is selected -export const DEBUG = isStringTruthy(import.meta.env.VITE_DEBUG); +export const DEBUG = isStringTruthy(String(import.meta.env.VITE_DEBUG)); From 9a02c7a3ab6e866da10b0df3b74ba6fdc2804034 Mon Sep 17 00:00:00 2001 From: mle225 Date: Sat, 30 Apr 2022 02:51:15 +0700 Subject: [PATCH 03/22] Update isStringTruthy function signature Co-authored-by: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> --- src/lib/common/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/common/utils.ts b/src/lib/common/utils.ts index 0531e8c12..d8331161b 100644 --- a/src/lib/common/utils.ts +++ b/src/lib/common/utils.ts @@ -1,4 +1,4 @@ -export function isStringTruthy(str: string): boolean { +export function isStringTruthy(payload?: string | null, defaultValue = false): boolean { if (str == null) { return false; } From 0b6bc9f11bd76ee98efe56220dbd032c15329331 Mon Sep 17 00:00:00 2001 From: mle225 Date: Sat, 30 Apr 2022 02:54:35 +0700 Subject: [PATCH 04/22] Update isStringTruthy truthy check Co-authored-by: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> --- src/lib/common/utils.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib/common/utils.ts b/src/lib/common/utils.ts index d8331161b..72502be95 100644 --- a/src/lib/common/utils.ts +++ b/src/lib/common/utils.ts @@ -1,7 +1,5 @@ export function isStringTruthy(payload?: string | null, defaultValue = false): boolean { - if (str == null) { - return false; - } + if (!payload) return false; return !['false', '0', ''].includes(str.toLowerCase()); } From 030f1b2e19153d964ac467fc6bd308767966960a Mon Sep 17 00:00:00 2001 From: mle225 Date: Sat, 30 Apr 2022 03:07:34 +0700 Subject: [PATCH 05/22] Update src/lib/common/utils.ts Co-authored-by: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> --- src/lib/common/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/common/utils.ts b/src/lib/common/utils.ts index 72502be95..cf3cc2e25 100644 --- a/src/lib/common/utils.ts +++ b/src/lib/common/utils.ts @@ -1,5 +1,5 @@ export function isStringTruthy(payload?: string | null, defaultValue = false): boolean { if (!payload) return false; - return !['false', '0', ''].includes(str.toLowerCase()); + return !['0', 'false'].includes(payload.trim().toLowerCase()); } From dcd14855e9e14b402b2c72d41f16a0b26d5f7bef Mon Sep 17 00:00:00 2001 From: Mle225 Date: Sat, 30 Apr 2022 04:45:21 +0700 Subject: [PATCH 06/22] modified isStringTruthy and added test cases --- src/lib/common/utils.test.ts | 19 +++++++++++++++++++ src/lib/common/utils.ts | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/lib/common/utils.test.ts diff --git a/src/lib/common/utils.test.ts b/src/lib/common/utils.test.ts new file mode 100644 index 000000000..a7b7d6bef --- /dev/null +++ b/src/lib/common/utils.test.ts @@ -0,0 +1,19 @@ +import { test, expect } from 'vitest'; +import * as utils from './utils'; + +test('checks correct isStringTruthy output for falsy and truthy values', () => { + expect(utils.isStringTruthy('FALSE') === false); + expect(utils.isStringTruthy('') === false); + expect(utils.isStringTruthy('') === false); + expect(utils.isStringTruthy(``) === false); + expect(utils.isStringTruthy(null) === false); + expect(utils.isStringTruthy(undefined) === false); + expect(utils.isStringTruthy(String(false)) === false); + expect(utils.isStringTruthy(String(NaN)) === false); + expect(utils.isStringTruthy(String(0)) === false); + expect(utils.isStringTruthy(String(-0)) === false); + // truthy values + expect(utils.isStringTruthy('TRUE') === true); + expect(utils.isStringTruthy(String(true)) === true); + expect(utils.isStringTruthy(String(1)) === true); +}); diff --git a/src/lib/common/utils.ts b/src/lib/common/utils.ts index cf3cc2e25..77b201495 100644 --- a/src/lib/common/utils.ts +++ b/src/lib/common/utils.ts @@ -1,5 +1,6 @@ export function isStringTruthy(payload?: string | null, defaultValue = false): boolean { - if (!payload) return false; + if (!payload) return defaultValue; - return !['0', 'false'].includes(payload.trim().toLowerCase()); + // unlikely NaN will be passed, but included to be safe + return !['0', 'false', 'nan'].includes(payload.trim().toLowerCase()); } From f7dfbc0848add10560cf9101a65b2ba954c8dcaf Mon Sep 17 00:00:00 2001 From: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> Date: Thu, 19 May 2022 00:50:04 -0700 Subject: [PATCH 07/22] Refactored truthiness checker function - Renamed to `determineTruthyString` --- src/lib/common/utils.ts | 8 ++++++-- src/lib/constants/index.ts | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib/common/utils.ts b/src/lib/common/utils.ts index 77b201495..5db421847 100644 --- a/src/lib/common/utils.ts +++ b/src/lib/common/utils.ts @@ -1,6 +1,10 @@ -export function isStringTruthy(payload?: string | null, defaultValue = false): boolean { +export function determineTruthyString(payload?: string | null, defaultValue = false): boolean { if (!payload) return defaultValue; + payload = payload.trim().toLowerCase(); + // unlikely NaN will be passed, but included to be safe - return !['0', 'false', 'nan'].includes(payload.trim().toLowerCase()); + const stringsOtherwiseTruthy = [0, false, NaN].map((v) => String(v).toLowerCase()); + + return !stringsOtherwiseTruthy.includes(payload); } diff --git a/src/lib/constants/index.ts b/src/lib/constants/index.ts index a6cd0e31e..c6e97e692 100644 --- a/src/lib/constants/index.ts +++ b/src/lib/constants/index.ts @@ -2,7 +2,7 @@ export * from './acm-paths'; export * from './links'; export * from './officers'; -import { isStringTruthy } from '../common/utils'; +import { determineTruthyString } from '../common/utils'; // DEBUG flag is activated when anything besides '', '0', or 'false' is selected -export const DEBUG = isStringTruthy(String(import.meta.env.VITE_DEBUG)); +export const DEBUG = determineTruthyString(import.meta.env.VITE_DEBUG); From 69dd5f3ef45e28d51bb4957aebb3e872c27d1841 Mon Sep 17 00:00:00 2001 From: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> Date: Thu, 19 May 2022 00:51:54 -0700 Subject: [PATCH 08/22] Updated tests for `determineTruthyString` --- src/lib/common/utils.test.ts | 39 +++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/lib/common/utils.test.ts b/src/lib/common/utils.test.ts index a7b7d6bef..96f0ef2ca 100644 --- a/src/lib/common/utils.test.ts +++ b/src/lib/common/utils.test.ts @@ -1,19 +1,26 @@ import { test, expect } from 'vitest'; import * as utils from './utils'; -test('checks correct isStringTruthy output for falsy and truthy values', () => { - expect(utils.isStringTruthy('FALSE') === false); - expect(utils.isStringTruthy('') === false); - expect(utils.isStringTruthy('') === false); - expect(utils.isStringTruthy(``) === false); - expect(utils.isStringTruthy(null) === false); - expect(utils.isStringTruthy(undefined) === false); - expect(utils.isStringTruthy(String(false)) === false); - expect(utils.isStringTruthy(String(NaN)) === false); - expect(utils.isStringTruthy(String(0)) === false); - expect(utils.isStringTruthy(String(-0)) === false); - // truthy values - expect(utils.isStringTruthy('TRUE') === true); - expect(utils.isStringTruthy(String(true)) === true); - expect(utils.isStringTruthy(String(1)) === true); -}); +const TRUTHY_INPUT_DATA = ['TRUE', String(true), String(1)]; +for (const input of TRUTHY_INPUT_DATA) { + test(`correctly determines input value '${input}' as truthy`, () => { + expect(utils.determineTruthyString(input)).toBe(true); + }); +} + +const FALSY_INPUT_DATA = [ + 'FALSE', + '', + ``, + null, + undefined, + String(false), + String(NaN), + String(0), + String(-0), +]; +for (const input of FALSY_INPUT_DATA) { + test(`correctly determines input value '${input}' as falsy`, () => { + expect(utils.determineTruthyString(input)).toBe(false); + }); +} From f9db6abff1993e018c8ff4fd0ccba8b118f220d1 Mon Sep 17 00:00:00 2001 From: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> Date: Thu, 19 May 2022 00:53:31 -0700 Subject: [PATCH 09/22] Updated import for `determineTruthyString` --- src/lib/ical/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/ical/utils.ts b/src/lib/ical/utils.ts index dff246669..d8a6bc802 100644 --- a/src/lib/ical/utils.ts +++ b/src/lib/ical/utils.ts @@ -2,7 +2,7 @@ import * as RRule from 'rrule/dist/es5/rrule.min.js'; import { Temporal } from '@js-temporal/polyfill'; import type { AcmPath } from '$lib/constants/acm-paths'; import { acmAlgo, acmCreate, acmDev, acmGeneral } from '$lib/constants/acm-paths'; -import { isStringTruthy } from '../common/utils'; +import { determineTruthyString } from '$lib/common/utils'; export interface AcmEvent { month: string; @@ -320,7 +320,7 @@ export function makeAcmEvent( variables.get('ACM_LOCATION') ); - const isPinned = isStringTruthy(variables.get('ACM_PINNED')); + const isPinned = determineTruthyString(variables.get('ACM_PINNED')); const slug = makeEventSlug(title, dtStart); From af8c952a87cca83d84c19273a6349dd7490985de Mon Sep 17 00:00:00 2001 From: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> Date: Thu, 19 May 2022 01:10:43 -0700 Subject: [PATCH 10/22] Attempt number 1 at _Recent Events_ UI --- src/routes/events/index.svelte | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/routes/events/index.svelte b/src/routes/events/index.svelte index 4a6ec7948..d300e1d0a 100644 --- a/src/routes/events/index.svelte +++ b/src/routes/events/index.svelte @@ -15,6 +15,17 @@ import AcmEmpty from '$lib/components/utils/acm-empty.svelte'; export let events: AcmEvent[] = []; + + let unpinnedEvents: AcmEvent[] = []; + let pinnedEvents: AcmEvent[] = []; + + $: { + [unpinnedEvents, pinnedEvents] = [[], []]; + events.forEach((event) => { + if (event.hasEnded && event.isPinned) pinnedEvents.push(event); + else unpinnedEvents.push(event); + }); + } @@ -45,7 +56,7 @@ {#if events.length > 0} - + {:else}

There are no events scheduled!

@@ -54,6 +65,23 @@ +
+

Recent Events

+ Blue Calender +
+ + + +{#if events.length > 0} + +{:else} + +

There are no recent events posted!

+
+{/if} + + +