diff --git a/src/lib/calculator/Calculator.svelte b/src/lib/calculator/Calculator.svelte index 75bf12e..e3257a4 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) { @@ -135,12 +138,14 @@ function update_price(commission: Commission) { commission.price = 0; + console.log(commission.answers); for (let index = 0; index < commission.answers.length; index++) { const answer = commission.answers[index]; const question = commission.questions.filter(value => { return value['name'] == answer['name']; })[0]; + console.log(commission.price); question['options'].forEach(value => { if(value['name'] == answer['option']) { commission.price += value['price']; @@ -149,13 +154,35 @@ } total = 0; + // console.log(commissions); commissions.forEach(value => { total += value.price; }) } 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 +210,7 @@ function clear() { commissions = []; + total = 0; save(); } @@ -203,7 +231,7 @@
- +