diff options
| author | Maze <167211895+mazeincoding@users.noreply.github.com> | 2026-01-31 00:20:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-31 00:20:04 +0100 |
| commit | 7bf0984698e43b9aa2dd879f65951318ed410390 (patch) | |
| tree | ccf2cd590a47d550152afc07129cb55c71a9ec35 /apps/web/src/stores/keybindings | |
| parent | 0173db99448d1c4c6415dcf15272e17551b48b04 (diff) | |
| download | opencut-7bf0984698e43b9aa2dd879f65951318ed410390.tar.gz | |
codebase overhaul (#697)
Diffstat (limited to 'apps/web/src/stores/keybindings')
| -rw-r--r-- | apps/web/src/stores/keybindings/migrations/index.ts | 28 | ||||
| -rw-r--r-- | apps/web/src/stores/keybindings/migrations/v2-to-v3.ts | 26 |
2 files changed, 54 insertions, 0 deletions
diff --git a/apps/web/src/stores/keybindings/migrations/index.ts b/apps/web/src/stores/keybindings/migrations/index.ts new file mode 100644 index 00000000..1689802e --- /dev/null +++ b/apps/web/src/stores/keybindings/migrations/index.ts @@ -0,0 +1,28 @@ +import { v2ToV3 } from './v2-to-v3'; + +type MigrationFn = ({ state }: { state: unknown }) => unknown; + +/** + * key = version we're migrating from + * value = migration function + */ +const migrations: Record<number, MigrationFn> = { + 2: v2ToV3, +}; + +export const CURRENT_VERSION = 3; + +export function runMigrations({ + state, + fromVersion, +}: { + state: unknown; + fromVersion: number; +}): unknown { + let current = state; + for (let version = fromVersion; version < CURRENT_VERSION; version++) { + const migrate = migrations[version]; + if (migrate) current = migrate({ state: current }); + } + return current; +} diff --git a/apps/web/src/stores/keybindings/migrations/v2-to-v3.ts b/apps/web/src/stores/keybindings/migrations/v2-to-v3.ts new file mode 100644 index 00000000..1517b52b --- /dev/null +++ b/apps/web/src/stores/keybindings/migrations/v2-to-v3.ts @@ -0,0 +1,26 @@ +import type { KeybindingConfig, ShortcutKey } from "@/types/keybinding"; +import type { TActionWithOptionalArgs } from "@/lib/actions"; + +interface V2State { + keybindings: KeybindingConfig; + isCustomized: boolean; +} + +export function v2ToV3({ state }: { state: unknown }): unknown { + const v2 = state as V2State; + + const renames: Record<string, string> = { + "split-selected": "split", + "split-selected-left": "split-left", + "split-selected-right": "split-right", + }; + + const migrated = { ...v2.keybindings }; + for (const [key, action] of Object.entries(migrated)) { + if (action && renames[action]) { + migrated[key as ShortcutKey] = renames[action] as TActionWithOptionalArgs; + } + } + + return { ...v2, keybindings: migrated }; +} |
