0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-06 23:02:45 +00:00

Add getHistoryItems function

This commit is contained in:
G.Ambatte
2024-09-14 21:20:31 +12:00
parent 48eb42862a
commit d01548feb6
3 changed files with 72 additions and 14 deletions

View File

@@ -1,4 +1,5 @@
export const HISTORY_PREFIX = 'HOMEBREWERY-HISTORY';
export const HISTORY_SLOTS = 5;
// const HISTORY_SAVE_DELAYS = {
// 0: 0, // 0 minutes (if not specified)
// 1: 2, // 2 minutes
@@ -68,16 +69,29 @@ function updateStoredBrew(brew, slot=0){
return;
};
export function updateHistory(brew) {
export function historyExists(brew){
return Object.keys(localStorage)
.some((key)=>{
return key.startsWith(`${HISTORY_PREFIX}-${brew.shareId}`);
});
}
export function loadHistory(brew){
const history = {};
// Load data from local storage to History object
for (let i = 1; i<=5; i++){
for (let i = 1; i <= HISTORY_SLOTS; i++){
history[i] = getVersionBySlot(brew, i);
};
return history;
}
export function updateHistory(brew) {
const history = loadHistory(brew);
// Walk each version position
for (let slot = 5; slot>0; slot--){
for (let slot = HISTORY_SLOTS; slot > 0; slot--){
const storedVersion = history[slot];
// If slot has expired, update all lower slots and break
@@ -96,6 +110,16 @@ export function updateHistory(brew) {
};
};
export function getHistoryItems(brew){
const historyArray = [];
for (let i = 1; i <= HISTORY_SLOTS; i++){
historyArray.push(getVersionBySlot(brew, i));
}
return historyArray;
};
export function versionHistoryGarbageCollection(){
Object.keys(localStorage)
.filter((key)=>{