From 1e705db7c30acc603160480a64ea0084b5de0db3 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 2 Jul 2025 10:54:14 -0700 Subject: [PATCH] fixed audio context --- packages/http/src/routes/todos/[id].tsx | 2 +- packages/shared/src/kv.ts | 47 ------------------------- packages/shared/src/utils.ts | 3 +- packages/todo/src/todoCompletion.ts | 5 +-- packages/todo/src/todoKeymap.ts | 6 ++-- packages/todo/src/todoTimer.ts | 5 +-- 6 files changed, 12 insertions(+), 56 deletions(-) diff --git a/packages/http/src/routes/todos/[id].tsx b/packages/http/src/routes/todos/[id].tsx index 04b0572..31ce01d 100644 --- a/packages/http/src/routes/todos/[id].tsx +++ b/packages/http/src/routes/todos/[id].tsx @@ -1,7 +1,7 @@ import KV from "@workshop/shared/kv" import { submitAction, useAction, type Head, type LoaderProps } from "@workshop/nano-remix" -import { TodoEditor } from "@workshop/todo" import { useCallback } from "hono/jsx/dom" +import { TodoEditor } from "@workshop/todo" export const head: Head = { title: "Todos", diff --git a/packages/shared/src/kv.ts b/packages/shared/src/kv.ts index f516b82..c129662 100644 --- a/packages/shared/src/kv.ts +++ b/packages/shared/src/kv.ts @@ -99,53 +99,6 @@ const getStorePath = (key: T): string => { return join(kvDir, `${key}.v${version}.json`) } -// Migration function to convert from old kv.json to new individual files -const migrateFromOldFormat = async (): Promise => { - timeBomb("2025-07-01", "This migration isn't needed anymore. Delete it.") - - try { - const rootDir = process.env.DATA_DIR ?? join(import.meta.dir, "..") - const oldKvPath = join(rootDir, "data/kv.json") - const oldFile = Bun.file(oldKvPath) - - if (!(await oldFile.exists())) { - return // No old file to migrate - } - - console.log("Migrating from old kv.json format to new individual files...") - - const oldData = await oldFile.json() - const migrations: Promise[] = [] - - // Migrate each key from the old format - for (const [oldKey, value] of Object.entries(oldData)) { - const keyParts = oldKey.split(".") - const keyName = keyParts[0] as keyof Keys - - // Only migrate if it's a valid key we recognize and value exists - if (keyName in keyVersions && value !== undefined && value !== null) { - console.log(`Migrating key: ${keyName}`) - migrations.push(writeStore(keyName, value as Keys[typeof keyName])) - } - } - - await Promise.all(migrations) - - const backupPath = join(rootDir, "data/kv.json.backup") - await Bun.write(backupPath, await oldFile.text()) - await oldFile.delete() - - console.log("Migration completed successfully. Old file backed up as kv.json.backup") - } catch (error) { - console.error("Error during migration:", error) - } -} - -if (typeof process !== "undefined") { - // If this is running via bun, run the migration - await migrateFromOldFormat() -} - export default { set, get, remove, update } export type Conversation = { message: string; role: "user" | "assistant" } diff --git a/packages/shared/src/utils.ts b/packages/shared/src/utils.ts index a2e9b48..d293250 100644 --- a/packages/shared/src/utils.ts +++ b/packages/shared/src/utils.ts @@ -29,7 +29,8 @@ export const timeBomb = (date: string, message: string) => { const targetDate = DateTime.fromISO(date) if (now > targetDate) { - console.warn(`💣 Time bomb triggered: ${message}`) + const stack = new Error().stack + console.warn(`💣 Time bomb triggered: ${message}\n${stack}`) } } diff --git a/packages/todo/src/todoCompletion.ts b/packages/todo/src/todoCompletion.ts index 4dfed9d..dc0348b 100644 --- a/packages/todo/src/todoCompletion.ts +++ b/packages/todo/src/todoCompletion.ts @@ -1,13 +1,14 @@ import { RangeSetBuilder } from "@codemirror/state" import { Decoration, EditorView } from "@codemirror/view" -import { zzfx } from "zzfx" -export function triggerTodoCompletionEffect(view: EditorView, pos: number) { +export const triggerTodoCompletionEffect = async (view: EditorView, pos: number) => { const builder = new RangeSetBuilder() const line = view.state.doc.lineAt(pos) builder.add(pos, pos, Decoration.line({ class: "animate-completion" })) builder.finish() + // Only play sound in browser environment (not during SSR) + const { zzfx } = await import("zzfx") zzfx(...[0.8, , 617, 0.02, 0.03, 0.18, , 3, -0.1, , 358, 0.06, -0.01, , , , 0.02, 1.09, 0.05, 0.02, -1213]) // Pickup 58 - Mutation 5 } diff --git a/packages/todo/src/todoKeymap.ts b/packages/todo/src/todoKeymap.ts index 0215249..1917a36 100644 --- a/packages/todo/src/todoKeymap.ts +++ b/packages/todo/src/todoKeymap.ts @@ -14,7 +14,7 @@ export const buildKeyBindings = ( ): Command[] => [ { label: "Insert empty", - key: "alt-h", + key: "alt-l", preventDefault: true, run: (view: EditorView) => { // if the line is empty, insert a new todo item @@ -58,7 +58,7 @@ export const buildKeyBindings = ( }, { label: "Toggle the todo timer", - key: "alt-Enter", + key: "alt-k", preventDefault: true, run: (view: EditorView) => { const timerPlugin = view.plugin(todoTimer) @@ -71,7 +71,7 @@ export const buildKeyBindings = ( }, { label: "Move all done todos to # Done", - key: "alt-k", + key: "alt-,", preventDefault: true, run: (view: EditorView) => { moveToDone(view) diff --git a/packages/todo/src/todoTimer.ts b/packages/todo/src/todoTimer.ts index 5e6ca69..71e1ae9 100644 --- a/packages/todo/src/todoTimer.ts +++ b/packages/todo/src/todoTimer.ts @@ -1,7 +1,6 @@ import { EditorView, ViewPlugin, ViewUpdate, WidgetType, Decoration } from "@codemirror/view" import { RangeSetBuilder } from "@codemirror/state" import { Todo } from "@/todo" -import { zzfx } from "zzfx" class CountdownWidget extends WidgetType { duration: number @@ -52,7 +51,7 @@ class CountdownWidget extends WidgetType { this.toggleTimer() }) - const updateTimer = () => { + const updateTimer = async () => { if (this.startedAt) { span.classList.add("running") } else { @@ -72,6 +71,8 @@ class CountdownWidget extends WidgetType { span.classList.remove("running") span.classList.add("finished") this.stopTimer() + // Only play sound in browser environment (not during SSR) + const { zzfx } = await import("zzfx") zzfx(...[1.2, , 117, 0.03, 0.01, 0.12, , 2.1, , , , , , 1.3, , 0.3, 0.08, 0.6, 0.1, , 1946]) // Hit 107 this.showNotification() return