From 6eef67d5daab3aeb9be4cc5c7f3c98879e10d7ff Mon Sep 17 00:00:00 2001 From: fadhlu Date: Fri, 19 Mar 2021 13:44:04 +0700 Subject: [PATCH] Add desired resin input --- src/locales/en.json | 8 ++++-- src/locales/id.json | 8 ++++-- src/routes/calculator/_resin.svelte | 41 ++++++++++++++++++++++------- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index d204a47b..e3f36dc5 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -206,11 +206,15 @@ "mora": "Mora Cost" }, "resin": { - "inputCurrentResin": "Input Current Resin...", + "currentResin": "Current Resin", + "desiredResin": "Desired Resin", + "or": "or", + "inputCurrentResin": "Input current resin...", + "inputDesireResin": "Input how many resin you want to wait...", "timeFormat": "en", "calculate": "Calculate", "currentTime": "Current Time", - "fullTime": "Resin Will Be Replenished At" + "fullTime": "Will be replenished at" } }, "items": { diff --git a/src/locales/id.json b/src/locales/id.json index 6e549827..999b3dad 100644 --- a/src/locales/id.json +++ b/src/locales/id.json @@ -206,11 +206,15 @@ "mora": "Jumlah Mora" }, "resin": { - "inputCurrentResin": "Masukkan Jumlah Resin Sekarang...", + "currentResin": "Resin Saat Ini", + "desiredResin": "Resin Yang Diinginkan", + "or": "atau", + "inputCurrentResin": "Masukkan jumlah resin sekarang...", + "inputDesireResin": "Masukkan jumlah resin yang diinginkan...", "timeFormat": "id", "calculate": "Hitung", "currentTime": "Waktu Sekarang", - "fullTime": "Resin Akan Penuh Pada" + "fullTime": "Akan terisi pada" } }, "items": { diff --git a/src/routes/calculator/_resin.svelte b/src/routes/calculator/_resin.svelte index fddf1bb3..bdac34f9 100644 --- a/src/routes/calculator/_resin.svelte +++ b/src/routes/calculator/_resin.svelte @@ -9,10 +9,14 @@ let changed = false; let currentResin = ''; + let desiredResin = ''; let maxResin = 160; let millisecondsToWait; let fullTime = null; let missingResin = 160; + let showResult = false; + let resinTypeOutput = ''; + let resinOutput = ''; let originalResin = { id: 'original_resin', @@ -21,7 +25,7 @@ value: 8, }; - // 8 menit per resin * 60 seconds * 1000 millisec + // 8 minute per resin * 60 seconds * 1000 millisec let minutePerResin = originalResin.value * 60 * 1000; let dateTimeOptions = { @@ -31,33 +35,50 @@ weekday: 'long', }; - $: canCalculate = currentResin !== '' && currentResin >= 0 && currentResin < 160; + $: isCurrentResin = currentResin >= 0 && currentResin < 160 && currentResin !== ''; + $: isDesiredResin = desiredResin <= 160 && desiredResin >= 1 && desiredResin === ''; + $: canCalculate = isCurrentResin || isDesiredResin; function calculate() { missingResin = maxResin - currentResin; - millisecondsToWait = missingResin * minutePerResin; + resinOutput = resinTypeOutput === 'maxResin' ? missingResin : desiredResin; + millisecondsToWait = resinTypeOutput === 'maxResin' ? missingResin * minutePerResin : desiredResin * minutePerResin; fullTime = new Date($time.getTime() + millisecondsToWait); + showResult = true; } - function onChange() { + function onChange(type) { changed = true; + showResult = false; + resinTypeOutput = type; }
-
+
+

+ {$t('calculator.resin.currentResin')} +

onChange('maxResin')} type="number" min={0} max={160} bind:value={currentResin} placeholder={$t('calculator.resin.inputCurrentResin')} /> -

+

{$t('calculator.resin.or')} {$t('calculator.resin.desiredResin')}

+ onChange('desiredResin')} + type="number" + min={1} + max={160} + bind:value={desiredResin} + placeholder={$t('calculator.resin.inputDesireResin')} + /> +

{$t('calculator.resin.currentTime')}: {new Intl.DateTimeFormat( $t('calculator.resin.timeFormat'), dateTimeOptions, @@ -68,12 +89,12 @@ - {#if fullTime} + {#if showResult}

{missingResin} + >{resinOutput}