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(
/* webpackChunkName: 'Timeline' */ '../_components/Timeline.html'
).then(mod => mod.default)
export {
importURLSearchParams,
importToast,
importTimeline
}

View File

@ -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')
}
}

View File

@ -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})