diff --git a/src/lib/Drink.svelte b/src/lib/Drink.svelte index c74a4d4..da96b97 100644 --- a/src/lib/Drink.svelte +++ b/src/lib/Drink.svelte @@ -9,9 +9,17 @@ let amountBottles: number; const saveInventory = () => { + // If there is not a timestamp entry yet, create one. + if ( !$inventory.some(item => "timestamp" in item)) { + let _unixTime = Date.now(); + let _date = new Date(_unixTime).toLocaleDateString(); + let _time = new Date(_unixTime).toLocaleTimeString(); + $inventory = [{ + timestamp: _date + " um " + _time + }, ...$inventory]; + } // Check if a drink is already in the inventory. If yes, then update the amounts. If not, add it. if ($inventory.some(item => item.name === drinkName)) { - // Potentially inefficient, how to refactor forEach? $inventory.forEach(item => { if (drinkName === item.name) { item.amountContainers = amountContainers; diff --git a/src/lib/Finish.svelte b/src/lib/Finish.svelte index a513c2a..cb76601 100644 --- a/src/lib/Finish.svelte +++ b/src/lib/Finish.svelte @@ -1,21 +1,26 @@