Refactor account-info to use Composition API (#8568)

* refactor(client): refactor account-info  to use Composition API

* fix(client): use mounted hook for initial data

* fix(client): switch to non-null assertion for account check
This commit is contained in:
Andreas Nedbal 2022-05-04 03:16:14 +02:00 committed by GitHub
parent c72f5e2773
commit 7154ad5a73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 58 deletions

View File

@ -7,163 +7,150 @@
<FormSection> <FormSection>
<MkKeyValue> <MkKeyValue>
<template #key>{{ $ts.registeredDate }}</template> <template #key>{{ i18n.ts.registeredDate }}</template>
<template #value><MkTime :time="$i.createdAt" mode="detail"/></template> <template #value><MkTime :time="$i.createdAt" mode="detail"/></template>
</MkKeyValue> </MkKeyValue>
</FormSection> </FormSection>
<FormSection v-if="stats"> <FormSection v-if="stats">
<template #label>{{ $ts.statistics }}</template> <template #label>{{ i18n.ts.statistics }}</template>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.notesCount }}</template> <template #key>{{ i18n.ts.notesCount }}</template>
<template #value>{{ number(stats.notesCount) }}</template> <template #value>{{ number(stats.notesCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.repliesCount }}</template> <template #key>{{ i18n.ts.repliesCount }}</template>
<template #value>{{ number(stats.repliesCount) }}</template> <template #value>{{ number(stats.repliesCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.renotesCount }}</template> <template #key>{{ i18n.ts.renotesCount }}</template>
<template #value>{{ number(stats.renotesCount) }}</template> <template #value>{{ number(stats.renotesCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.repliedCount }}</template> <template #key>{{ i18n.ts.repliedCount }}</template>
<template #value>{{ number(stats.repliedCount) }}</template> <template #value>{{ number(stats.repliedCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.renotedCount }}</template> <template #key>{{ i18n.ts.renotedCount }}</template>
<template #value>{{ number(stats.renotedCount) }}</template> <template #value>{{ number(stats.renotedCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.pollVotesCount }}</template> <template #key>{{ i18n.ts.pollVotesCount }}</template>
<template #value>{{ number(stats.pollVotesCount) }}</template> <template #value>{{ number(stats.pollVotesCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.pollVotedCount }}</template> <template #key>{{ i18n.ts.pollVotedCount }}</template>
<template #value>{{ number(stats.pollVotedCount) }}</template> <template #value>{{ number(stats.pollVotedCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.sentReactionsCount }}</template> <template #key>{{ i18n.ts.sentReactionsCount }}</template>
<template #value>{{ number(stats.sentReactionsCount) }}</template> <template #value>{{ number(stats.sentReactionsCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.receivedReactionsCount }}</template> <template #key>{{ i18n.ts.receivedReactionsCount }}</template>
<template #value>{{ number(stats.receivedReactionsCount) }}</template> <template #value>{{ number(stats.receivedReactionsCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.noteFavoritesCount }}</template> <template #key>{{ i18n.ts.noteFavoritesCount }}</template>
<template #value>{{ number(stats.noteFavoritesCount) }}</template> <template #value>{{ number(stats.noteFavoritesCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.followingCount }}</template> <template #key>{{ i18n.ts.followingCount }}</template>
<template #value>{{ number(stats.followingCount) }}</template> <template #value>{{ number(stats.followingCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.followingCount }} ({{ $ts.local }})</template> <template #key>{{ i18n.ts.followingCount }} ({{ i18n.ts.local }})</template>
<template #value>{{ number(stats.localFollowingCount) }}</template> <template #value>{{ number(stats.localFollowingCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.followingCount }} ({{ $ts.remote }})</template> <template #key>{{ i18n.ts.followingCount }} ({{ i18n.ts.remote }})</template>
<template #value>{{ number(stats.remoteFollowingCount) }}</template> <template #value>{{ number(stats.remoteFollowingCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.followersCount }}</template> <template #key>{{ i18n.ts.followersCount }}</template>
<template #value>{{ number(stats.followersCount) }}</template> <template #value>{{ number(stats.followersCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.followersCount }} ({{ $ts.local }})</template> <template #key>{{ i18n.ts.followersCount }} ({{ i18n.ts.local }})</template>
<template #value>{{ number(stats.localFollowersCount) }}</template> <template #value>{{ number(stats.localFollowersCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.followersCount }} ({{ $ts.remote }})</template> <template #key>{{ i18n.ts.followersCount }} ({{ i18n.ts.remote }})</template>
<template #value>{{ number(stats.remoteFollowersCount) }}</template> <template #value>{{ number(stats.remoteFollowersCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.pageLikesCount }}</template> <template #key>{{ i18n.ts.pageLikesCount }}</template>
<template #value>{{ number(stats.pageLikesCount) }}</template> <template #value>{{ number(stats.pageLikesCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.pageLikedCount }}</template> <template #key>{{ i18n.ts.pageLikedCount }}</template>
<template #value>{{ number(stats.pageLikedCount) }}</template> <template #value>{{ number(stats.pageLikedCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.driveFilesCount }}</template> <template #key>{{ i18n.ts.driveFilesCount }}</template>
<template #value>{{ number(stats.driveFilesCount) }}</template> <template #value>{{ number(stats.driveFilesCount) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>{{ $ts.driveUsage }}</template> <template #key>{{ i18n.ts.driveUsage }}</template>
<template #value>{{ bytes(stats.driveUsage) }}</template> <template #value>{{ bytes(stats.driveUsage) }}</template>
</MkKeyValue> </MkKeyValue>
</FormSection> </FormSection>
<FormSection> <FormSection>
<template #label>{{ $ts.other }}</template> <template #label>{{ i18n.ts.other }}</template>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>emailVerified</template> <template #key>emailVerified</template>
<template #value>{{ $i.emailVerified ? $ts.yes : $ts.no }}</template> <template #value>{{ $i.emailVerified ? i18n.ts.yes : i18n.ts.no }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>twoFactorEnabled</template> <template #key>twoFactorEnabled</template>
<template #value>{{ $i.twoFactorEnabled ? $ts.yes : $ts.no }}</template> <template #value>{{ $i.twoFactorEnabled ? i18n.ts.yes : i18n.ts.no }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>securityKeys</template> <template #key>securityKeys</template>
<template #value>{{ $i.securityKeys ? $ts.yes : $ts.no }}</template> <template #value>{{ $i.securityKeys ? i18n.ts.yes : i18n.ts.no }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>usePasswordLessLogin</template> <template #key>usePasswordLessLogin</template>
<template #value>{{ $i.usePasswordLessLogin ? $ts.yes : $ts.no }}</template> <template #value>{{ $i.usePasswordLessLogin ? i18n.ts.yes : i18n.ts.no }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>isModerator</template> <template #key>isModerator</template>
<template #value>{{ $i.isModerator ? $ts.yes : $ts.no }}</template> <template #value>{{ $i.isModerator ? i18n.ts.yes : i18n.ts.no }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>isAdmin</template> <template #key>isAdmin</template>
<template #value>{{ $i.isAdmin ? $ts.yes : $ts.no }}</template> <template #value>{{ $i.isAdmin ? i18n.ts.yes : i18n.ts.no }}</template>
</MkKeyValue> </MkKeyValue>
</FormSection> </FormSection>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineAsyncComponent, defineComponent } from 'vue'; import { defineExpose, onMounted, ref } from 'vue';
import FormSection from '@/components/form/section.vue'; import FormSection from '@/components/form/section.vue';
import MkKeyValue from '@/components/key-value.vue'; import MkKeyValue from '@/components/key-value.vue';
import * as os from '@/os'; import * as os from '@/os';
import number from '@/filters/number'; import number from '@/filters/number';
import bytes from '@/filters/bytes'; import bytes from '@/filters/bytes';
import * as symbols from '@/symbols'; import * as symbols from '@/symbols';
import { $i } from '@/account';
import { i18n } from '@/i18n';
export default defineComponent({ const stats = ref<any>({});
components: {
FormSection,
MkKeyValue,
},
emits: ['info'], onMounted(() => {
data() {
return {
[symbols.PAGE_INFO]: {
title: this.$ts.accountInfo,
icon: 'fas fa-info-circle'
},
stats: null
}
},
mounted() {
os.api('users/stats', { os.api('users/stats', {
userId: this.$i.id userId: $i!.id
}).then(stats => { }).then(response => {
this.stats = stats; stats.value = response;
});
}); });
},
methods: { defineExpose({
number, [symbols.PAGE_INFO]: {
bytes, title: i18n.ts.accountInfo,
icon: 'fas fa-info-circle'
} }
}); });
</script> </script>