make toast non-async for better error messages

This commit is contained in:
Nolan Lawson 2018-01-14 23:36:44 -08:00
parent e3bb16b688
commit 234c21f249
3 changed files with 7 additions and 12 deletions

View file

@ -9,16 +9,11 @@ const importURLSearchParams = () => import(
}) })
}) })
const importToast = () => import(
/* webpackChunkName: 'toast' */ './toast'
).then(mod => mod.toast)
const importTimeline = () => import( const importTimeline = () => import(
/* webpackChunkName: 'Timeline' */ '../_components/Timeline.html' /* webpackChunkName: 'Timeline' */ '../_components/Timeline.html'
).then(mod => mod.default) ).then(mod => mod.default)
export { export {
importURLSearchParams, importURLSearchParams,
importToast,
importTimeline importTimeline
} }

View file

@ -96,7 +96,7 @@
import { themes } from '../../_static/themes' import { themes } from '../../_static/themes'
import { switchToTheme } from '../../_utils/themeEngine' import { switchToTheme } from '../../_utils/themeEngine'
import { goto } from 'sapper/runtime.js' import { goto } from 'sapper/runtime.js'
import { importToast } from '../../_utils/asyncModules' import { toast } from '../../_utils/toast'
export default { export default {
components: { components: {
@ -159,7 +159,7 @@
}) })
this.store.save() this.store.save()
switchToTheme(instanceThemes[newInstance] || 'default') switchToTheme(instanceThemes[newInstance] || 'default')
importToast().then(toast => toast.say(`Logged out of ${instanceName}`)) toast.say(`Logged out of ${instanceName}`)
goto('/settings/instances') goto('/settings/instances')
} }
} }

View file

@ -57,7 +57,7 @@
import { store } from '../../_utils/store' import { store } from '../../_utils/store'
import { goto } from 'sapper/runtime.js' import { goto } from 'sapper/runtime.js'
import { switchToTheme } from '../../_utils/themeEngine' import { switchToTheme } from '../../_utils/themeEngine'
import { importToast } from '../../_utils/asyncModules' import { toast } from '../../_utils/toast'
import LoadingMask from '../../_components/LoadingMask' import LoadingMask from '../../_components/LoadingMask'
const REDIRECT_URI = (typeof location !== 'undefined' ? const REDIRECT_URI = (typeof location !== 'undefined' ?
@ -90,8 +90,10 @@
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.error(err) console.error(err)
} }
const toast = await importToast() toast.say(`Error: ${err.message || err.name}. ` +
toast.say(`Error: ${err.message || err.name}. Is this a valid Mastodon instance?`) (navigator.onLine ?
`Is this a valid Mastodon instance?` :
`Are you offline?`))
} finally { } finally {
this.set({loading: false}) this.set({loading: false})
} }
@ -101,7 +103,6 @@
let loggedInInstances = this.store.get('loggedInInstances') let loggedInInstances = this.store.get('loggedInInstances')
instanceName = instanceName.replace(/^https?:\/\//, '').replace('/$', '') instanceName = instanceName.replace(/^https?:\/\//, '').replace('/$', '')
if (Object.keys(loggedInInstances).includes(instanceName)) { if (Object.keys(loggedInInstances).includes(instanceName)) {
const toast = await importToast()
toast.say(`You've already logged in to ${instanceName}`) toast.say(`You've already logged in to ${instanceName}`)
return return
} }
@ -123,7 +124,6 @@
this.set({loading: true}) this.set({loading: true})
await this.registerNewInstance(code) await this.registerNewInstance(code)
} catch (err) { } catch (err) {
const toast = await importToast()
toast.say(`Error: ${err.message || err.name}. Failed to connect to instance.`) toast.say(`Error: ${err.message || err.name}. Failed to connect to instance.`)
} finally { } finally {
this.set({loading: false}) this.set({loading: false})