refactor(client): refactor admin/instance-block to use Composition API (#8663)

This commit is contained in:
Andreas Nedbal 2022-05-17 18:31:59 +02:00 committed by GitHub
parent 2317105922
commit 24aaad4b26

View file

@ -2,57 +2,45 @@
<MkSpacer :content-max="700" :margin-min="16" :margin-max="32"> <MkSpacer :content-max="700" :margin-min="16" :margin-max="32">
<FormSuspense :p="init"> <FormSuspense :p="init">
<FormTextarea v-model="blockedHosts" class="_formBlock"> <FormTextarea v-model="blockedHosts" class="_formBlock">
<span>{{ $ts.blockedInstances }}</span> <span>{{ i18n.ts.blockedInstances }}</span>
<template #caption>{{ $ts.blockedInstancesDescription }}</template> <template #caption>{{ i18n.ts.blockedInstancesDescription }}</template>
</FormTextarea> </FormTextarea>
<FormButton primary class="_formBlock" @click="save"><i class="fas fa-save"></i> {{ $ts.save }}</FormButton> <FormButton primary class="_formBlock" @click="save"><i class="fas fa-save"></i> {{ i18n.ts.save }}</FormButton>
</FormSuspense> </FormSuspense>
</MkSpacer> </MkSpacer>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { } from 'vue';
import FormButton from '@/components/ui/button.vue'; import FormButton from '@/components/ui/button.vue';
import FormTextarea from '@/components/form/textarea.vue'; import FormTextarea from '@/components/form/textarea.vue';
import FormSuspense from '@/components/form/suspense.vue'; import FormSuspense from '@/components/form/suspense.vue';
import * as os from '@/os'; import * as os from '@/os';
import * as symbols from '@/symbols'; import * as symbols from '@/symbols';
import { fetchInstance } from '@/instance'; import { fetchInstance } from '@/instance';
import { i18n } from '@/i18n';
export default defineComponent({ let blockedHosts: string = $ref('');
components: {
FormButton,
FormTextarea,
FormSuspense,
},
emits: ['info'], async function init() {
data() {
return {
[symbols.PAGE_INFO]: {
title: this.$ts.instanceBlocking,
icon: 'fas fa-ban',
bg: 'var(--bg)',
},
blockedHosts: '',
}
},
methods: {
async init() {
const meta = await os.api('admin/meta'); const meta = await os.api('admin/meta');
this.blockedHosts = meta.blockedHosts.join('\n'); blockedHosts = meta.blockedHosts.join('\n');
}, }
save() { function save() {
os.apiWithDialog('admin/update-meta', { os.apiWithDialog('admin/update-meta', {
blockedHosts: this.blockedHosts.split('\n') || [], blockedHosts: blockedHosts.split('\n') || [],
}).then(() => { }).then(() => {
fetchInstance(); fetchInstance();
}); });
} }
defineExpose({
[symbols.PAGE_INFO]: {
title: i18n.ts.instanceBlocking,
icon: 'fas fa-ban',
bg: 'var(--bg)',
} }
}); });
</script> </script>