From 3bdd4358d197a6f3dfeb94bef170d0ac80b2552a Mon Sep 17 00:00:00 2001 From: orlinmalkja <54899269+orlinmalkja@users.noreply.github.com> Date: Thu, 6 Jun 2024 13:48:15 +0200 Subject: [PATCH] refactor: use 'contents' Pinia store (#10) * refactor: use 'contents' Pinia store, no more Vuex store modules * style: minor --------- Co-authored-by: malkja --- src/App.vue | 23 +- src/components/ContentView.vue | 6 +- src/components/ImageView.vue | 8 +- src/components/TreeView.vue | 17 +- .../annotations/AnnotationsView.vue | 8 +- src/components/header/GlobalHeader.vue | 8 +- src/components/header/Navbar.vue | 20 +- src/components/header/TitleBar.vue | 8 +- .../metadata/CollectionMetadata.vue | 10 +- src/components/metadata/ItemMetadata.vue | 12 +- src/components/metadata/ManifestMetadata.vue | 11 +- src/components/panels/Panel.vue | 6 +- src/main.js | 3 - src/store/contents/actions.js | 219 -------------- src/store/contents/getters.js | 28 -- src/store/contents/index.js | 12 - src/store/contents/mutations.js | 24 -- src/store/contents/state.js | 10 - src/store/index.js | 9 - src/store/store-flag.d.ts | 9 - src/stores/contents.ts | 280 ++++++++++++++++++ 21 files changed, 352 insertions(+), 379 deletions(-) delete mode 100644 src/store/contents/actions.js delete mode 100644 src/store/contents/getters.js delete mode 100644 src/store/contents/index.js delete mode 100644 src/store/contents/mutations.js delete mode 100644 src/store/contents/state.js delete mode 100644 src/store/index.js delete mode 100644 src/store/store-flag.d.ts create mode 100644 src/stores/contents.ts diff --git a/src/App.vue b/src/App.vue index ce7f8453..c6e4dcdb 100644 --- a/src/App.vue +++ b/src/App.vue @@ -36,9 +36,9 @@ export default { import { computed, inject, onMounted, ref, } from 'vue'; -import { useStore } from 'vuex'; import { useConfigStore } from '@/stores/config'; -import { useAnnotationsStore } from './stores/annotations'; +import { useAnnotationsStore } from '@/stores/annotations'; +import { useContentsStore } from '@/stores/contents'; import { useI18n } from 'vue-i18n'; import GlobalHeader from '@/components/header/GlobalHeader.vue'; @@ -49,9 +49,9 @@ import Loading from '@/components/Loading.vue'; import BaseIcon from '@/components/base/BaseIcon.vue'; import { initUseDark } from '@/utils/is-dark'; -const store = useStore(); const configStore = useConfigStore() const annotationStore = useAnnotationsStore() +const contentStore = useContentsStore() const { t, locale: i18nLocale } = useI18n(); const errorTitle = ref(''); @@ -80,10 +80,10 @@ const ready = computed(() => { }); const annotations = computed(() => annotationStore.annotations); const config = computed(() => configStore.config); -const collection = computed(() => store.getters['contents/collection']); -const item = computed(() => store.getters['contents/item']); -const manifest = computed(() => store.getters['contents/manifest']); -const manifests = computed(() => store.getters['contents/manifests']); +const collection = computed(() => contentStore.collection); +const item = computed(() => contentStore.item); +const manifest = computed(() => contentStore.manifest); +const manifests = computed(() => contentStore.manifests); initUseDark(config.value.container); onMounted(async () => { @@ -104,7 +104,8 @@ onMounted(async () => { }); async function getCollection(url: string) { - await store.dispatch('contents/initCollection', url); + const contentStore = useContentsStore() + await contentStore.initCollection(url) } async function loadConfig() { try { @@ -116,10 +117,12 @@ async function loadConfig() { } } async function getManifest(url: string) { - await store.dispatch('contents/initManifest', url); + const contentStore = useContentsStore() + await contentStore.initManifest(url) } async function getItem(url: string) { - await store.dispatch('contents/initItem', url); + const contentStore = useContentsStore() + await contentStore.initItem(url) } async function init() { const { collection, manifest, item } = config.value; diff --git a/src/components/ContentView.vue b/src/components/ContentView.vue index 100e649c..90bdbab9 100644 --- a/src/components/ContentView.vue +++ b/src/components/ContentView.vue @@ -21,9 +21,9 @@ import { computed, readonly, ref, watch, } from 'vue'; -import { useStore } from 'vuex'; import { useConfigStore } from '@/stores/config'; import { useAnnotationsStore } from '@/stores/annotations'; +import { useContentsStore } from '@/stores/contents' import Notification from '@/components/Notification.vue'; import { request } from '@/utils/http'; import { domParser, delay } from '@/utils'; @@ -35,8 +35,8 @@ const props = defineProps({ }); const emit = defineEmits(['loading']); -const store = useStore(); const configStore = useConfigStore() +const contentStore = useContentsStore() const content = ref(''); const errorTextMessage = ref(null); @@ -78,7 +78,7 @@ async function loadContent(url) { // TODO: Enable Hover + Tooltip feature when reqs are clarified // await store.dispatch('annotations/addHighlightHoverListeners'); - store.commit('contents/setActiveContentUrl', props.url); + contentStore.setActiveContentUrl(props.url) }, 100); } catch (err) { errorTextMessage.value = err.message; diff --git a/src/components/ImageView.vue b/src/components/ImageView.vue index 3506188f..075d9921 100644 --- a/src/components/ImageView.vue +++ b/src/components/ImageView.vue @@ -10,18 +10,18 @@ + \ No newline at end of file diff --git a/src/components/TreeView.vue b/src/components/TreeView.vue index efe96551..ac5fa2bd 100644 --- a/src/components/TreeView.vue +++ b/src/components/TreeView.vue @@ -47,16 +47,16 @@ import Tree from 'primevue/tree'; import { computed, nextTick, onMounted, ref, watch, } from 'vue'; -import { useStore } from 'vuex'; import { useConfigStore } from '@/stores/config'; +import { useContentsStore } from '@/stores/contents'; import { useI18n } from 'vue-i18n'; import { request } from '@/utils/http'; import { isElementVisible } from '@/utils'; const emit = defineEmits(['loading']); -const store = useStore(); const configStore = useConfigStore() +const contentStore = useContentsStore() const { t } = useI18n(); const expanded = ref({}); @@ -65,11 +65,11 @@ const tree = ref([]); const containerRef = ref(null); const config = computed(() => configStore.config); -const collectionTitle = computed(() => store.getters['contents/collectionTitle']); -const collection = computed(() => store.getters['contents/collection']); +const collectionTitle = computed(() => contentStore.collectionTitle); +const collection = computed(() => contentStore.collection); const labels = computed(() => (config.value && config.value.labels) || {}); -const itemUrl = computed(() => store.getters['contents/itemUrl']); -const currentManifest = computed(() => store.getters['contents/manifest']); +const itemUrl = computed(() => contentStore.itemUrl); +const currentManifest = computed(() => contentStore.manifest); onMounted(() => { emit('loading', true); @@ -165,13 +165,14 @@ async function onNodeExpand(node) { async function onNodeSelect(node) { const configStore = useConfigStore() + const contentStore = useContentsStore() if (currentManifest.value.id !== node.parent) { // If we selected an item from a different manifest - await store.dispatch('contents/initManifest', node.parent); + await contentStore.initManifest(node.parent) await configStore.setDefaultActiveViews() } - await store.dispatch('contents/initItem', node.key); + await contentStore.initItem(node.key) } function scrollSelectedIntoView() { diff --git a/src/components/annotations/AnnotationsView.vue b/src/components/annotations/AnnotationsView.vue index 2afc64ff..693f33b5 100644 --- a/src/components/annotations/AnnotationsView.vue +++ b/src/components/annotations/AnnotationsView.vue @@ -21,32 +21,32 @@ \ No newline at end of file diff --git a/src/components/header/Navbar.vue b/src/components/header/Navbar.vue index c294288b..f953d407 100644 --- a/src/components/header/Navbar.vue +++ b/src/components/header/Navbar.vue @@ -25,18 +25,18 @@ \ No newline at end of file diff --git a/src/components/header/TitleBar.vue b/src/components/header/TitleBar.vue index 70e8d972..15f262b3 100644 --- a/src/components/header/TitleBar.vue +++ b/src/components/header/TitleBar.vue @@ -35,8 +35,8 @@