Skip to content

Commit

Permalink
🗑️ Remove references to important list
Browse files Browse the repository at this point in the history
  • Loading branch information
homostellaris committed Nov 6, 2024
1 parent 281f00e commit d511117
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
14 changes: 8 additions & 6 deletions components/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ export interface Icon {
name: string
}

export interface List {
order: string[] // Todo IDs
type: '#important'
}

export enum ListType {
wayfinder,
icebox,
Expand All @@ -43,7 +38,6 @@ export interface Setting {

export class DexieStarfocus extends Dexie {
wayfinderOrder!: DexieCloudTable<{ todoId: string; order: string }, 'todoId'>
lists!: Table<List>
settings!: DexieCloudTable<Setting, 'key'>
starRoles: DexieCloudTable<StarRole, 'id'>
starRolesOrder!: DexieCloudTable<
Expand Down Expand Up @@ -80,6 +74,14 @@ export class DexieStarfocus extends Dexie {
starRolesOrder: '&starRoleId, &order',
todos: '@id, createdAt, completedAt, starRole, title',
})
this.version(5).stores({
lists: null,
wayfinderOrder: '&todoId, &order',
settings: '&key',
starRoles: '@id, title',
starRolesOrder: '&starRoleId, &order',
todos: '@id, createdAt, completedAt, starRole, title',
})
this.cloud.configure({
databaseUrl: process.env.NEXT_PUBLIC_DATABASE_URL!,
requireAuth: false,
Expand Down
24 changes: 0 additions & 24 deletions components/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,30 +336,6 @@ export const MiscMenu = () => {

// Remove empty todos
await db.todos.where('title').equals('').delete()

// Remove todos from important list that don't exist
const important = await db.lists.get('#important')
const todos = await db.todos.bulkGet(important?.order || [])
const cleanedImportantOrder = _.zip(important!.order, todos)
.filter(([_id, todo]) => todo !== undefined)
.map(([id, _todo]) => id) as string[]
await db.lists.update('#important', {
order: cleanedImportantOrder,
})

// Migrate to new important order
const wayfinderOrder = await db.wayfinderOrder
.orderBy('order')
.keys()
if (wayfinderOrder.length === 0) {
const oldOrder = await db.lists.get('#important')
const orderKeys = starMudder(oldOrder?.order.length)
const records = oldOrder?.order.map(todoId => ({
todoId,
order: orderKeys.shift(),
}))
db.wayfinderOrder.bulkAdd(records as any)
}
}}
>
Clean database
Expand Down

0 comments on commit d511117

Please sign in to comment.