From 7e18aa300358e6af311a0e0ec599f563336d5c74 Mon Sep 17 00:00:00 2001 From: midblep Date: Tue, 24 May 2022 20:09:40 +0200 Subject: [PATCH] error msg --- src/lib/calculator/Calculator.svelte | 41 ++++++++++++++++++---------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/lib/calculator/Calculator.svelte b/src/lib/calculator/Calculator.svelte index fde0830..60edd09 100644 --- a/src/lib/calculator/Calculator.svelte +++ b/src/lib/calculator/Calculator.svelte @@ -4,6 +4,7 @@ import words from "$lib/en-lang.json"; let total = 0; + let error = null; let lang = words["calculator"]; let types = lang["types"]; @@ -25,23 +26,29 @@ const urlParams = new URLSearchParams(window.location.search); urlParams.forEach((value, key) => { if(key == "commissions") { - commissions = JSON.parse(value); - commissions.forEach(value => { - types.forEach(element => { - if(element["name"] == value.type) { - value['questions'] = element["questions"]; - } + try { + commissions = JSON.parse(value); + commissions.forEach(value => { + types.forEach(element => { + if(element["name"] == value.type) { + value['questions'] = element["questions"]; + } + }); + value.questions.forEach(question => { + value['answers'].push({'name': question.name, 'option': question.options[0]['name']}); + }); + update_price(value); + update_example(value); + console.log(value.example); }); - value.questions.forEach(question => { - value['answers'].push({'name': question.name, 'option': question.options[0]['name']}); - }); - update_price(value); - update_example(value); - console.log(value.example); - }); + } catch(msg) { + error = "The selected preset link failed to load. It may be from an old version of the commission picker. It has been replaced with the default preset below." + } } }); - if(commissions.length == 0) base(); + if(commissions.length == 0) { + base(); + } } function update_example(commission: Commission) { @@ -200,6 +207,12 @@ + {#if error} +
+ ⚠️ {error} +
+ {/if} + {#each [...commissions].reverse() as commission}