diff --git a/src/lib/calculator/Calculator.svelte b/src/lib/calculator/Calculator.svelte index 75bf12e..9ab7377 100644 --- a/src/lib/calculator/Calculator.svelte +++ b/src/lib/calculator/Calculator.svelte @@ -36,9 +36,6 @@ 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); }); @@ -114,10 +111,16 @@ let url = window.location.origin + window.location.pathname + "?" + urlParams.toString(); - navigator.clipboard.writeText(url); window.history.replaceState( {} , document.title, url); } + function save_clipboard() { + save(); + const urlParams = new URLSearchParams(window.location.search); + let url = window.location.origin + window.location.pathname + "?" + urlParams.toString(); + navigator.clipboard.writeText(url); + } + function update_commission_type(commission: Commission) { types.forEach(element => { if(element["name"] == commission.type) { @@ -155,7 +158,28 @@ } async function load() { - window.location.href = await navigator.clipboard.readText(); + let url = await navigator.clipboard.readText(); + window.history.replaceState( {} , document.title, url); + + const urlParams = new URLSearchParams(window.location.search); + urlParams.forEach((value, key) => { + if(key == "commissions") { + try { + commissions = JSON.parse(value); + commissions.forEach(value => { + types.forEach(element => { + if(element["name"] == value.type) { + value['questions'] = element["questions"]; + } + }); + update_price(value); + update_example(value); + }); + } catch(msg) { + error = "The selected preset link failed to load. It may be from an old version of the commission picker." + } + } + }); } function createNew() { @@ -183,6 +207,7 @@ function clear() { commissions = []; + total = 0; save(); } @@ -203,7 +228,7 @@
- +