feat: implement robust offline-first sync with Dexie.js
- Migrated to Dexie.js for IndexedDB management - Added optimistic UI for tasting notes with 'Wartet auf Sync' badge - Implemented background caching for tags and buddies - Unified scanning and tasting sync in a global UploadQueue
This commit is contained in:
57
src/lib/db.ts
Normal file
57
src/lib/db.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import Dexie, { type Table } from 'dexie';
|
||||
|
||||
export interface PendingScan {
|
||||
id?: number;
|
||||
imageBase64: string;
|
||||
timestamp: number;
|
||||
provider?: 'gemini' | 'nebius';
|
||||
}
|
||||
|
||||
export interface PendingTasting {
|
||||
id?: number;
|
||||
bottle_id: string;
|
||||
data: {
|
||||
session_id?: string;
|
||||
rating: number;
|
||||
nose_notes?: string;
|
||||
palate_notes?: string;
|
||||
finish_notes?: string;
|
||||
is_sample?: boolean;
|
||||
buddy_ids?: string[];
|
||||
tag_ids?: string[];
|
||||
};
|
||||
photo?: string; // Optional photo if taken during tasting
|
||||
tasted_at: string;
|
||||
}
|
||||
|
||||
export interface CachedTag {
|
||||
id: string;
|
||||
name: string;
|
||||
category: string;
|
||||
is_system_default: boolean;
|
||||
popularity_score: number;
|
||||
}
|
||||
|
||||
export interface CachedBuddy {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export class WhiskyDexie extends Dexie {
|
||||
pending_scans!: Table<PendingScan>;
|
||||
pending_tastings!: Table<PendingTasting>;
|
||||
cache_tags!: Table<CachedTag>;
|
||||
cache_buddies!: Table<CachedBuddy>;
|
||||
|
||||
constructor() {
|
||||
super('WhiskyVault');
|
||||
this.version(1).stores({
|
||||
pending_scans: '++id, timestamp',
|
||||
pending_tastings: '++id, bottle_id, tasted_at',
|
||||
cache_tags: 'id, category, name',
|
||||
cache_buddies: 'id, name'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const db = new WhiskyDexie();
|
||||
Reference in New Issue
Block a user