Skip to content

Commit

Permalink
Events: Display TBD if location is empty or null (#479)
Browse files Browse the repository at this point in the history
* Display TBD if location is empty or null

* move bulk of logic to utils, tests are kinda scuffed

* fix logic, still need ternary, update test

* Move around logic to be more readable

* null check in parse, format in ui, remove unit test

* add !location and fix info.location

* I forgor

* null check and trim everything, change default location

* Update src/lib/components/events/event-item.svelte

Co-authored-by: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com>

* Remove optional chaining, update test data and test

* Add unit tests to format location

* remove unecessary toast 🍞

* Add good location format tests

Co-authored-by: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com>
Co-authored-by: jason wong <jayywong92@gmail.com>
  • Loading branch information
3 people committed Jun 5, 2022
1 parent 145ad90 commit e571135
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 41 deletions.
14 changes: 2 additions & 12 deletions src/lib/components/events/event-item.svelte
@@ -1,26 +1,18 @@
<script lang="ts">
import { onMount } from 'svelte';
import type { AcmEvent } from '$lib/ical';
import { toast, ToastType } from '$lib/stores/toasts';
import CopyLinkIcon from '$lib/components/icons/copy-link.svelte';
import CopyTextIcon from '$lib/components/icons/copy-text.svelte';
import GoogleCalendarIcon from '$lib/components/icons/google-calendar.svelte';
import MsOutlookIcon from '$lib/components/icons/ms-outlook.svelte';
import { formatLocation, copy } from './utils';
export let info: AcmEvent;
let isRecurring: boolean = info.recurring;
let anchor: HTMLElement;
let details: HTMLDetailsElement;
/** @see <https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText> */
function copy(link: string, successMessage: string, errorMessage: string, path: string) {
navigator.clipboard
.writeText(link)
.then(() => toast({ content: successMessage, path }))
.catch(() => toast({ path, type: ToastType.Error, content: errorMessage }));
}
onMount(() => {
if (location.hash === `#${info.slug}`) {
anchor.scrollIntoView({
Expand All @@ -47,9 +39,7 @@
</h2>

<p class="event-location">
{info.location === 'Discord' || info.location === 'Zoom'
? `Hosted on ${info.location}`
: info.location}
{formatLocation(info.location)}
</p>
</div>

Expand Down
19 changes: 19 additions & 0 deletions src/lib/components/events/event-item.test.ts
@@ -0,0 +1,19 @@
import { expect, test } from 'vitest';
import { formatLocation } from './utils';

test('can format bad locations', () => {
expect(formatLocation(null)).toBe('TBD');
expect(formatLocation('')).toBe('TBD');
expect(formatLocation(undefined)).toBe('TBD');
expect(formatLocation(" Your mom's house ")).toBe("Your mom's house");
});

test('can format online locations', () => {
expect(formatLocation('Discord')).toBe('Hosted on Discord');
expect(formatLocation('Zoom')).toBe('Hosted on Zoom');
});

test('can format good locations', () => {
expect(formatLocation('CS-104')).toBe('CS-104');
expect(formatLocation('TSU Pavilions')).toBe('TSU Pavilions');
});
16 changes: 16 additions & 0 deletions src/lib/components/events/utils.ts
@@ -0,0 +1,16 @@
import { toast, ToastType } from '$lib/stores/toasts';

/** @see <https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText> */
export function copy(link: string, successMessage: string, errorMessage: string, path: string) {
navigator.clipboard
.writeText(link)
.then(() => toast({ content: successMessage, path }))
.catch(() => toast({ path, type: ToastType.Error, content: errorMessage }));
}

export function formatLocation(location?: string | null, hosted = ['Discord', 'Zoom']): string {
// '', null, and undefined are all TBD
location = location?.trim() ?? '';
if (location === '') return 'TBD';
return hosted.includes(location) ? `Hosted on ${location}` : location;
}
2 changes: 1 addition & 1 deletion src/lib/ical/parse.test.ts
Expand Up @@ -15,5 +15,5 @@ test('ICAL parser integration test', () => {
// `export const events = ${JSON.stringify(events)};`
// );

expect(JSON.stringify(events)).toBe(JSON.stringify(EVENT_DATA));
expect(events).toEqual(EVENT_DATA);
});
10 changes: 6 additions & 4 deletions src/lib/ical/utils.ts
Expand Up @@ -241,18 +241,20 @@ export function makeOutlookCalendarLink(

export function parseLocation(
rawLocation?: string,
defaultLocation = 'Discord',
defaultLocation = 'TBD',
defaultLink = '/discord'
): { location: string; meetingLink: string } {
if (rawLocation?.includes('zoom.us')) {
rawLocation = rawLocation?.trim() ?? '';

if (rawLocation.includes('zoom.us')) {
return { location: 'Zoom', meetingLink: rawLocation };
}

if (rawLocation?.startsWith('https://')) {
if (rawLocation.startsWith('https://')) {
return { location: defaultLocation, meetingLink: rawLocation };
}

if (rawLocation?.length > 0) {
if (rawLocation.length > 0) {
return { location: rawLocation, meetingLink: defaultLink };
}

Expand Down
48 changes: 24 additions & 24 deletions src/routes/events/_testdata/events.ts
Expand Up @@ -7,7 +7,7 @@ export const events = [
hasStarted: true,
hasEnded: true,
duration: '0 minutes',
location: 'Discord',
location: 'TBD',
title: 'ACM & ACM-W Meeting',
summary: 'ACM & ACM-W Meeting — https://acmcsuf.com/events#acm-acm-w-meeting-2018-august-17',
description: '',
Expand All @@ -23,9 +23,9 @@ export const events = [
},
calendarLinks: {
google:
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=ACM+%26+ACM-W+Meeting&details=ACM+%26+ACM-W+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23acm-acm-w-meeting-2018-august-17&location=https%3A%2F%2Facmcsuf.com%2Fevents%23acm-acm-w-meeting-2018-august-17&dates=20180817T120017%2F20180817T130017',
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=ACM+%26+ACM-W+Meeting&details=ACM+%26+ACM-W+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23acm-acm-w-meeting-2018-august-17&location=TBD&dates=20180817T120017%2F20180817T130017',
outlook:
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20180817T120017&enddt=20180817T130017&subject=ACM+%26+ACM-W+Meeting&body=ACM+%26+ACM-W+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23acm-acm-w-meeting-2018-august-17&location=https%3A%2F%2Facmcsuf.com%2Fevents%23acm-acm-w-meeting-2018-august-17',
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20180817T120017&enddt=20180817T130017&subject=ACM+%26+ACM-W+Meeting&body=ACM+%26+ACM-W+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23acm-acm-w-meeting-2018-august-17&location=TBD',
},
},
{
Expand All @@ -36,7 +36,7 @@ export const events = [
hasStarted: true,
hasEnded: true,
duration: '0 minutes',
location: 'Discord',
location: 'TBD',
title: 'ACM Board Meeting',
summary: 'ACM Board Meeting — https://acmcsuf.com/events#acm-board-meeting-2018-august-17',
description: '',
Expand All @@ -52,9 +52,9 @@ export const events = [
},
calendarLinks: {
google:
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=ACM+Board+Meeting&details=ACM+Board+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23acm-board-meeting-2018-august-17&location=https%3A%2F%2Facmcsuf.com%2Fevents%23acm-board-meeting-2018-august-17&dates=20180817T170017%2F20180817T190017',
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=ACM+Board+Meeting&details=ACM+Board+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23acm-board-meeting-2018-august-17&location=TBD&dates=20180817T170017%2F20180817T190017',
outlook:
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20180817T170017&enddt=20180817T190017&subject=ACM+Board+Meeting&body=ACM+Board+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23acm-board-meeting-2018-august-17&location=https%3A%2F%2Facmcsuf.com%2Fevents%23acm-board-meeting-2018-august-17',
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20180817T170017&enddt=20180817T190017&subject=ACM+Board+Meeting&body=ACM+Board+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23acm-board-meeting-2018-august-17&location=TBD',
},
},
{
Expand All @@ -65,7 +65,7 @@ export const events = [
hasStarted: true,
hasEnded: true,
duration: '0 minutes',
location: 'Discord',
location: 'TBD',
title: 'Personal Website Workshop Planning',
summary:
'Personal Website Workshop Planning — https://acmcsuf.com/events#personal-website-workshop-planning-2018-august-21',
Expand All @@ -82,9 +82,9 @@ export const events = [
},
calendarLinks: {
google:
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=Personal+Website+Workshop+Planning&details=Personal+Website+Workshop+Planning+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23personal-website-workshop-planning-2018-august-21&location=https%3A%2F%2Facmcsuf.com%2Fevents%23personal-website-workshop-planning-2018-august-21&dates=20180821T120021%2F20180821T150021',
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=Personal+Website+Workshop+Planning&details=Personal+Website+Workshop+Planning+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23personal-website-workshop-planning-2018-august-21&location=TBD&dates=20180821T120021%2F20180821T150021',
outlook:
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20180821T120021&enddt=20180821T150021&subject=Personal+Website+Workshop+Planning&body=Personal+Website+Workshop+Planning+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23personal-website-workshop-planning-2018-august-21&location=https%3A%2F%2Facmcsuf.com%2Fevents%23personal-website-workshop-planning-2018-august-21',
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20180821T120021&enddt=20180821T150021&subject=Personal+Website+Workshop+Planning&body=Personal+Website+Workshop+Planning+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23personal-website-workshop-planning-2018-august-21&location=TBD',
},
},
{
Expand All @@ -95,7 +95,7 @@ export const events = [
hasStarted: true,
hasEnded: true,
duration: '0 minutes',
location: 'Discord',
location: 'TBD',
title: 'Leadcon',
summary: 'Leadcon — https://acmcsuf.com/events#leadcon-2018-august-24',
description: '',
Expand All @@ -111,9 +111,9 @@ export const events = [
},
calendarLinks: {
google:
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=Leadcon&details=Leadcon+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23leadcon-2018-august-24&location=https%3A%2F%2Facmcsuf.com%2Fevents%23leadcon-2018-august-24&dates=20180824T090024%2F20180824T160024',
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=Leadcon&details=Leadcon+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23leadcon-2018-august-24&location=TBD&dates=20180824T090024%2F20180824T160024',
outlook:
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20180824T090024&enddt=20180824T160024&subject=Leadcon&body=Leadcon+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23leadcon-2018-august-24&location=https%3A%2F%2Facmcsuf.com%2Fevents%23leadcon-2018-august-24',
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20180824T090024&enddt=20180824T160024&subject=Leadcon&body=Leadcon+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23leadcon-2018-august-24&location=TBD',
},
},
{
Expand Down Expand Up @@ -155,7 +155,7 @@ export const events = [
hasStarted: true,
hasEnded: true,
duration: '0 minutes',
location: 'Discord',
location: 'TBD',
title: 'Project Jam Meeting',
summary:
'Project Jam Meeting — https://acmcsuf.com/events#project-jam-meeting-2018-september-14',
Expand All @@ -172,9 +172,9 @@ export const events = [
},
calendarLinks: {
google:
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=Project+Jam+Meeting&details=Project+Jam+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23project-jam-meeting-2018-september-14&location=https%3A%2F%2Facmcsuf.com%2Fevents%23project-jam-meeting-2018-september-14&dates=20180914T190014%2F20180914T210014',
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=Project+Jam+Meeting&details=Project+Jam+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23project-jam-meeting-2018-september-14&location=TBD&dates=20180914T190014%2F20180914T210014',
outlook:
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20180914T190014&enddt=20180914T210014&subject=Project+Jam+Meeting&body=Project+Jam+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23project-jam-meeting-2018-september-14&location=https%3A%2F%2Facmcsuf.com%2Fevents%23project-jam-meeting-2018-september-14',
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20180914T190014&enddt=20180914T210014&subject=Project+Jam+Meeting&body=Project+Jam+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23project-jam-meeting-2018-september-14&location=TBD',
},
},
{
Expand All @@ -185,7 +185,7 @@ export const events = [
hasStarted: true,
hasEnded: true,
duration: '0 minutes',
location: 'ROOM SGSR212 CSUF Pollak Library ',
location: 'ROOM SGSR212 CSUF Pollak Library',
title: 'Personal Website Workshop Mock Presentation',
summary:
'Personal Website Workshop Mock Presentation\n===========================================\n\nLink to slides: https://goo.gl/uQCu5u\n\nhttps://acmcsuf.com/events#personal-website-workshop-mock-presentation-2018-september-19',
Expand All @@ -203,9 +203,9 @@ export const events = [
},
calendarLinks: {
google:
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=Personal+Website+Workshop+Mock+Presentation&details=Personal+Website+Workshop+Mock+Presentation%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A%0ALink+to+slides%3A+https%3A%2F%2Fgoo.gl%2FuQCu5u%0A%0Ahttps%3A%2F%2Facmcsuf.com%2Fevents%23personal-website-workshop-mock-presentation-2018-september-19&location=ROOM+SGSR212+CSUF+Pollak+Library+&dates=20180919T120019%2F20180919T140019',
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=Personal+Website+Workshop+Mock+Presentation&details=Personal+Website+Workshop+Mock+Presentation%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A%0ALink+to+slides%3A+https%3A%2F%2Fgoo.gl%2FuQCu5u%0A%0Ahttps%3A%2F%2Facmcsuf.com%2Fevents%23personal-website-workshop-mock-presentation-2018-september-19&location=ROOM+SGSR212+CSUF+Pollak+Library&dates=20180919T120019%2F20180919T140019',
outlook:
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20180919T120019&enddt=20180919T140019&subject=Personal+Website+Workshop+Mock+Presentation&body=Personal+Website+Workshop+Mock+Presentation%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A%0ALink+to+slides%3A+https%3A%2F%2Fgoo.gl%2FuQCu5u%0A%0Ahttps%3A%2F%2Facmcsuf.com%2Fevents%23personal-website-workshop-mock-presentation-2018-september-19&location=ROOM+SGSR212+CSUF+Pollak+Library+',
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20180919T120019&enddt=20180919T140019&subject=Personal+Website+Workshop+Mock+Presentation&body=Personal+Website+Workshop+Mock+Presentation%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A%0ALink+to+slides%3A+https%3A%2F%2Fgoo.gl%2FuQCu5u%0A%0Ahttps%3A%2F%2Facmcsuf.com%2Fevents%23personal-website-workshop-mock-presentation-2018-september-19&location=ROOM+SGSR212+CSUF+Pollak+Library',
},
},
{
Expand Down Expand Up @@ -247,7 +247,7 @@ export const events = [
hasStarted: true,
hasEnded: true,
duration: '0 minutes',
location: 'Discord',
location: 'TBD',
title: 'Website Meeting',
summary: 'Website Meeting — https://acmcsuf.com/events#website-meeting-2019-february-5',
description: '',
Expand All @@ -263,9 +263,9 @@ export const events = [
},
calendarLinks: {
google:
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=Website+Meeting&details=Website+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23website-meeting-2019-february-5&location=https%3A%2F%2Facmcsuf.com%2Fevents%23website-meeting-2019-february-5&dates=20190205T183005%2F20190205T193005',
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=Website+Meeting&details=Website+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23website-meeting-2019-february-5&location=TBD&dates=20190205T183005%2F20190205T193005',
outlook:
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20190205T183005&enddt=20190205T193005&subject=Website+Meeting&body=Website+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23website-meeting-2019-february-5&location=https%3A%2F%2Facmcsuf.com%2Fevents%23website-meeting-2019-february-5',
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20190205T183005&enddt=20190205T193005&subject=Website+Meeting&body=Website+Meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23website-meeting-2019-february-5&location=TBD',
},
},
{
Expand All @@ -276,7 +276,7 @@ export const events = [
hasStarted: true,
hasEnded: true,
duration: '0 minutes',
location: 'Discord',
location: 'TBD',
title: 'Workshop meeting',
summary: 'Workshop meeting — https://acmcsuf.com/events#workshop-meeting-2019-february-6',
description: '',
Expand All @@ -292,9 +292,9 @@ export const events = [
},
calendarLinks: {
google:
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=Workshop+meeting&details=Workshop+meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23workshop-meeting-2019-february-6&location=https%3A%2F%2Facmcsuf.com%2Fevents%23workshop-meeting-2019-february-6&dates=20190206T103006%2F20190206T113006',
'https://calendar.google.com/calendar/render?action=TEMPLATE&text=Workshop+meeting&details=Workshop+meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23workshop-meeting-2019-february-6&location=TBD&dates=20190206T103006%2F20190206T113006',
outlook:
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20190206T103006&enddt=20190206T113006&subject=Workshop+meeting&body=Workshop+meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23workshop-meeting-2019-february-6&location=https%3A%2F%2Facmcsuf.com%2Fevents%23workshop-meeting-2019-february-6',
'https://outlook.live.com/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=20190206T103006&enddt=20190206T113006&subject=Workshop+meeting&body=Workshop+meeting+%E2%80%94+https%3A%2F%2Facmcsuf.com%2Fevents%23workshop-meeting-2019-february-6&location=TBD',
},
},
];

1 comment on commit e571135

@vercel
Copy link

@vercel vercel bot commented on e571135 Jun 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.