From ecaa088e4317cd1ff1b83249343375951e380a1d Mon Sep 17 00:00:00 2001 From: "Florine W. Dekker" Date: Wed, 23 Nov 2022 17:54:34 +0100 Subject: [PATCH] Store last value in local storage Fixes #10. --- package.json | 2 +- src/main/js/main.js | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9e7ac21..998a5ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "converter", - "version": "1.5.0", + "version": "1.5.1", "description": "Convert numbers to and from various bases.", "author": "Florine W. Dekker", "browser": "dist/bundle.js", diff --git a/src/main/js/main.js b/src/main/js/main.js index 01eb5cb..8c9cc38 100644 --- a/src/main/js/main.js +++ b/src/main/js/main.js @@ -2,9 +2,17 @@ const {$, doAfterLoad, stringToHtml} = window.fwdekker; // noinspection JSUnresolvedVariable const {clearInputValidity, showInputInvalid} = window.fwdekker.validation; +// noinspection JSUnresolvedVariable +const {LocalStorage} = window.fwdekker.storage; import bigInt from "big-integer"; +/** + * Interfaces with local storage. + */ +const storage = new LocalStorage("/tools/converter//config"); + + /** * Replaces the character at the given index with the given replacement. * @@ -370,6 +378,11 @@ class NumeralSystemInputWithToggleableSeparator extends NumeralSystemInput { } +/** + * @type {NumeralSystem} the decimal number system + */ +const decimalSystem = new NumeralSystem(10, "0123456789"); + /** * All the inputs to display. * @@ -378,7 +391,7 @@ class NumeralSystemInputWithToggleableSeparator extends NumeralSystemInput { const inputs = [ new NumeralSystemInput("Binary", new NumeralSystem(2, "01")), new NumeralSystemInput("Octal", new NumeralSystem(8, "01234567")), - new NumeralSystemInput("Decimal", new NumeralSystem(10, "0123456789")), + new NumeralSystemInput("Decimal", decimalSystem), new NumeralSystemInput("Duodecimal", new NumeralSystem(12, "0123456789ab")), new NumeralSystemInput("Hexadecimal", new NumeralSystem(16, "0123456789abcdef")), new Base64NumeralSystemInput("Base64"), @@ -399,6 +412,8 @@ const inputs = [ * @param newDecimalValues {bigInt[]} the decimal representation of the new value */ function updateAllInputs(source, newDecimalValues) { + storage.setArray("last-value", decimalSystem.decimalsToBases(newDecimalValues)); + for (const input of inputs) if (input !== source) input.setValues(newDecimalValues); @@ -410,6 +425,6 @@ doAfterLoad(() => { for (const input of inputs) input.addToParent(form); - updateAllInputs(undefined, [bigInt(42), bigInt(17)]); + updateAllInputs(undefined, decimalSystem.basesToDecimals(storage.getArray("last-value", [42, 17]))); inputs[0].textarea.focus(); });