mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 10:24:05 +00:00
21 lines
616 B
TypeScript
21 lines
616 B
TypeScript
import { todoApi } from '../api/client'
|
|
import { offlineDb, upsertTodoItems } from '../db/offlineDb'
|
|
import { onlineThenCache } from './withOfflineFallback'
|
|
import type { TodoItem } from '../types'
|
|
|
|
export const todoRepo = {
|
|
async list(tripId: number | string): Promise<{ items: TodoItem[] }> {
|
|
return onlineThenCache(
|
|
async () => {
|
|
const result = await todoApi.list(tripId)
|
|
void upsertTodoItems(result.items)
|
|
return result
|
|
},
|
|
async () => ({
|
|
items: await offlineDb.todoItems
|
|
.where('trip_id').equals(Number(tripId)).toArray(),
|
|
}),
|
|
)
|
|
},
|
|
}
|