* feat(mobile): bring list and inbox back * navigate to list * inbox support * fix: query entries * use proxy image * fix list and inbox state * estimatedItemSize * update * update * update * fix list unread count * unread count component * update * fix unread count by view
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { eq } from "drizzle-orm"
|
|
|
|
import { db } from "../database"
|
|
import { listsTable } from "../database/schemas"
|
|
import type { ListSchema } from "../database/schemas/types"
|
|
import { listActions } from "../store/list/store"
|
|
import type { Hydratable, Resetable } from "./internal/base"
|
|
import { conflictUpdateAllExcept } from "./internal/utils"
|
|
|
|
class ListServiceStatic implements Hydratable, Resetable {
|
|
async reset() {
|
|
await db.delete(listsTable).execute()
|
|
}
|
|
async hydrate() {
|
|
const lists = await db.query.listsTable.findMany()
|
|
listActions.upsertManyInSession(
|
|
lists.map((list) => ({
|
|
...list,
|
|
feedIds: JSON.parse(list.feedIds || "[]") as string[],
|
|
})),
|
|
)
|
|
}
|
|
async upsertMany(lists: ListSchema[]) {
|
|
if (lists.length === 0) return
|
|
await db
|
|
.insert(listsTable)
|
|
.values(lists)
|
|
.onConflictDoUpdate({
|
|
target: [listsTable.id],
|
|
set: conflictUpdateAllExcept(listsTable, ["id"]),
|
|
})
|
|
}
|
|
|
|
async deleteList(params: { listId: string }) {
|
|
await db.delete(listsTable).where(eq(listsTable.id, params.listId))
|
|
}
|
|
}
|
|
|
|
export const ListService = new ListServiceStatic()
|