Add id to wish counter

pull/1/head
I Made Setia Baruna 2020-11-02 21:02:08 +07:00
parent e6e5020b8f
commit e2360f799f
2 changed files with 8 additions and 6 deletions

View File

@ -5,19 +5,20 @@
import Button from '../../components/Button.svelte'; import Button from '../../components/Button.svelte';
import Icon from '../../components/Icon.svelte'; import Icon from '../../components/Icon.svelte';
export let id = '';
export let name = ''; export let name = '';
let total = 0; let total = 0;
let legendary = 0; let legendary = 0;
let rare = 0; let rare = 0;
$: id = `wish-counter-${name.toLowerCase().replace(/ /g, '-')}`; $: path = `wish-counter-${id}`;
onMount(() => { onMount(() => {
readLocalData(); readLocalData();
}); });
function readLocalData() { function readLocalData() {
const data = localStorage.getItem(id); const data = localStorage.getItem(path);
if (data !== null) { if (data !== null) {
const counterData = JSON.parse(data); const counterData = JSON.parse(data);
total = counterData.total; total = counterData.total;
@ -32,7 +33,7 @@
legendary, legendary,
rare, rare,
}); });
localStorage.setItem(id, data); localStorage.setItem(path, data);
} }
function add(val) { function add(val) {
@ -67,6 +68,7 @@
function getRare() { function getRare() {
total += 1; total += 1;
legendary += 1;
rare = 0; rare = 0;
saveData(); saveData();
} }

View File

@ -8,8 +8,8 @@
<div class="pt-20 lg:ml-64 lg:pt-8 p-8"> <div class="pt-20 lg:ml-64 lg:pt-8 p-8">
<h1 class="font-display font-black text-5xl text-white mb-2">Wish Counter</h1> <h1 class="font-display font-black text-5xl text-white mb-2">Wish Counter</h1>
<div class="grid gap-4 grid-cols-1 md:grid-cols-2 xl:grid-cols-3 max-w-screen-xl"> <div class="grid gap-4 grid-cols-1 md:grid-cols-2 xl:grid-cols-3 max-w-screen-xl">
<Counter name="Promotional Character" /> <Counter id="character-event" name="Character Event" />
<Counter name="Promotional Weapon" /> <Counter id="weapon-event" name="Weapon Event" />
<Counter name="Standard" /> <Counter id="standard" name="Standard" />
</div> </div>
</div> </div>