Add error handler for gdrive

pull/1/head
I Made Setia Baruna 2021-01-09 15:29:26 +08:00
parent a714eeabe4
commit 0e94c1533c
3 changed files with 21 additions and 2 deletions

View File

@ -3,7 +3,7 @@
import dayjs from 'dayjs';
import { onMount, getContext, setContext } from 'svelte';
import { driveSignedIn, driveLoading, saveId, synced } from '../stores/dataSync';
import { driveSignedIn, driveError, driveLoading, saveId, synced } from '../stores/dataSync';
import { getLocalSaveJson, updateSave, updateTime, UPDATE_TIME_KEY } from '../stores/saveManager';
import SyncConflictModal from '../components/SyncConflictModal.svelte';
@ -31,10 +31,19 @@
synced.set(false);
const script = document.createElement('script');
script.onload = handleClientLoad;
script.onerror = handleError;
script.src = 'https://apis.google.com/js/api.js';
document.body.appendChild(script);
}
function handleError() {
console.log('error loading google drive api');
driveSignedIn.set(false);
driveLoading.set(false);
driveError.set(true);
synced.set(true);
}
function handleClientLoad() {
gapi.load('client:auth2', initClient);
}
@ -212,6 +221,10 @@
},
function (error) {
console.error(error);
driveSignedIn.set(false);
driveLoading.set(false);
driveError.set(true);
synced.set(true);
},
);
}

View File

@ -6,7 +6,7 @@
import Icon from '../components/Icon.svelte';
import Select from '../components/Select.svelte';
import { driveSignedIn, driveLoading, synced, localModified, lastSyncTime } from '../stores/dataSync';
import { driveSignedIn, driveError, driveLoading, synced, localModified, lastSyncTime } from '../stores/dataSync';
import { server } from '../stores/server';
const servers = [
@ -63,6 +63,11 @@
<p class="text-white mb-4">Paimon.moe can only read and write file that this site create.</p>
{#if $driveLoading}
<Icon path={mdiLoading} color="white" spin />
{:else if $driveError}
<Button color="red">
<Icon path={mdiGoogleDrive} className="mr-2" />
Google Drive API cannot be loaded
</Button>
{:else if !$driveSignedIn}
<Button on:click={signIn}>
<Icon path={mdiGoogleDrive} className="mr-2" />

View File

@ -2,6 +2,7 @@ import { writable } from 'svelte/store';
export const driveSignedIn = writable(false);
export const driveLoading = writable(true);
export const driveError = writable(false);
export const lastSyncTime = writable(null);
export const localModified = writable(false);
export const synced = writable(false);