diff --git a/source/demyo-vue-frontend/src/composables/model-index.js b/source/demyo-vue-frontend/src/composables/model-index.js deleted file mode 100644 index dddf2aee..00000000 --- a/source/demyo-vue-frontend/src/composables/model-index.js +++ /dev/null @@ -1,28 +0,0 @@ -import { useUiStore } from '@/stores/ui' -import { useHead } from '@unhead/vue' -import { useI18n } from 'vue-i18n' - -/** - * Composable for simple model indexes loading data from the service. - * @param {AbstractModelService} serviceInstance The service to use to fetch the data. - * @param {string} titleKey the page title key - */ -export function useSimpleIndex(serviceInstance, titleKey) { - useHead({ - title: useI18n().t(titleKey) - }) - - const uiStore = useUiStore() - - const modelList = ref([]) - - async function fetchData() { - uiStore.enableGlobalOverlay() - modelList.value = await serviceInstance.findForIndex() - uiStore.disableGlobalOverlay() - } - - fetchData() - - return { modelList } -} diff --git a/source/demyo-vue-frontend/src/composables/model-index.ts b/source/demyo-vue-frontend/src/composables/model-index.ts new file mode 100644 index 00000000..7d43d76f --- /dev/null +++ b/source/demyo-vue-frontend/src/composables/model-index.ts @@ -0,0 +1,36 @@ +import AbstractModelService from '@/services/abstract-model-service' +import { useUiStore } from '@/stores/ui' +import { useHead } from '@unhead/vue' +import { computed } from 'vue' +import { useI18n } from 'vue-i18n' + +/** + * Composable for simple model indexes loading data from the service. + * @param serviceInstance The service to use to fetch the data. + * @param titleKey the page title key + */ +export function useSimpleIndex(serviceInstance: AbstractModelService, titleKey: string, + fetchData: (() => Promise) | null = null) { + // + let safeFetchData: () => Promise + safeFetchData = fetchData || (() => serviceInstance.findForIndex()) + + useHead({ + title: useI18n().t(titleKey) + }) + + const uiStore = useUiStore() + const loading = computed(() => uiStore.globalOverlay) + + const modelList = ref([] as T[]) + + async function loadData() { + uiStore.enableGlobalOverlay() + modelList.value = await safeFetchData() + uiStore.disableGlobalOverlay() + } + + loadData() + + return { loading, modelList } +} diff --git a/source/demyo-vue-frontend/src/composables/pagination.ts b/source/demyo-vue-frontend/src/composables/pagination.ts index b741f808..1484a8bc 100644 --- a/source/demyo-vue-frontend/src/composables/pagination.ts +++ b/source/demyo-vue-frontend/src/composables/pagination.ts @@ -3,7 +3,7 @@ */ import { useReaderStore } from '@/stores/reader' -import { Dictionary } from 'lodash' +import type { Dictionary } from 'lodash' import deburr from 'lodash/deburr' import groupBy from 'lodash/groupBy' @@ -19,7 +19,7 @@ function extractFirstLetter(item: T, firstLetterExtract export const emitTypes = ['page-change'] -interface PaginationState { +interface PaginationState { /** The current page number. */ currentPage: Ref /** The total page count. */ diff --git a/source/demyo-vue-frontend/src/pages/albums/AlbumIndex.vue b/source/demyo-vue-frontend/src/pages/albums/AlbumIndex.vue index c386686d..fafeaab8 100644 --- a/source/demyo-vue-frontend/src/pages/albums/AlbumIndex.vue +++ b/source/demyo-vue-frontend/src/pages/albums/AlbumIndex.vue @@ -1,33 +1,22 @@ - diff --git a/source/demyo-vue-frontend/src/pages/tags/TagIndex.vue b/source/demyo-vue-frontend/src/pages/tags/TagIndex.vue index c473bb6f..f230e2b7 100644 --- a/source/demyo-vue-frontend/src/pages/tags/TagIndex.vue +++ b/source/demyo-vue-frontend/src/pages/tags/TagIndex.vue @@ -5,61 +5,38 @@ - + -