Move spinner to its own file, and only mask the current view, not the whole window

This commit is contained in:
Tom Hubrecht 2022-07-28 14:16:52 +02:00
parent b7bf1f96a7
commit 8e5d9bb657
2 changed files with 41 additions and 21 deletions

View file

@ -1,7 +1,6 @@
<script> <script>
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
import FullCalendar from 'svelte-fullcalendar'; import FullCalendar from 'svelte-fullcalendar';
import { Circle2 } from 'svelte-loading-spinners';
import timeGridPlugin from '@fullcalendar/timegrid'; import timeGridPlugin from '@fullcalendar/timegrid';
import adaptivePlugin from '@fullcalendar/adaptive'; import adaptivePlugin from '@fullcalendar/adaptive';
import rrulePlugin from '@fullcalendar/rrule'; import rrulePlugin from '@fullcalendar/rrule';
@ -15,6 +14,7 @@
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import Help from './Help.svelte'; import Help from './Help.svelte';
import Share from './Share.svelte'; import Share from './Share.svelte';
import Spinner from './Spinner.svelte';
import 'bootstrap/dist/css/bootstrap.css'; import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap-icons/font/bootstrap-icons.css'; import 'bootstrap-icons/font/bootstrap-icons.css';
@ -69,6 +69,7 @@
}; };
let calendar; let calendar;
let spinner;
let options = writable({ let options = writable({
initialView: allowedViews.includes(view) initialView: allowedViews.includes(view)
@ -115,7 +116,12 @@
month: mobile ? 'numeric' : 'long', month: mobile ? 'numeric' : 'long',
day: 'numeric' day: 'numeric'
}, },
loading: b => (isLoading = b), loading: b => {
isLoading = b;
if (spinner) {
spinner.$set({ isLoading: b });
}
},
eventSources: [], eventSources: [],
themeSystem: 'bootstrap5', themeSystem: 'bootstrap5',
nextDayThreshold: '05:00:00', nextDayThreshold: '05:00:00',
@ -126,7 +132,14 @@
title: info.event.extendedProps.short_name, title: info.event.extendedProps.short_name,
placement: 'top' placement: 'top'
}); });
} },
viewDidMount: arg => {
spinner = new Spinner({
target: arg.el,
props: { isLoading: isLoading }
});
},
viewWillUnmount: _ => spinner.$destroy()
}); });
const flatten = d => { const flatten = d => {
@ -162,14 +175,6 @@
$: updateEvents(selectedCalendars); $: updateEvents(selectedCalendars);
</script> </script>
{#if isLoading}
<div class="load-spinner">
<div class="position-absolute top-50 start-50">
<Circle2 colorOuter="#e658ea" colorInner="#eaac3f" />
</div>
</div>
{/if}
<div class="h-100 d-flex flex-column"> <div class="h-100 d-flex flex-column">
<h1 class="mt-3 title text-center">Calendrier de la vie étudiante à l'ENS</h1> <h1 class="mt-3 title text-center">Calendrier de la vie étudiante à l'ENS</h1>
@ -184,16 +189,6 @@
</div> </div>
<style> <style>
.load-spinner {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.7);
z-index: 1044;
}
:global(.fs-7) { :global(.fs-7) {
font-size: 0.9rem !important; font-size: 0.9rem !important;
} }

25
src/Spinner.svelte Normal file
View file

@ -0,0 +1,25 @@
<script>
import { Circle2 } from 'svelte-loading-spinners';
export let isLoading = false;
</script>
{#if isLoading}
<div class="load-spinner">
<div class="position-absolute top-50 start-50">
<Circle2 colorOuter="#e658ea" colorInner="#eaac3f" />
</div>
</div>
{/if}
<style>
.load-spinner {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.6);
z-index: 50;
}
</style>