main^2
Midnight 2 years ago
parent abe617e599
commit a902b52095

@ -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 @@
<section class="container bg-slate-800 rounded-lg shadow-lg p-5 flex flex-col w-full gap-10">
<div class="flex flex-col lg:flex-row gap-5 lg:gap-1 flex-wrap -ml-2 -mr-2">
<span class="flex-grow"><Button added_classes="w-full" on:click={createNew}> Add Commission</Button></span>
<span><Button on:click={save}>💾 Save to Clipboard</Button></span>
<span><Button on:click={save_clipboard}>💾 Save to Clipboard</Button></span>
<span><Button on:click={load}>📋 Load from Clipboard</Button></span>
<span><Button on:click={clear}> Clear</Button></span>
</div>

Loading…
Cancel
Save