From 306514fe1c9b721bb2a39312d95d71932149a25f Mon Sep 17 00:00:00 2001 From: midblep Date: Tue, 24 May 2022 19:56:31 +0200 Subject: [PATCH] shorten urls --- src/lib/calculator/Calculator.svelte | 30 ++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/lib/calculator/Calculator.svelte b/src/lib/calculator/Calculator.svelte index f3ad183..fde0830 100644 --- a/src/lib/calculator/Calculator.svelte +++ b/src/lib/calculator/Calculator.svelte @@ -21,12 +21,24 @@ let number: number; $: number = commissions.length + 1; - function setup() { + async function setup() { const urlParams = new URLSearchParams(window.location.search); urlParams.forEach((value, key) => { if(key == "commissions") { commissions = JSON.parse(value); - update_price(commissions[0]); + 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); + }); } }); if(commissions.length == 0) base(); @@ -79,8 +91,19 @@ } function save() { + let data = []; + commissions.forEach(value => { + data.push({ + "type": value['type'], + "name": value["name"], + "answers": value["answers"] + }) + }); + console.log(data); + console.log(JSON.stringify(data)); + const urlParams = new URLSearchParams(window.location.search); - urlParams.set("commissions", JSON.stringify(commissions)); + urlParams.set("commissions", JSON.stringify(data)); let url = window.location.origin + window.location.pathname + "?" + urlParams.toString(); @@ -100,7 +123,6 @@ }); update_price(commission); update_example(commission); - console.log(commission.answers); } function update_price(commission: Commission) {