LocalStorage Data Management

Purpose

This subtopic addresses the need to persistently store, retrieve, and manage historical meeting data within the browser environment. While the parent topic, Persistent Meeting History, covers the broader functionality of storing and retrieving past meeting records, LocalStorage Data Management specifically abstracts and encapsulates all interactions with the browser's localStorage API. This abstraction ensures meeting data can be saved reliably, retrieved efficiently, and maintained within set constraints, such as limiting the number of stored records to prevent unbounded growth.

By centralizing localStorage operations behind a dedicated interface, the system gains improved maintainability, testability, and clarity in data persistence concerns, decoupling storage logic from meeting state management and UI rendering.

Functionality

The core responsibilities of this subtopic include:

The implementation is encapsulated in the Warehouse class, which acts as a façade over localStorage operations:

export default class Warehouse {
    local = false;
    defaultKey = 'meetings';

    constructor() {
        if (typeof (Storage) !== "undefined") {
            this.local = true;
        }
    }

    save(payload, key=this.defaultKey) {
        if (!this.local) return null;
        let pastMeetings = JSON.parse(this.load()) || [];
        pastMeetings.push(payload);
        if (pastMeetings.length > 10) pastMeetings.shift();
        return window.localStorage.setItem(key, JSON.stringify(pastMeetings));
    }

    load(key=this.defaultKey) {
        if (!this.local) return null;
        return window.localStorage.getItem(key);
    }

    remove(key=this.defaultKey) {
        if (!this.local) return null;
        return window.localStorage.removeItem(key);
    }

    clear() {
        if (!this.local) return null;
        return window.localStorage.clear();
    }
}

Key Workflows

This subtopic ensures reliability and limits on stored data, which prevents stale or excessive meeting records cluttering the browser storage.

Integration

LocalStorage Data Management integrates tightly with its parent topic, Persistent Meeting History, by serving as the underlying persistence layer. When a meeting completes in the Real-Time Meeting Cost Tracking module, the finalized meeting data is passed to the Warehouse instance for storage.

The stored data is later retrieved by the Historical Meeting Display subtopic, which formats and presents the saved records to the user in a readable table. The clear storage functionality, exposed via UI controls managed in User Interaction and Interface, invokes methods from this subtopic to erase historical data.

This separation allows the UI and display logic to focus on presentation without concern for storage mechanics, and the meeting lifecycle logic to remain clean and focused on cost/time tracking.

flowchart TD
UI[User Interface] -->|Save meeting data| Warehouse["Warehouse (LocalStorage Data Management)"]
Warehouse -->|Store meeting records| localStorage["(Browser localStorage)"]
Warehouse -->|Load meeting records| PastMeetings[Historical Meeting Display]
UI -->|Clear storage command| Warehouse

The diagram illustrates how UI actions trigger storage operations via the Warehouse, which abstracts direct localStorage interaction, coordinating data flow to and from persistent storage and the display components.


This focused data management layer is critical to maintaining a smooth user experience, ensuring that meeting histories persist across sessions without overloading browser storage or complicating other modules.