From 4a26f576627d3c8e5b9044abe50bcc8809ac6cca Mon Sep 17 00:00:00 2001 From: paultirk Date: Tue, 25 Jun 2024 21:44:08 +0000 Subject: [PATCH 1/4] add localforage package --- package-lock.json | 28 ++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 29 insertions(+) diff --git a/package-lock.json b/package-lock.json index 967b1d2..f346009 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,6 +38,7 @@ "eslint-plugin-vue": "^9.9.0", "glob": "^8.0.3", "jsdom": "^20.0.0", + "localforage": "^1.10.0", "postcss": "^8.4.14", "prettier": "^3.0.3", "release-it": "^16.2.1", @@ -6235,6 +6236,13 @@ "node": ">= 4" } }, + "node_modules/immediate": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", + "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==", + "dev": true, + "license": "MIT" + }, "node_modules/immutable": { "version": "4.3.5", "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.3.5.tgz", @@ -7554,6 +7562,16 @@ "node": ">= 0.8.0" } }, + "node_modules/lie": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz", + "integrity": "sha512-RiNhHysUjhrDQntfYSfY4MU24coXXdEOgw9WGcKHNeEwffDYbF//u87M1EWaMGzuFoSbqW0C9C6lEEhDOAswfw==", + "dev": true, + "license": "MIT", + "dependencies": { + "immediate": "~3.0.5" + } + }, "node_modules/lilconfig": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.1.0.tgz", @@ -7601,6 +7619,16 @@ "url": "https://github.com/sponsors/antfu" } }, + "node_modules/localforage": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/localforage/-/localforage-1.10.0.tgz", + "integrity": "sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "lie": "3.1.1" + } + }, "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", diff --git a/package.json b/package.json index 2f44d2d..8aac248 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "eslint-plugin-vue": "^9.9.0", "glob": "^8.0.3", "jsdom": "^20.0.0", + "localforage": "^1.10.0", "postcss": "^8.4.14", "prettier": "^3.0.3", "release-it": "^16.2.1", From 89767c44f71ec4c6f5bb322906b7f0072ee01b4c Mon Sep 17 00:00:00 2001 From: paultirk Date: Tue, 25 Jun 2024 22:37:43 +0000 Subject: [PATCH 2/4] add local forage composable --- src/utils/useLocalForage.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/utils/useLocalForage.ts diff --git a/src/utils/useLocalForage.ts b/src/utils/useLocalForage.ts new file mode 100644 index 0000000..456e3f3 --- /dev/null +++ b/src/utils/useLocalForage.ts @@ -0,0 +1,30 @@ +import localforage from 'localforage'; + +export function useLocalForage( + storageKey: string, + storeName = 'settings' +): { + setItemInKey: (itemId: number, value: T) => Promise; + getItemInKey: (itemId: number) => Promise; +} { + localforage.config({ + name: 'money', + storeName + }); + + return { + getItemInKey: async (itemId): Promise => { + const keyValue = await localforage.getItem>(storageKey); + + return keyValue?.[itemId]; + }, + setItemInKey: async (itemId, value): Promise => { + const status = await localforage.getItem>(storageKey); + + await localforage.setItem('bookCollapsedStatus', { + ...status, + [itemId]: value + }); + } + }; +} From 0bf4fce58caf13003ab164a89b13c7e21a9160d5 Mon Sep 17 00:00:00 2001 From: paultirk Date: Tue, 25 Jun 2024 22:39:23 +0000 Subject: [PATCH 3/4] save collapsible status of book navigation items --- src/components/BookNavigationItem.vue | 41 +++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/components/BookNavigationItem.vue b/src/components/BookNavigationItem.vue index b998dc6..bc82533 100644 --- a/src/components/BookNavigationItem.vue +++ b/src/components/BookNavigationItem.vue @@ -23,7 +23,7 @@ :loading="isLoading" :undo="isDeleting" :open="isOpen" - @update:open="(open: boolean) => (isOpen = open)" + @update:open="handleUpdateOpenStatus" @update:name="handleUpdateBookName" @undo="handleUndo" > @@ -121,7 +121,14 @@ From 1e39ece580c3c4dcae87f26fe9127e9ae89a942a Mon Sep 17 00:00:00 2001 From: paultirk Date: Tue, 25 Jun 2024 22:39:44 +0000 Subject: [PATCH 4/4] add changelog entry for saving book collapsed state --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db74888..0dc5b7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Reset input when escape key is pressed - Implement audit logging +- Save collapsed state of book navigation items ## [0.26.6] - 2024-06-10