From 8dff9ca9192aad7f02fe60cffe4a191ced99be68 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sun, 13 Mar 2022 01:59:11 +0100 Subject: [PATCH 01/79] Add pre-selection of calendars --- src/App.svelte | 22 ++++++++++++++++++++-- src/FilterBar.svelte | 9 ++++++--- src/FilterItem.svelte | 14 +++++++++++--- src/calendar.js | 21 ++++++++++++++++++++- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 9c8bb16..40f17cf 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -10,7 +10,7 @@ import frLocale from '@fullcalendar/core/locales/fr'; import EventModal from './EventModal.svelte'; import FilterBar from './FilterBar.svelte'; - import { mkSource, calendarTree } from './calendar'; + import { mkSource, calendarTree, initialCalendars, getSubCalendars } from './calendar'; import { debounce } from 'lodash'; import Help from './Help.svelte'; @@ -30,6 +30,8 @@ return time.toLocaleTimeString(); })(); + const params = new URL(document.location).searchParams.getAll('c'); + let calendar; let options = writable({ @@ -71,7 +73,23 @@ progressiveEventRendering: true }); + const flatten = d => { + let array = []; + if (Array.isArray(d)) { + d.forEach(a => (array = array.concat(flatten(a)))); + } else { + for (const [n, s] of Object.entries(d)) { + array = array.concat(n, flatten(s)); + } + } + return array; + }; + let selectedCalendars = []; + const initial = + params.length > 0 + ? flatten(params.map(cal => getSubCalendars(cal))).concat(params) + : initialCalendars; const updateEvents = debounce(calendars => { options.update(opts => ({ @@ -88,7 +106,7 @@ - + diff --git a/src/FilterBar.svelte b/src/FilterBar.svelte index 5b10482..80df604 100644 --- a/src/FilterBar.svelte +++ b/src/FilterBar.svelte @@ -5,15 +5,17 @@ export let calendarTree = []; export let selected = null; + export let initial = []; let open = false; + let icon; let generalToggle = writable(true); const toggle = () => (open = !open); - $: icon = () => ($generalToggle ? 'toggle-on' : 'toggle-off'); - let subSelections = Array.from({ length: Object.keys(calendarTree).length }, _ => []); $: selected = subSelections.flat(); + + generalToggle.subscribe(v => (icon = v ? 'toggle-on' : 'toggle-off'));