|
| 1 | +--- |
| 2 | +id: TASK-336.2 |
| 3 | +title: 'Frontend: complete tauriInvoke migration and extract small helpers' |
| 4 | +status: To Do |
| 5 | +assignee: [] |
| 6 | +created_date: '2026-04-29 04:20' |
| 7 | +labels: |
| 8 | + - refactor |
| 9 | + - frontend |
| 10 | + - complexity |
| 11 | +dependencies: [] |
| 12 | +references: |
| 13 | + - 'https://github.com/pythoninthegrass/mt/commit/4ba8be8' |
| 14 | +parent_task_id: TASK-336 |
| 15 | +priority: medium |
| 16 | +--- |
| 17 | + |
| 18 | +## Description |
| 19 | + |
| 20 | +<!-- SECTION:DESCRIPTION:BEGIN --> |
| 21 | +Closes the leak left by PR #44's `tauriInvoke` extraction: the helper exists in `app/frontend/js/api/shared.js` but several components still call `window.__TAURI__.core.invoke(...)` directly. Also extracts two more small helpers that have multiple inline copies. Estimated ~100 LOC reduction. |
| 22 | + |
| 23 | +**Scope:** |
| 24 | + |
| 25 | +1. **Replace direct `window.__TAURI__.core.invoke` with `tauriInvoke`** in 14 sites: |
| 26 | + - `app/frontend/js/components/settings-view.js` (9 sites near lines 195, 211, 229, 296, 312, 345, 379, 427, 943) |
| 27 | + - `app/frontend/js/components/metadata-modal.js` (3 sites: 204, 266, 393) |
| 28 | + - `app/frontend/js/components/stats-view.js` (1 site: 215) |
| 29 | + - `app/frontend/js/utils/library-operations.js` (1 site: 489) |
| 30 | + |
| 31 | +2. **Add `tauriConfirm(message, options)` to `app/frontend/js/api/shared.js`** wrapping `window.__TAURI__?.dialog?.confirm(...) ?? window.confirm(...)`. Replace the 5 inlined copies in: |
| 32 | + - `app/frontend/js/mixins/context-menu-actions.js` (~line 456) |
| 33 | + - `app/frontend/js/mixins/column-settings.js` (~line 218) |
| 34 | + - `app/frontend/js/mixins/playlist-crud.js` (~line 210) |
| 35 | + - `app/frontend/js/components/settings-view.js` (~lines 393, 798, 986) |
| 36 | + |
| 37 | +3. **Move the local `formatDuration` shorthand from `app/frontend/js/components/stats-view.js:170-179`** into `app/frontend/js/utils/formatting.js` as a new export `formatDurationShorthand` (returns "3d 2h" / "45m" style). Note: the existing `formatDuration` in `formatting.js` returns `MM:SS` and is **not** a drop-in replacement — keep both. |
| 38 | + |
| 39 | +**Files to modify:** |
| 40 | +- `app/frontend/js/api/shared.js` (add `tauriConfirm`) |
| 41 | +- `app/frontend/js/utils/formatting.js` (add `formatDurationShorthand`) |
| 42 | +- `app/frontend/js/components/settings-view.js` |
| 43 | +- `app/frontend/js/components/metadata-modal.js` |
| 44 | +- `app/frontend/js/components/stats-view.js` |
| 45 | +- `app/frontend/js/utils/library-operations.js` |
| 46 | +- `app/frontend/js/mixins/context-menu-actions.js` |
| 47 | +- `app/frontend/js/mixins/column-settings.js` |
| 48 | +- `app/frontend/js/mixins/playlist-crud.js` |
| 49 | +<!-- SECTION:DESCRIPTION:END --> |
| 50 | + |
| 51 | +## Acceptance Criteria |
| 52 | +<!-- AC:BEGIN --> |
| 53 | +- [ ] #1 No remaining direct calls to window.__TAURI__.core.invoke outside app/frontend/js/api/ |
| 54 | +- [ ] #2 tauriConfirm helper exists in api/shared.js and is used by all 5 previous inline confirm-dialog sites |
| 55 | +- [ ] #3 formatDurationShorthand exists in utils/formatting.js and is imported by stats-view.js; the local copy is removed |
| 56 | +- [ ] #4 deno lint and deno fmt --check pass |
| 57 | +- [ ] #5 cd app/frontend && npx vitest run passes |
| 58 | +- [ ] #6 cd app/frontend && npx playwright test --grep '@tauri' passes (or is skipped consistently with main) |
| 59 | +- [ ] #7 Manual smoke: open app, change settings, edit a track's metadata, view stats page, confirm a destructive action via context menu — no regressions |
| 60 | +<!-- AC:END --> |
0 commit comments