From 234c21f2498926bae76ec2441f1ddb6f35f86bff Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 14 Jan 2018 23:36:44 -0800 Subject: [PATCH] make toast non-async for better error messages --- routes/_utils/asyncModules.js | 5 ----- routes/settings/instances/[instanceName].html | 4 ++-- routes/settings/instances/add.html | 10 +++++----- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/routes/_utils/asyncModules.js b/routes/_utils/asyncModules.js index c90e3b0d..8f1c7b79 100644 --- a/routes/_utils/asyncModules.js +++ b/routes/_utils/asyncModules.js @@ -9,16 +9,11 @@ const importURLSearchParams = () => import( }) }) -const importToast = () => import( - /* webpackChunkName: 'toast' */ './toast' - ).then(mod => mod.toast) - const importTimeline = () => import( /* webpackChunkName: 'Timeline' */ '../_components/Timeline.html' ).then(mod => mod.default) export { importURLSearchParams, - importToast, importTimeline } \ No newline at end of file diff --git a/routes/settings/instances/[instanceName].html b/routes/settings/instances/[instanceName].html index b9abc4e9..39ceeb1c 100644 --- a/routes/settings/instances/[instanceName].html +++ b/routes/settings/instances/[instanceName].html @@ -96,7 +96,7 @@ import { themes } from '../../_static/themes' import { switchToTheme } from '../../_utils/themeEngine' import { goto } from 'sapper/runtime.js' - import { importToast } from '../../_utils/asyncModules' + import { toast } from '../../_utils/toast' export default { components: { @@ -159,7 +159,7 @@ }) this.store.save() switchToTheme(instanceThemes[newInstance] || 'default') - importToast().then(toast => toast.say(`Logged out of ${instanceName}`)) + toast.say(`Logged out of ${instanceName}`) goto('/settings/instances') } } diff --git a/routes/settings/instances/add.html b/routes/settings/instances/add.html index 70b3edf4..afee8050 100644 --- a/routes/settings/instances/add.html +++ b/routes/settings/instances/add.html @@ -57,7 +57,7 @@ import { store } from '../../_utils/store' import { goto } from 'sapper/runtime.js' import { switchToTheme } from '../../_utils/themeEngine' - import { importToast } from '../../_utils/asyncModules' + import { toast } from '../../_utils/toast' import LoadingMask from '../../_components/LoadingMask' const REDIRECT_URI = (typeof location !== 'undefined' ? @@ -90,8 +90,10 @@ if (process.env.NODE_ENV !== 'production') { console.error(err) } - const toast = await importToast() - toast.say(`Error: ${err.message || err.name}. Is this a valid Mastodon instance?`) + toast.say(`Error: ${err.message || err.name}. ` + + (navigator.onLine ? + `Is this a valid Mastodon instance?` : + `Are you offline?`)) } finally { this.set({loading: false}) } @@ -101,7 +103,6 @@ let loggedInInstances = this.store.get('loggedInInstances') instanceName = instanceName.replace(/^https?:\/\//, '').replace('/$', '') if (Object.keys(loggedInInstances).includes(instanceName)) { - const toast = await importToast() toast.say(`You've already logged in to ${instanceName}`) return } @@ -123,7 +124,6 @@ this.set({loading: true}) await this.registerNewInstance(code) } catch (err) { - const toast = await importToast() toast.say(`Error: ${err.message || err.name}. Failed to connect to instance.`) } finally { this.set({loading: false})