Refactor admin/integrations to use Composition API (#8664)

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

* Apply review suggestions 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:31:48 +02:00 committed by GitHub
parent 83ac6742f6
commit 18307c822c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 167 deletions

View file

@ -24,57 +24,36 @@
</FormSuspense> </FormSuspense>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { } from 'vue';
import FormSwitch from '@/components/form/switch.vue'; import FormSwitch from '@/components/form/switch.vue';
import FormInput from '@/components/form/input.vue'; import FormInput from '@/components/form/input.vue';
import FormButton from '@/components/ui/button.vue'; import FormButton from '@/components/ui/button.vue';
import FormInfo from '@/components/ui/info.vue'; import FormInfo from '@/components/ui/info.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 { fetchInstance } from '@/instance'; import { fetchInstance } from '@/instance';
export default defineComponent({ let uri: string = $ref('');
components: { let enableDiscordIntegration: boolean = $ref(false);
FormSwitch, let discordClientId: string | null = $ref(null);
FormInput, let discordClientSecret: string | null = $ref(null);
FormInfo,
FormButton,
FormSuspense,
},
emits: ['info'], async function init() {
data() {
return {
[symbols.PAGE_INFO]: {
title: 'Discord',
icon: 'fab fa-discord'
},
enableDiscordIntegration: false,
discordClientId: null,
discordClientSecret: null,
}
},
methods: {
async init() {
const meta = await os.api('admin/meta'); const meta = await os.api('admin/meta');
this.uri = meta.uri; uri = meta.uri;
this.enableDiscordIntegration = meta.enableDiscordIntegration; enableDiscordIntegration = meta.enableDiscordIntegration;
this.discordClientId = meta.discordClientId; discordClientId = meta.discordClientId;
this.discordClientSecret = meta.discordClientSecret; discordClientSecret = meta.discordClientSecret;
}, }
save() {
function save() {
os.apiWithDialog('admin/update-meta', { os.apiWithDialog('admin/update-meta', {
enableDiscordIntegration: this.enableDiscordIntegration, enableDiscordIntegration,
discordClientId: this.discordClientId, discordClientId,
discordClientSecret: this.discordClientSecret, discordClientSecret,
}).then(() => { }).then(() => {
fetchInstance(); fetchInstance();
}); });
} }
}
});
</script> </script>

View file

@ -24,57 +24,36 @@
</FormSuspense> </FormSuspense>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { } from 'vue';
import FormSwitch from '@/components/form/switch.vue'; import FormSwitch from '@/components/form/switch.vue';
import FormInput from '@/components/form/input.vue'; import FormInput from '@/components/form/input.vue';
import FormButton from '@/components/ui/button.vue'; import FormButton from '@/components/ui/button.vue';
import FormInfo from '@/components/ui/info.vue'; import FormInfo from '@/components/ui/info.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 { fetchInstance } from '@/instance'; import { fetchInstance } from '@/instance';
export default defineComponent({ let uri: string = $ref('');
components: { let enableGithubIntegration: boolean = $ref(false);
FormSwitch, let githubClientId: string | null = $ref(null);
FormInput, let githubClientSecret: string | null = $ref(null);
FormInfo,
FormButton,
FormSuspense,
},
emits: ['info'], async function init() {
data() {
return {
[symbols.PAGE_INFO]: {
title: 'GitHub',
icon: 'fab fa-github'
},
enableGithubIntegration: false,
githubClientId: null,
githubClientSecret: null,
}
},
methods: {
async init() {
const meta = await os.api('admin/meta'); const meta = await os.api('admin/meta');
this.uri = meta.uri; uri = meta.uri;
this.enableGithubIntegration = meta.enableGithubIntegration; enableGithubIntegration = meta.enableGithubIntegration;
this.githubClientId = meta.githubClientId; githubClientId = meta.githubClientId;
this.githubClientSecret = meta.githubClientSecret; githubClientSecret = meta.githubClientSecret;
}, }
save() {
function save() {
os.apiWithDialog('admin/update-meta', { os.apiWithDialog('admin/update-meta', {
enableGithubIntegration: this.enableGithubIntegration, enableGithubIntegration,
githubClientId: this.githubClientId, githubClientId,
githubClientSecret: this.githubClientSecret, githubClientSecret,
}).then(() => { }).then(() => {
fetchInstance(); fetchInstance();
}); });
} }
}
});
</script> </script>

View file

@ -24,7 +24,7 @@
</FormSuspense> </FormSuspense>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import FormSwitch from '@/components/form/switch.vue'; import FormSwitch from '@/components/form/switch.vue';
import FormInput from '@/components/form/input.vue'; import FormInput from '@/components/form/input.vue';
@ -32,49 +32,28 @@ import FormButton from '@/components/ui/button.vue';
import FormInfo from '@/components/ui/info.vue'; import FormInfo from '@/components/ui/info.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 { fetchInstance } from '@/instance'; import { fetchInstance } from '@/instance';
export default defineComponent({ let uri: string = $ref('');
components: { let enableTwitterIntegration: boolean = $ref(false);
FormSwitch, let twitterConsumerKey: string | null = $ref(null);
FormInput, let twitterConsumerSecret: string | null = $ref(null);
FormInfo,
FormButton,
FormSuspense,
},
emits: ['info'], async function init() {
data() {
return {
[symbols.PAGE_INFO]: {
title: 'Twitter',
icon: 'fab fa-twitter'
},
enableTwitterIntegration: false,
twitterConsumerKey: null,
twitterConsumerSecret: null,
}
},
methods: {
async init() {
const meta = await os.api('admin/meta'); const meta = await os.api('admin/meta');
this.uri = meta.uri; uri = meta.uri;
this.enableTwitterIntegration = meta.enableTwitterIntegration; enableTwitterIntegration = meta.enableTwitterIntegration;
this.twitterConsumerKey = meta.twitterConsumerKey; twitterConsumerKey = meta.twitterConsumerKey;
this.twitterConsumerSecret = meta.twitterConsumerSecret; twitterConsumerSecret = meta.twitterConsumerSecret;
}, }
save() {
function save() {
os.apiWithDialog('admin/update-meta', { os.apiWithDialog('admin/update-meta', {
enableTwitterIntegration: this.enableTwitterIntegration, enableTwitterIntegration,
twitterConsumerKey: this.twitterConsumerKey, twitterConsumerKey,
twitterConsumerSecret: this.twitterConsumerSecret, twitterConsumerSecret,
}).then(() => { }).then(() => {
fetchInstance(); fetchInstance();
}); });
} }
}
});
</script> </script>

View file

@ -4,69 +4,52 @@
<FormFolder class="_formBlock"> <FormFolder class="_formBlock">
<template #icon><i class="fab fa-twitter"></i></template> <template #icon><i class="fab fa-twitter"></i></template>
<template #label>Twitter</template> <template #label>Twitter</template>
<template #suffix>{{ enableTwitterIntegration ? $ts.enabled : $ts.disabled }}</template> <template #suffix>{{ enableTwitterIntegration ? i18n.ts.enabled : i18n.ts.disabled }}</template>
<XTwitter/> <XTwitter/>
</FormFolder> </FormFolder>
<FormFolder to="/admin/integrations/github" class="_formBlock"> <FormFolder class="_formBlock">
<template #icon><i class="fab fa-github"></i></template> <template #icon><i class="fab fa-github"></i></template>
<template #label>GitHub</template> <template #label>GitHub</template>
<template #suffix>{{ enableGithubIntegration ? $ts.enabled : $ts.disabled }}</template> <template #suffix>{{ enableGithubIntegration ? i18n.ts.enabled : i18n.ts.disabled }}</template>
<XGithub/> <XGithub/>
</FormFolder> </FormFolder>
<FormFolder to="/admin/integrations/discord" class="_formBlock"> <FormFolder class="_formBlock">
<template #icon><i class="fab fa-discord"></i></template> <template #icon><i class="fab fa-discord"></i></template>
<template #label>Discord</template> <template #label>Discord</template>
<template #suffix>{{ enableDiscordIntegration ? $ts.enabled : $ts.disabled }}</template> <template #suffix>{{ enableDiscordIntegration ? i18n.ts.enabled : i18n.ts.disabled }}</template>
<XDiscord/> <XDiscord/>
</FormFolder> </FormFolder>
</FormSuspense> </FormSuspense>
</MkSpacer> </MkSpacer>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { } from 'vue';
import FormFolder from '@/components/form/folder.vue'; import FormFolder from '@/components/form/folder.vue';
import FormSecion from '@/components/form/section.vue';
import FormSuspense from '@/components/form/suspense.vue'; import FormSuspense from '@/components/form/suspense.vue';
import XTwitter from './integrations.twitter.vue'; import XTwitter from './integrations.twitter.vue';
import XGithub from './integrations.github.vue'; import XGithub from './integrations.github.vue';
import XDiscord from './integrations.discord.vue'; import XDiscord from './integrations.discord.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 { i18n } from '@/i18n';
export default defineComponent({ let enableTwitterIntegration: boolean = $ref(false);
components: { let enableGithubIntegration: boolean = $ref(false);
FormFolder, let enableDiscordIntegration: boolean = $ref(false);
FormSecion,
FormSuspense,
XTwitter,
XGithub,
XDiscord,
},
emits: ['info'], async function init() {
const meta = await os.api('admin/meta');
enableTwitterIntegration = meta.enableTwitterIntegration;
enableGithubIntegration = meta.enableGithubIntegration;
enableDiscordIntegration = meta.enableDiscordIntegration;
}
data() { defineExpose({
return {
[symbols.PAGE_INFO]: { [symbols.PAGE_INFO]: {
title: this.$ts.integration, title: i18n.ts.integration,
icon: 'fas fa-share-alt', icon: 'fas fa-share-alt',
bg: 'var(--bg)', bg: 'var(--bg)',
},
enableTwitterIntegration: false,
enableGithubIntegration: false,
enableDiscordIntegration: false,
}
},
methods: {
async init() {
const meta = await os.api('admin/meta');
this.enableTwitterIntegration = meta.enableTwitterIntegration;
this.enableGithubIntegration = meta.enableGithubIntegration;
this.enableDiscordIntegration = meta.enableDiscordIntegration;
},
} }
}); });
</script> </script>