From 3054c3ec5ca0d74382068faf538f8033380ec5b5 Mon Sep 17 00:00:00 2001 From: axolotle Date: Sat, 6 Jul 2024 16:03:47 +0200 Subject: [PATCH] refactor: use useInitialQueries in views --- app/src/views/app/AppCatalog.vue | 28 +++++++++------- app/src/views/app/AppInfo.vue | 41 +++++++++-------------- app/src/views/app/AppInstall.vue | 17 ++++++---- app/src/views/app/AppList.vue | 19 ++++++----- app/src/views/backup/BackupCreate.vue | 22 ++++++------ app/src/views/backup/BackupInfo.vue | 11 ++++-- app/src/views/backup/BackupList.vue | 16 ++++----- app/src/views/diagnosis/DiagnosisView.vue | 26 ++++++-------- app/src/views/domain/DomainAdd.vue | 5 +-- app/src/views/domain/DomainDns.vue | 16 ++++----- app/src/views/domain/DomainInfo.vue | 29 +++++++--------- app/src/views/domain/DomainList.vue | 9 +++-- app/src/views/group/GroupList.vue | 33 +++++++++--------- app/src/views/service/ServiceInfo.vue | 31 ++++++++--------- app/src/views/service/ServiceList.vue | 16 +++++---- app/src/views/tool/ToolFirewall.vue | 22 +++++------- app/src/views/tool/ToolLog.vue | 21 +++++------- app/src/views/tool/ToolLogs.vue | 14 +++++--- app/src/views/tool/ToolMigrations.vue | 30 ++++++++--------- app/src/views/tool/ToolSettings.vue | 19 ++++------- app/src/views/update/SystemUpdate.vue | 24 ++++++------- app/src/views/user/UserCreate.vue | 18 +++++----- app/src/views/user/UserEdit.vue | 21 ++++++------ app/src/views/user/UserInfo.vue | 8 ++--- app/src/views/user/UserList.vue | 11 +++--- 25 files changed, 245 insertions(+), 262 deletions(-) diff --git a/app/src/views/app/AppCatalog.vue b/app/src/views/app/AppCatalog.vue index 406a6bb2..bff18bba 100644 --- a/app/src/views/app/AppCatalog.vue +++ b/app/src/views/app/AppCatalog.vue @@ -8,6 +8,7 @@ import CardDeckFeed from '@/components/CardDeckFeed.vue' import { useAutoModal } from '@/composables/useAutoModal' import { randint } from '@/helpers/commons' import { appRepoUrl, required } from '@/helpers/validators' +import { useInitialQueries } from '@/composables/useInitialQueries' const props = withDefaults( defineProps<{ @@ -28,8 +29,10 @@ const { t } = useI18n() const router = useRouter() const route = useRoute() const modalConfirm = useAutoModal() - -const queries = [['GET', 'apps/catalog?full&with_categories&with_antifeatures']] +const { loading } = useInitialQueries( + [['GET', 'apps/catalog?full&with_categories&with_antifeatures']], + { onQueriesResponse }, +) const apps = ref() const selectedApp = ref() @@ -96,10 +99,10 @@ const subtags = computed(() => { return null }) -function onQueriesResponse(data) { - const apps = [] - for (const key in data.apps) { - const app = data.apps[key] +function onQueriesResponse(catalog: any) { + const apps_ = [] + for (const key in catalog.apps) { + const app = catalog.apps[key] app.isInstallable = !app.installed || app.manifest.integration.multi_instance app.working = app.state === 'working' @@ -124,12 +127,12 @@ function onQueriesResponse(data) { ] .join(' ') .toLowerCase() - apps.push(app) + apps_.push(app) } - apps.value = apps.sort((a, b) => (a.id > b.id ? 1 : -1)) + apps.value = apps_.sort((a, b) => (a.id > b.id ? 1 : -1)) // CATEGORIES - data.categories.forEach(({ title, id, icon, subtags, description }) => { + catalog.categories.forEach(({ title, id, icon, subtags, description }) => { categories.push({ text: title, value: id, @@ -139,7 +142,7 @@ function onQueriesResponse(data) { }) }) antifeatures.value = Object.fromEntries( - data.antifeatures.map((af) => [af.id, af]), + catalog.antifeatures.map((af) => [af.id, af]), ) } @@ -180,11 +183,10 @@ async function onCustomInstallClick() {