mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
refactor: rework async ToolSettings
This commit is contained in:
parent
ab506a5727
commit
09e9c272b7
1 changed files with 25 additions and 39 deletions
|
@ -1,32 +1,20 @@
|
|||
<script setup lang="ts">
|
||||
import { shallowRef } from 'vue'
|
||||
|
||||
import api, { objectToParams } from '@/api'
|
||||
import ConfigPanelsComponent from '@/components/ConfigPanels.vue'
|
||||
import type {
|
||||
ConfigPanelsProps,
|
||||
OnPanelApply,
|
||||
} from '@/composables/configPanels'
|
||||
import { formatConfigPanels, useConfigPanels } from '@/composables/configPanels'
|
||||
import { useInitialQueries } from '@/composables/useInitialQueries'
|
||||
import type { CoreConfigPanels } from '@/types/core/options'
|
||||
|
||||
const props = defineProps<{ tabId?: string }>()
|
||||
|
||||
const { loading, refetch } = useInitialQueries([{ uri: 'settings?full' }], {
|
||||
onQueriesResponse,
|
||||
const coreConfig = await api.get<CoreConfigPanels>({
|
||||
uri: 'settings?full',
|
||||
initial: true,
|
||||
})
|
||||
const config = shallowRef<ConfigPanelsProps | undefined>()
|
||||
|
||||
function onQueriesResponse(config_: CoreConfigPanels) {
|
||||
config.value = useConfigPanels(
|
||||
formatConfigPanels(config_),
|
||||
const { form, panel, v, routes, onPanelApply } = useConfigPanels(
|
||||
formatConfigPanels(coreConfig),
|
||||
() => props.tabId,
|
||||
onPanelApply,
|
||||
)
|
||||
}
|
||||
|
||||
const onPanelApply: OnPanelApply = ({ panelId, data }, onError) => {
|
||||
({ panelId, data }, onError) => {
|
||||
// FIXME no route for potential action
|
||||
api
|
||||
.put({
|
||||
|
@ -34,20 +22,18 @@ const onPanelApply: OnPanelApply = ({ panelId, data }, onError) => {
|
|||
data: { args: objectToParams(data) },
|
||||
humanKey: { key: 'settings.update', panel: panelId },
|
||||
})
|
||||
.then(() => refetch())
|
||||
.then(() => api.refetch())
|
||||
.catch(onError)
|
||||
}
|
||||
},
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ViewBase :loading="loading" skeleton="CardFormSkeleton">
|
||||
<ConfigPanelsComponent
|
||||
v-if="config"
|
||||
v-model="config.form"
|
||||
:panel="config.panel.value"
|
||||
:validations="config.v.value"
|
||||
:routes="config.routes"
|
||||
@apply="config.onPanelApply"
|
||||
v-model="form"
|
||||
:panel="panel"
|
||||
:validations="v"
|
||||
:routes="routes"
|
||||
@apply="onPanelApply"
|
||||
/>
|
||||
</ViewBase>
|
||||
</template>
|
||||
|
|
Loading…
Add table
Reference in a new issue