Refactor admin/relays to use Composition API (#8677)

* refactor(client): refactor admin/relays to use Composition API

* Apply review suggestion from @Johann150

Co-authored-by: Johann150 <johann@qwertqwefsday.eu>

Co-authored-by: Johann150 <johann@qwertqwefsday.eu>
This commit is contained in:
Andreas Nedbal 2022-05-17 18:30:49 +02:00 committed by GitHub
parent 7d08b936c6
commit dfeafaf499
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,84 +8,71 @@
<i v-else class="fas fa-clock icon requesting"></i> <i v-else class="fas fa-clock icon requesting"></i>
<span>{{ $t(`_relayStatus.${relay.status}`) }}</span> <span>{{ $t(`_relayStatus.${relay.status}`) }}</span>
</div> </div>
<MkButton class="button" inline danger @click="remove(relay.inbox)"><i class="fas fa-trash-alt"></i> {{ $ts.remove }}</MkButton> <MkButton class="button" inline danger @click="remove(relay.inbox)"><i class="fas fa-trash-alt"></i> {{ i18n.ts.remove }}</MkButton>
</div> </div>
</MkSpacer> </MkSpacer>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { } from 'vue';
import MkButton from '@/components/ui/button.vue'; import MkButton from '@/components/ui/button.vue';
import * as os from '@/os'; import * as os from '@/os';
import * as symbols from '@/symbols'; import * as symbols from '@/symbols';
import { i18n } from '@/i18n';
export default defineComponent({ let relays: any[] = $ref([]);
components: {
MkButton,
},
emits: ['info'], async function addRelay() {
data() {
return {
[symbols.PAGE_INFO]: {
title: this.$ts.relays,
icon: 'fas fa-globe',
bg: 'var(--bg)',
actions: [{
asFullButton: true,
icon: 'fas fa-plus',
text: this.$ts.addRelay,
handler: this.addRelay,
}],
},
relays: [],
inbox: '',
}
},
created() {
this.refresh();
},
methods: {
async addRelay() {
const { canceled, result: inbox } = await os.inputText({ const { canceled, result: inbox } = await os.inputText({
title: this.$ts.addRelay, title: i18n.ts.addRelay,
type: 'url', type: 'url',
placeholder: this.$ts.inboxUrl placeholder: i18n.ts.inboxUrl
}); });
if (canceled) return; if (canceled) return;
os.api('admin/relays/add', { os.api('admin/relays/add', {
inbox inbox
}).then((relay: any) => { }).then((relay: any) => {
this.refresh(); refresh();
}).catch((e: any) => { }).catch((err: any) => {
os.alert({ os.alert({
type: 'error', type: 'error',
text: e.message || e text: err.message || err
}); });
}); });
}, }
remove(inbox: string) { function remove(inbox: string) {
os.api('admin/relays/remove', { os.api('admin/relays/remove', {
inbox inbox
}).then(() => { }).then(() => {
this.refresh(); refresh();
}).catch((e: any) => { }).catch((err: any) => {
os.alert({ os.alert({
type: 'error', type: 'error',
text: e.message || e text: err.message || err
}); });
}); });
}, }
refresh() { function refresh() {
os.api('admin/relays/list').then((relays: any) => { os.api('admin/relays/list').then((relayList: any) => {
this.relays = relays; relays = relayList;
}); });
} }
refresh();
defineExpose({
[symbols.PAGE_INFO]: {
title: i18n.ts.relays,
icon: 'fas fa-globe',
bg: 'var(--bg)',
actions: [{
asFullButton: true,
icon: 'fas fa-plus',
text: i18n.ts.addRelay,
handler: addRelay,
}],
} }
}); });
</script> </script>