forked from MapComplete/MapComplete
Refactoring: move error logic into svelte component
This commit is contained in:
parent
06c096b21a
commit
9b27961d90
2 changed files with 42 additions and 24 deletions
31
src/UI/CustomThemeError.svelte
Normal file
31
src/UI/CustomThemeError.svelte
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import ArrowDownTray from "@babeard/svelte-heroicons/mini/ArrowDownTray"
|
||||||
|
import { Utils } from "../Utils"
|
||||||
|
|
||||||
|
export let customDefinition: string
|
||||||
|
export let stack: string[]
|
||||||
|
|
||||||
|
function offerDefinitionForDownload() {
|
||||||
|
Utils.offerContentsAsDownloadableFile(
|
||||||
|
customDefinition,
|
||||||
|
"mapcomplete-theme.json",
|
||||||
|
{ mimetype: "application/json" }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex flex-col w-full h-full m-8 justify-center items-center">
|
||||||
|
|
||||||
|
<h1>Something went wrong</h1>
|
||||||
|
<div class="alert">{stack[0]}</div>
|
||||||
|
{#each stack.slice(1) as stck}
|
||||||
|
<div>{stck}</div>
|
||||||
|
{/each}
|
||||||
|
{#if customDefinition}
|
||||||
|
<button on:click={() => offerDefinitionForDownload()}>
|
||||||
|
<ArrowDownTray class="w-16 h-16" />
|
||||||
|
Download the theme definition file
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
35
src/index.ts
35
src/index.ts
|
@ -1,19 +1,13 @@
|
||||||
import DetermineTheme from "./Logic/DetermineTheme"
|
import DetermineTheme from "./Logic/DetermineTheme"
|
||||||
import SvelteUIElement from "./UI/Base/SvelteUIElement"
|
|
||||||
import { FixedUiElement } from "./UI/Base/FixedUiElement"
|
|
||||||
import Combine from "./UI/Base/Combine"
|
|
||||||
import { SubtleButton } from "./UI/Base/SubtleButton"
|
|
||||||
import { Utils } from "./Utils"
|
|
||||||
import ArrowDownTray from "@babeard/svelte-heroicons/mini/ArrowDownTray"
|
|
||||||
import SingleThemeGui from "./UI/SingleThemeGui.svelte"
|
import SingleThemeGui from "./UI/SingleThemeGui.svelte"
|
||||||
|
import CustomThemeError from "./UI/CustomThemeError.svelte"
|
||||||
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
const target = document.getElementById("maindiv")
|
||||||
|
const childs = Array.from(target.children)
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const theme = await DetermineTheme.getTheme()
|
const theme = await DetermineTheme.getTheme()
|
||||||
const target = document.getElementById("maindiv")
|
|
||||||
const childs = Array.from(target.children)
|
|
||||||
new SingleThemeGui({
|
new SingleThemeGui({
|
||||||
target,
|
target,
|
||||||
props: { theme }
|
props: { theme }
|
||||||
|
@ -25,22 +19,15 @@ async function main() {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error while initializing: ", err, err.stack)
|
console.error("Error while initializing: ", err, err.stack)
|
||||||
const customDefinition = DetermineTheme.getCustomDefinition()
|
const customDefinition = DetermineTheme.getCustomDefinition()
|
||||||
new Combine([
|
|
||||||
new FixedUiElement(err.toString().split("\n").join("<br/>")).SetClass("block alert"),
|
|
||||||
|
|
||||||
customDefinition?.length > 0
|
new CustomThemeError({
|
||||||
? new SubtleButton(
|
target,
|
||||||
new SvelteUIElement(ArrowDownTray),
|
props: {
|
||||||
"Download the raw file"
|
stack: err.toString().split("\n"),
|
||||||
).onClick(() =>
|
customDefinition
|
||||||
Utils.offerContentsAsDownloadableFile(
|
}
|
||||||
DetermineTheme.getCustomDefinition(),
|
})
|
||||||
"mapcomplete-theme.json",
|
|
||||||
{ mimetype: "application/json" }
|
|
||||||
)
|
|
||||||
)
|
|
||||||
: undefined,
|
|
||||||
]).AttachTo("maindiv")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue