From e6055c8bf8453a4ccb856487e21199bf45541a01 Mon Sep 17 00:00:00 2001 From: Azri Kahar <42867097+azrikahar@users.noreply.github.com> Date: Sat, 5 Mar 2022 08:15:10 +0800 Subject: [PATCH] Resizable navigation panel (#11944) * WIP for resizable nav panel * tweak handle width & hover delay * further tweaks based on vscode's implementation * add useLocalStorage * tweak responsiveness & limits * prefix localstorage key * rename key * add context menu for resetting width * snap into place when within 10 pixels range * fix stylelint * Tweak styling, reduce folder complexity * Remove context menu * Organize imports * Rework private-view to script setup Co-authored-by: rijkvanzanten --- app/src/composables/use-local-storage.ts | 40 ++++ app/src/lang/translations/en-US.yaml | 1 + app/src/views/private/private-view.vue | 258 ++++++++++++++++------- 3 files changed, 222 insertions(+), 77 deletions(-) create mode 100644 app/src/composables/use-local-storage.ts diff --git a/app/src/composables/use-local-storage.ts b/app/src/composables/use-local-storage.ts new file mode 100644 index 0000000000..e73acee620 --- /dev/null +++ b/app/src/composables/use-local-storage.ts @@ -0,0 +1,40 @@ +import { ref, watch } from 'vue'; + +export default function useLocalStorage(key: string) { + const internalKey = `directus-${key}`; + const data = ref(null); + + function getExistingValue() { + let rawExistingValue; + try { + rawExistingValue = localStorage.getItem(internalKey); + } catch (err: any) { + // + } + + if (!rawExistingValue) return; + + try { + const existingValue = JSON.parse(rawExistingValue); + data.value = existingValue; + } catch (err: any) { + // + } + } + + getExistingValue(); + + watch(data, () => { + try { + if (data.value == null) { + localStorage.removeItem(internalKey); + } else { + localStorage.setItem(internalKey, JSON.stringify(data.value)); + } + } catch (err: any) { + // + } + }); + + return { data }; +} diff --git a/app/src/lang/translations/en-US.yaml b/app/src/lang/translations/en-US.yaml index cfeb677d22..4643ffddbf 100644 --- a/app/src/lang/translations/en-US.yaml +++ b/app/src/lang/translations/en-US.yaml @@ -29,6 +29,7 @@ draft: Draft archived: Archived modules: Modules module_bar: Module Bar +reset_width: Reset Width tile_size: Tile Size edit_field: Edit Field conditions: Conditions diff --git a/app/src/views/private/private-view.vue b/app/src/views/private/private-view.vue index 77c62e832c..a4a429645d 100644 --- a/app/src/views/private/private-view.vue +++ b/app/src/views/private/private-view.vue @@ -10,12 +10,21 @@
@@ -37,6 +46,7 @@