From e8064b0aff282985b93d24a97100c7bea7fcd68c Mon Sep 17 00:00:00 2001 From: Chris McCormick Date: Mon, 5 Jan 2026 15:14:31 +0800 Subject: [PATCH] Extract file operations into higher level abstraction. --- TODO.md | 2 +- index.html | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/TODO.md b/TODO.md index c0ce5d8..1fb623c 100644 --- a/TODO.md +++ b/TODO.md @@ -15,7 +15,6 @@ ## Refactor -- [ ] Extract file operations into higher-level abstraction - [ ] Simplify drop indicator logic - [ ] Consolidate menu creation (card menus and burger menu) - [ ] Extract line parsing logic - separate parsing from state management @@ -25,6 +24,7 @@ ## Done +- [x] Extract file operations into higher-level abstraction - [x] Consolidate modal logic into generic modal handler - [x] Warning colored note on home and about page if browser doesn't support FileSystem Access API. - [x] Ability to delete an item, with confirmation. diff --git a/index.html b/index.html index 1f671a2..8986cbb 100644 --- a/index.html +++ b/index.html @@ -1346,15 +1346,20 @@ chmod 755 kbtd return null; } - async function updateCardInFile(lineNumber, newTitle, newNestedContent, baseIndent) { - console.log('updateCardInFile:', lineNumber, newTitle, newNestedContent, baseIndent); + async function modifyCard(lineNumber, fn) { await modifyFileLines(lines => { const cardInfo = findCardByLineNumber(lineNumber); if (!cardInfo) { console.error('Could not find card with line number', lineNumber); return; } - + fn(lines, cardInfo); + }); + } + + async function updateCardInFile(lineNumber, newTitle, newNestedContent, baseIndent) { + console.log('updateCardInFile:', lineNumber, newTitle, newNestedContent, baseIndent); + await modifyCard(lineNumber, (lines, cardInfo) => { const card = cardInfo.card; const oldNestedLineCount = card.nestedLines.length; @@ -1371,13 +1376,7 @@ chmod 755 kbtd async function deleteCard(lineNumber) { console.log('deleteCard:', lineNumber); - await modifyFileLines(lines => { - const cardInfo = findCardByLineNumber(lineNumber); - if (!cardInfo) { - console.error('Could not find card with line number', lineNumber); - return; - } - + await modifyCard(lineNumber, (lines, cardInfo) => { const card = cardInfo.card; const nestedLineCount = card.nestedLines.length;