Skip to content

Load chat and friend Alpine stores from IndexedDB with JSON fallback#1

Open
xylin-dev wants to merge 1 commit intomasterfrom
codex/organize-frontend-code-structure
Open

Load chat and friend Alpine stores from IndexedDB with JSON fallback#1
xylin-dev wants to merge 1 commit intomasterfrom
codex/organize-frontend-code-structure

Conversation

@xylin-dev
Copy link
Owner

Motivation

  • Persist and reuse conversation and friend data across page loads by reading from IndexedDB to avoid rebuilding state from server every time.
  • Provide a graceful fallback to existing inline JSON script state when IndexedDB is empty or a partial load is used.

Description

  • Added IndexedDB read helpers getFriendsFromDB, getChatsFromDB, and generic getObjectsFromDB in static/db.js to fetch stored records.
  • Introduced getJsonScriptData helper and updated loadFull to read JSON script tags (states/friends) and await persisting them with putFriendsToDB/putChatsToDB in static/stores.js.
  • Hydrate the chat store from IndexedDB via loadFromDB and add loadPartial which merges DB data with partial_states and persists partial states to IndexedDB.
  • Reworked the friend store to maintain both an iteration-friendly array friends and a lookup map friendMap, added loadFromDB and init to auto-hydrate on setup, and ensured both stores call init() when created.
  • Modified files: static/db.js and static/stores.js (see getFriendsFromDB, getChatsFromDB, getObjectsFromDB, getJsonScriptData, loadFromDB, loadPartial, store init changes).

Testing

  • No automated tests were executed for this change.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant