error recovery notification banner

This commit is contained in:
Martin McKeaveney 2020-03-30 21:14:41 +01:00
parent ab123aa098
commit 5d45797f3b
4 changed files with 93 additions and 2 deletions

View File

@ -6,12 +6,26 @@
import { onMount } from "svelte" import { onMount } from "svelte"
import IconButton from "./common/IconButton.svelte" import IconButton from "./common/IconButton.svelte"
import Spinner from "./common/Spinner.svelte" import Spinner from "./common/Spinner.svelte"
import AppNotification, { showAppNotification } from "./common/AppNotification.svelte"
let init = initialise() let init = initialise()
function showErrorBanner() {
showAppNotification({
status: "danger",
message:
"Whoops! Looks like we're having trouble. Please refresh the page.",
})
}
onMount(() => {
window.addEventListener("error", showErrorBanner)
window.addEventListener("unhandledrejection", showErrorBanner)
})
</script> </script>
<main> <main>
<AppNotification />
{#await init} {#await init}
<div class="spinner-container"> <div class="spinner-container">
<Spinner /> <Spinner />

View File

@ -5,6 +5,7 @@
import BackendRoot from "./BackendRoot.svelte" import BackendRoot from "./BackendRoot.svelte"
import { fade } from "svelte/transition" import { fade } from "svelte/transition"
import { SettingsIcon, PreviewIcon } from "./common/Icons/" import { SettingsIcon, PreviewIcon } from "./common/Icons/"
import { showAppNotification } from "./common/AppNotification.svelte"
const TABS = { const TABS = {
BACKEND: "backend", BACKEND: "backend",

View File

@ -44,7 +44,7 @@ export const getStore = () => {
currentNode: null, currentNode: null,
libraries: null, libraries: null,
showSettings: false, showSettings: false,
useAnalytics: true, useAnalytics: true
} }
const store = writable(initial) const store = writable(initial)

View File

@ -0,0 +1,76 @@
<script context="module">
import UIKit from "uikit"
export function showAppNotification({ message, status }) {
UIKit.notification({
message: `
<div class="message-container">
<i class="ri-information-fill information-icon"></i>
<span class="notification-message">
${message}
</span>
<button class="hoverable refresh-page-button" onclick="window.location.reload()">Refresh Page</button>
</div>
`,
status,
timeout: 100000
})
}
</script>
<style>
:global(.information-icon) {
font-size: 24px;
}
:global(.uk-nofi) {
display: grid;
grid-template-columns: 40px 1fr auto;
grid-gap: 5px;
align-items: center;
}
:global(.message-container) {
display: grid;
grid-template-columns: 40px 1fr auto;
grid-gap: 5px;
align-items: center;
}
:global(.uk-notification) {
width: 50% !important;
left: 0 !important;
right: 0 !important;
margin-right: auto !important;
margin-left: auto !important;
border-radius: 10px;
box-shadow: 0px 3px 6px #00000029;
}
:global(.uk-notification-message) {
border-radius: 5px;
}
:global(.uk-notification-message:hover .uk-notification-close) {
visibility: hidden;
}
:global(.uk-notification-message-danger) {
background: #f2545b !important;
color: #fff !important;
font-family: Roboto;
font-size: 14px !important;
}
:global(.refresh-page-button) {
font-size: 12px;
font-weight: 600;
border-radius: 5px;
border: none;
padding: 5px;
width: 91px;
height: 28px;
color: #f2545b;
background: #ffffff;
}
</style>