feat(web): add IndexedDB storage for unauthenticated event operations #1410
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Unauthenticated users were unable to create or view events without OAuth, forcing immediate authentication. This adds local-first event storage using IndexedDB via Dexie, allowing full event CRUD before authentication.
Changes
Database layer (
compass-local.db.ts)_idSchema_GridEventtype, no new local-only typesstartDate,endDate,isSomeday,createdAtStorage utilities (
indexeddb.util.ts)saveEventToIndexedDB,getEventsFromIndexedDB,updateEventInIndexedDB,deleteEventFromIndexedDBAuth utilities (
auth.util.ts)isUserAuthenticated(): Check session validitygetUserId(): Returns actual ID or "local_user" placeholderSaga modifications
All event sagas now check auth status first:
Modified sagas:
createEvent,deleteEvent,editEvent,getEvents,getSomedayEvents,convertSomedayToCalendarEvent,convertCalendarToSomedayEvent,reorderSomedayEventsNotes
Original prompt
This section details on the original issue you should resolve
<issue_title>Save events to indexeddb if user hasn't authenticated their gcal</issue_title>
<issue_description>
Storage: IndexedDB structure for events & tasks
Overall goals
Implementation
1. Database & object stores
Database name:
compass-localInitial version:
1On
upgradeneeded, we’ll create two object stores:events– for pre-auth calendar events.tasks– for local tasks (used both pre-auth and post-auth unless/until we add a backend for tasks).Upgrade handler sketch:
2. Events store: reuse existing schema, override ID only
We will not introduce a new
LocalEventtype. Instead:Schema_Event/Schema_GridEvent) as the base._id(e.g. a UUID withlocal_evt_prefix).source/originflag if the existing schema already has such a field (e.g."local"vs"provider").Store
events_id(string; same property we already use to identify events)_idfor local events must be unique and never collide with provider IDs; recommended:local_evt_${uuid}.Record shape
Conceptually:
Here’s an updated, concrete plan you can paste into #1407. I’ll structure it as an “Implementation Plan” section that incorporates all your feedback.
Because the automation couldn’t modify the issue, you’ll need to update the issue text manually.
Implementation Plan (Updated)
1. Recommended Technology: Dexie.js for IndexedDB
Instead of using raw IndexedDB, use Dexie.js as the abstraction layer:
packages/web:yarn add dexie(anddexie-react-hooksif we wantuseLiveQuerylater).packages/web/src/common/db/compass.db.ts: