Skip to content

Commit

Permalink
Clean up keep item names before at the start of sync
Browse files Browse the repository at this point in the history
  • Loading branch information
jakst committed Dec 23, 2024
1 parent a569555 commit 99438f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/server/src/google-keep-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { trimAndUppercase } from "lib"

function cleanFromTrash(value: string) {
let res = value
if (value.startsWith("till ")) res = res.slice(5)
if (value.endsWith(" på")) res = res.slice(0, -3)
if (value.toLowerCase().startsWith("till ")) res = res.slice(5)
if (value.toLowerCase().endsWith(" på")) res = res.slice(0, -3)

return res
}
Expand Down Expand Up @@ -203,7 +203,6 @@ export class GoogleKeepBot {
return { list, listItems: sortedItems }
}

// TODO: Use this
async refreshList() {
const { listItems } = await this.#getItems()

Expand All @@ -216,6 +215,7 @@ export class GoogleKeepBot {
res = trimAndUppercase(res)

if (res !== initialText) {
console.log(`[KEEP] "${initialText}" was cleaned up and renamed to "${res}"`)
item.text = res
modifiedItems.push(item)
}
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export class TinyDO extends WsServerDurableObject<Env> {
if (newKeepList.lastChangedAt !== prevKeepStore.lastChangedAt) {
console.log("[KEEP] List changed. Syncing changes back to the shopping list...")

await keepBot.refreshList()

const oldIds = new Set(prevKeepStore.items.map((item) => item.id))
const newIds = new Set(newKeepList.items.map((item) => item.id))
const removedIds = oldIds.difference(newIds)
Expand Down

0 comments on commit 99438f3

Please sign in to comment.