From 7ca2872422b6e9700907a114e6763cb12358eab7 Mon Sep 17 00:00:00 2001 From: Jessica Ho Date: Mon, 11 Sep 2023 04:30:36 +0000 Subject: [PATCH 1/9] mark all as busy --- src/routes/calendar/+page.svelte | 81 +++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/src/routes/calendar/+page.svelte b/src/routes/calendar/+page.svelte index 9c907c1..662b833 100644 --- a/src/routes/calendar/+page.svelte +++ b/src/routes/calendar/+page.svelte @@ -88,7 +88,7 @@ let timeErrs = new Set(); let schedDiffs: string[] = []; - async function markAs(i: number, status: string) { + async function markAs(i: number, status: string, updateUI = true) { const availRangeParts = status === AvailabilityStatus.AVAILABLE ? getAvailRangeParts(unsaved[i].availRange as string) @@ -150,34 +150,57 @@ endTime: endTime.toJSDate() }); if (response.status == 200) { - await invalidate('data:calendar'); - const { notes } = await response.json(); - let newAvailRange; - if (status === AvailabilityStatus.BUSY) newAvailRange = 'Busy'; - else if (status === AvailabilityStatus.UNSPECIFIED) newAvailRange = undefined; - else - newAvailRange = `${dateTo12Hour(startTime.toLocal())}-${dateTo12Hour(endTime.toLocal())}`; + if (updateUI) { + await invalidate('data:calendar'); + const { notes } = await response.json(); + let newAvailRange; + if (status === AvailabilityStatus.BUSY) newAvailRange = 'Busy'; + else if (status === AvailabilityStatus.UNSPECIFIED) newAvailRange = undefined; + else + newAvailRange = `${dateTo12Hour(startTime.toLocal())}-${dateTo12Hour(endTime.toLocal())}`; - rows[i] = { - ...rows[i], - notes, - availRange: newAvailRange, - emoticons: unsaved[i].emoticons, - ...availRangeParts - }; - unsaved[i] = { - ...unsaved[i], - notes, - availRange: status === AvailabilityStatus.AVAILABLE ? newAvailRange : '', - ...availRangeParts - }; - schedDiffs = generateDiffSchedule(ogRows, rows); - schedFull = generateFullSchedule(rows); + rows[i] = { + ...rows[i], + notes, + availRange: newAvailRange, + emoticons: unsaved[i].emoticons, + ...availRangeParts + }; + unsaved[i] = { + ...unsaved[i], + notes, + availRange: status === AvailabilityStatus.AVAILABLE ? newAvailRange : '', + ...availRangeParts + }; + schedDiffs = generateDiffSchedule(ogRows, rows); + schedFull = generateFullSchedule(rows); + } return 'ok'; - } else { - alert('Something went wrong with saving'); - return 'err'; } + + alert('Something went wrong with saving'); + return 'err'; + } + + async function markAllBusy() { + await Promise.all( + [...Array(rows.length).keys()].map((i) => markAs(i, AvailabilityStatus.BUSY, false)) + ); + // now update UI all at once + rows = rows.map((r) => ({ + ...r, + notes: '', + availRange: 'Busy', + emoticons: new Set() + })); + unsaved = unsaved.map((r) => ({ + ...r, + notes: '', + availRange: '', + emoticons: new Set() + })); + schedDiffs = generateDiffSchedule(ogRows, rows); + schedFull = generateFullSchedule(rows); } function toggleEmoticon(i: number, emoticon: string) { @@ -386,6 +409,9 @@ {/if} {/each} + {#key schedDiffs}

Notify Circle

Preview of your notification message(s)

@@ -595,7 +621,8 @@ .blue { background: #a0e3ff; } - .notif-btn { + .notif-btn, + .mark-all-busy-btn { padding: 0.2rem 1rem; border-radius: 17px; background: white; From db8138458cb5606467befabd4385d04bae3a5658 Mon Sep 17 00:00:00 2001 From: Jessica Ho Date: Mon, 11 Sep 2023 05:55:55 +0000 Subject: [PATCH 2/9] expired link msg --- src/hooks.server.ts | 2 +- src/routes/+page.server.ts | 2 +- src/routes/+page.svelte | 37 +++++++++++++++++++ .../login/[phone]/[token]/+page.server.ts | 6 +-- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 1d613e5..7ce03fe 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -103,7 +103,7 @@ export const handle = (async ({ event, resolve }) => { // } const cookie = event.cookies.get('session'); - console.log(event.url.pathname, cookie); + console.log(event.url.pathname); // check whether authenticated if ( event.url.pathname !== '/' && diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index f0089e1..2c32a35 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -4,5 +4,5 @@ import { redirect } from '@sveltejs/kit'; export const load = (async ({ cookies, url }) => { if (cookies.get('session')) throw redirect(307, '/dashboard'); - return { phone: url.searchParams.get('phone') }; + return { phone: url.searchParams.get('phone'), status: url.searchParams.get('status') }; }) satisfies PageServerLoad; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index a0e0b11..315113e 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -15,6 +15,8 @@ if (input && input.style) input.style.width = '100%'; } + let authErr = false; + let serverErr = false; onMount(() => { const input = document.querySelector('#phone'); phoneInput = intlTelInput(input, { @@ -24,6 +26,11 @@ stylePhoneInput(); }, 0); if (data.phone) phoneInput.telInput.value = data.phone; + if (data.status === '403') { + authErr = true; + } else if (data.status === '500') { + serverErr = true; + } }); async function login() { @@ -82,6 +89,25 @@
+ { + authErr = false; + serverErr = false; + }} + on:keyup={() => { + authErr = false; + serverErr = false; + }} + > + + {#if authErr} + Invalid / expired magic link + {:else if serverErr} + Something went wrong with logging in + {/if} +
@@ -260,6 +286,17 @@