From ea41cc6ec0f7b79fc753d37b4586abfef87bf23f Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 4 Jan 2024 15:30:40 +0900 Subject: [PATCH] refactor(frontend): reduce type errors --- packages/frontend/src/account.ts | 5 +++++ packages/frontend/src/pages/my-lists/index.vue | 6 ++++-- packages/frontend/src/pages/my-lists/list.vue | 6 ++++-- .../frontend/src/pages/settings/2fa.qrdialog.vue | 6 ++++-- packages/frontend/src/pages/settings/2fa.vue | 6 ++++-- .../settings/avatar-decoration.decoration.vue | 4 +++- .../pages/settings/avatar-decoration.dialog.vue | 4 +++- .../src/pages/settings/avatar-decoration.vue | 4 +++- packages/frontend/src/pages/settings/drive.vue | 4 +++- packages/frontend/src/pages/settings/email.vue | 16 +++++++++------- .../src/pages/settings/import-export.vue | 2 +- .../frontend/src/pages/settings/migration.vue | 10 ++++++---- .../pages/settings/mute-block.instance-mute.vue | 6 ++++-- .../frontend/src/pages/settings/mute-block.vue | 8 +++++--- .../src/pages/settings/notifications.vue | 8 +++++--- packages/frontend/src/pages/settings/other.vue | 12 +++--------- packages/frontend/src/pages/settings/privacy.vue | 8 +++++--- packages/frontend/src/pages/settings/profile.vue | 6 ++++-- packages/frontend/src/pages/settings/roles.vue | 8 ++------ 19 files changed, 77 insertions(+), 52 deletions(-) diff --git a/packages/frontend/src/account.ts b/packages/frontend/src/account.ts index 1e5f38cf1c..25af298910 100644 --- a/packages/frontend/src/account.ts +++ b/packages/frontend/src/account.ts @@ -26,6 +26,11 @@ export const $i = accountData ? reactive(JSON.parse(accountData) as Account) : n export const iAmModerator = $i != null && ($i.isAdmin === true || $i.isModerator === true); export const iAmAdmin = $i != null && $i.isAdmin; +export function signinRequired() { + if ($i == null) throw new Error('signin required'); + return $i; +} + export let notesCount = $i == null ? 0 : $i.notesCount; export function incNotesCount() { notesCount++; diff --git a/packages/frontend/src/pages/my-lists/index.vue b/packages/frontend/src/pages/my-lists/index.vue index 0abfb15d98..14e2315843 100644 --- a/packages/frontend/src/pages/my-lists/index.vue +++ b/packages/frontend/src/pages/my-lists/index.vue @@ -19,7 +19,7 @@ SPDX-License-Identifier: AGPL-3.0-only
-
{{ list.name }} ({{ i18n.t('nUsers', { n: `${list.userIds.length}/${$i?.policies['userEachUserListsLimit']}` }) }})
+
{{ list.name }} ({{ i18n.t('nUsers', { n: `${list.userIds.length}/${$i.policies['userEachUserListsLimit']}` }) }})
@@ -37,7 +37,9 @@ import { i18n } from '@/i18n.js'; import { definePageMetadata } from '@/scripts/page-metadata.js'; import { userListsCache } from '@/cache.js'; import { infoImageUrl } from '@/instance.js'; -import { $i } from '@/account.js'; +import { signinRequired } from '@/account.js'; + +const $i = signinRequired(); const items = computed(() => userListsCache.value.value ?? []); diff --git a/packages/frontend/src/pages/my-lists/list.vue b/packages/frontend/src/pages/my-lists/list.vue index cf9da02868..482fdcd8f2 100644 --- a/packages/frontend/src/pages/my-lists/list.vue +++ b/packages/frontend/src/pages/my-lists/list.vue @@ -25,7 +25,7 @@ SPDX-License-Identifier: AGPL-3.0-only - +
{{ i18n.ts.addUser }} @@ -66,10 +66,12 @@ import MkSwitch from '@/components/MkSwitch.vue'; import MkFolder from '@/components/MkFolder.vue'; import MkInput from '@/components/MkInput.vue'; import { userListsCache } from '@/cache.js'; -import { $i } from '@/account.js'; +import { signinRequired } from '@/account.js'; import { defaultStore } from '@/store.js'; import MkPagination from '@/components/MkPagination.vue'; +const $i = signinRequired(); + const { enableInfiniteScroll, } = defaultStore.reactiveState; diff --git a/packages/frontend/src/pages/settings/2fa.qrdialog.vue b/packages/frontend/src/pages/settings/2fa.qrdialog.vue index 4641b49103..3d7bb06da2 100644 --- a/packages/frontend/src/pages/settings/2fa.qrdialog.vue +++ b/packages/frontend/src/pages/settings/2fa.qrdialog.vue @@ -110,7 +110,9 @@ import * as os from '@/os.js'; import MkFolder from '@/components/MkFolder.vue'; import MkInfo from '@/components/MkInfo.vue'; import { confetti } from '@/scripts/confetti.js'; -import { $i } from '@/account.js'; +import { signinRequired } from '@/account.js'; + +const $i = signinRequired(); defineProps<{ twoFactorData: { @@ -151,7 +153,7 @@ function downloadBackupCodes() { const txtBlob = new Blob([backupCodes.value.join('\n')], { type: 'text/plain' }); const dummya = document.createElement('a'); dummya.href = URL.createObjectURL(txtBlob); - dummya.download = `${$i?.username}-2fa-backup-codes.txt`; + dummya.download = `${$i.username}-2fa-backup-codes.txt`; dummya.click(); } } diff --git a/packages/frontend/src/pages/settings/2fa.vue b/packages/frontend/src/pages/settings/2fa.vue index 4c165ef4ee..35331738fd 100644 --- a/packages/frontend/src/pages/settings/2fa.vue +++ b/packages/frontend/src/pages/settings/2fa.vue @@ -80,9 +80,11 @@ import MkSwitch from '@/components/MkSwitch.vue'; import FormSection from '@/components/form/section.vue'; import MkFolder from '@/components/MkFolder.vue'; import * as os from '@/os.js'; -import { $i } from '@/account.js'; +import { signinRequired } from '@/account.js'; import { i18n } from '@/i18n.js'; +const $i = signinRequired(); + // メモ: 各エンドポイントはmeUpdatedを発行するため、refreshAccountは不要 withDefaults(defineProps<{ @@ -91,7 +93,7 @@ withDefaults(defineProps<{ first: false, }); -const usePasswordLessLogin = computed(() => $i?.usePasswordLessLogin ?? false); +const usePasswordLessLogin = computed(() => $i.usePasswordLessLogin ?? false); async function registerTOTP(): Promise { const auth = await os.authenticateDialog(); diff --git a/packages/frontend/src/pages/settings/avatar-decoration.decoration.vue b/packages/frontend/src/pages/settings/avatar-decoration.decoration.vue index 9c95b5547e..29586ad5f1 100644 --- a/packages/frontend/src/pages/settings/avatar-decoration.decoration.vue +++ b/packages/frontend/src/pages/settings/avatar-decoration.decoration.vue @@ -16,7 +16,9 @@ SPDX-License-Identifier: AGPL-3.0-only