Refactor IndexedDb boilerplate.
This commit is contained in:
parent
2e6cd66f56
commit
c3d93998d1
2 changed files with 12 additions and 29 deletions
2
TODO.md
2
TODO.md
|
|
@ -17,12 +17,12 @@
|
||||||
|
|
||||||
- [ ] Consolidate menu creation (card menus and burger menu)
|
- [ ] Consolidate menu creation (card menus and burger menu)
|
||||||
- [ ] Extract line parsing logic - separate parsing from state management
|
- [ ] Extract line parsing logic - separate parsing from state management
|
||||||
- [ ] Reduce IndexedDB boilerplate with generic DB operation wrapper
|
|
||||||
- [ ] Make createAddForm more generic to handle both columns and cards
|
- [ ] Make createAddForm more generic to handle both columns and cards
|
||||||
- [ ] Extract and consolidate indent detection functions
|
- [ ] Extract and consolidate indent detection functions
|
||||||
|
|
||||||
## Done
|
## Done
|
||||||
|
|
||||||
|
- [x] Reduce IndexedDB boilerplate with generic DB operation wrapper
|
||||||
- [x] Simplify drop indicator logic
|
- [x] Simplify drop indicator logic
|
||||||
- [x] Extract file operations into higher-level abstraction
|
- [x] Extract file operations into higher-level abstraction
|
||||||
- [x] Consolidate modal logic into generic modal handler
|
- [x] Consolidate modal logic into generic modal handler
|
||||||
|
|
|
||||||
39
index.html
39
index.html
|
|
@ -1077,48 +1077,31 @@ chmod 755 kbtd
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
async function getFileHandle(path) {
|
async function dbOperation(mode, fn) {
|
||||||
const db = await dbPromise;
|
const db = await dbPromise;
|
||||||
|
const tx = db.transaction(STORE_NAME, mode);
|
||||||
|
const store = tx.objectStore(STORE_NAME);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const tx = db.transaction(STORE_NAME, 'readonly');
|
const request = fn(store);
|
||||||
const store = tx.objectStore(STORE_NAME);
|
|
||||||
const request = store.get(path);
|
|
||||||
request.onsuccess = () => resolve(request.result);
|
request.onsuccess = () => resolve(request.result);
|
||||||
request.onerror = () => reject(request.error);
|
request.onerror = () => reject(request.error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getFileHandle(path) {
|
||||||
|
return dbOperation('readonly', store => store.get(path));
|
||||||
|
}
|
||||||
|
|
||||||
async function storeFileHandle(path, handle) {
|
async function storeFileHandle(path, handle) {
|
||||||
const db = await dbPromise;
|
return dbOperation('readwrite', store => store.put(handle, path));
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const tx = db.transaction(STORE_NAME, 'readwrite');
|
|
||||||
const store = tx.objectStore(STORE_NAME);
|
|
||||||
const request = store.put(handle, path);
|
|
||||||
request.onsuccess = () => resolve();
|
|
||||||
request.onerror = () => reject(request.error);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeFileHandle(path) {
|
async function removeFileHandle(path) {
|
||||||
const db = await dbPromise;
|
return dbOperation('readwrite', store => store.delete(path));
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const tx = db.transaction(STORE_NAME, 'readwrite');
|
|
||||||
const store = tx.objectStore(STORE_NAME);
|
|
||||||
const request = store.delete(path);
|
|
||||||
request.onsuccess = () => resolve();
|
|
||||||
request.onerror = () => reject(request.error);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAllStoredProjects() {
|
async function getAllStoredProjects() {
|
||||||
const db = await dbPromise;
|
return dbOperation('readonly', store => store.getAllKeys());
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const tx = db.transaction(STORE_NAME, 'readonly');
|
|
||||||
const store = tx.objectStore(STORE_NAME);
|
|
||||||
const request = store.getAllKeys();
|
|
||||||
request.onsuccess = () => resolve(request.result);
|
|
||||||
request.onerror = () => reject(request.error);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function validateFileHandle(handle) {
|
async function validateFileHandle(handle) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue