-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #156
- Loading branch information
Showing
5 changed files
with
66 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T extends IModel>(serviceInstance: AbstractModelService, titleKey: string, | ||
fetchData: (() => Promise<T[]>) | null = null) { | ||
// | ||
let safeFetchData: () => Promise<T[]> | ||
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 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,22 @@ | ||
<template> | ||
<div class="c-AlbumIndex"> | ||
<MetaSeriesIndex :items="albums" @page-change="scrollToTop" /> | ||
<Fab to="/albums/new" icon="mdi-plus" /> | ||
<Fab v-if="!loading" to="/albums/new" icon="mdi-plus" /> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
<script setup lang="ts"> | ||
import { useSimpleIndex } from '@/composables/model-index' | ||
import { retrieveFilter } from '@/helpers/filter' | ||
import albumService from '@/services/album-service' | ||
import { useUiStore } from '@/stores/ui' | ||
import { useHead } from '@unhead/vue' | ||
import { useI18n } from 'vue-i18n' | ||
import { useRoute } from 'vue-router' | ||
useHead({ | ||
title: useI18n().t('title.index.album') | ||
}) | ||
const uiStore = useUiStore() | ||
const route = useRoute() | ||
const albums = ref([]) | ||
async function fetchData() { | ||
uiStore.enableGlobalOverlay() | ||
function fetchData() { | ||
const filter = retrieveFilter(route) | ||
albums.value = await albumService.findForIndex(filter) | ||
uiStore.disableGlobalOverlay() | ||
return albumService.findForIndex(filter) | ||
} | ||
void fetchData() | ||
const { loading, modelList: albums } = useSimpleIndex(albumService, 'title.index.album', fetchData) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters