Store last value in local storage

Fixes #10.
This commit is contained in:
Florine W. Dekker 2022-11-23 17:54:34 +01:00
parent 1be17216b3
commit ecaa088e43
Signed by: FWDekker
GPG Key ID: D3DCFAA8A4560BE0
2 changed files with 18 additions and 3 deletions

View File

@ -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",

View File

@ -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();
});