From 1aec738200137731e4f02c821f216a8d776ddf5a Mon Sep 17 00:00:00 2001 From: naskya Date: Mon, 8 Jan 2024 17:03:39 +0900 Subject: [PATCH] refactor (client): use ?? to check null/undefined --- packages/client/src/account.ts | 2 +- .../src/components/MkAbuseReportWindow.vue | 2 +- .../client/src/components/MkAutocomplete.vue | 2 +- packages/client/src/components/MkCaptcha.vue | 4 +- .../src/components/MkDateSeparatedList.vue | 2 +- packages/client/src/components/MkDialog.vue | 8 ++- .../client/src/components/MkDrive.file.vue | 2 +- packages/client/src/components/MkDrive.vue | 2 +- .../client/src/components/MkEmojiPicker.vue | 6 +- .../client/src/components/MkFollowButton.vue | 6 +- .../client/src/components/MkFormDialog.vue | 18 +++--- .../src/components/MkInstanceCardMini.vue | 2 +- .../src/components/MkInstanceTicker.vue | 2 +- packages/client/src/components/MkMention.vue | 2 +- packages/client/src/components/MkMenu.vue | 12 ++-- .../client/src/components/MkMiniChart.vue | 2 +- packages/client/src/components/MkNote.vue | 6 +- packages/client/src/components/MkNoteSub.vue | 6 +- packages/client/src/components/MkNotes.vue | 2 +- .../MkNotificationSettingWindow.vue | 2 +- .../client/src/components/MkNotifications.vue | 2 +- packages/client/src/components/MkNumber.vue | 2 +- .../client/src/components/MkPagination.vue | 4 +- packages/client/src/components/MkPostForm.vue | 20 +++---- .../src/components/MkPostFormAttaches.vue | 2 +- .../client/src/components/MkReactionIcon.vue | 2 +- packages/client/src/components/MkSignin.vue | 2 +- packages/client/src/components/MkSignup.vue | 28 ++++----- .../src/components/MkTokenGenerateWindow.vue | 4 +- .../src/components/MkTutorialDialog.vue | 2 +- .../client/src/components/MkUrlPreview.vue | 12 ++-- .../client/src/components/global/MkAcct.vue | 2 +- .../src/components/global/MkUserName.vue | 2 +- packages/client/src/components/mfm.ts | 58 +++++++++---------- .../src/components/page/page.counter.vue | 2 +- packages/client/src/directives/size.ts | 2 +- packages/client/src/filters/user.ts | 2 +- packages/client/src/init.ts | 6 +- packages/client/src/os.ts | 12 ++-- packages/client/src/pages/about.emojis.vue | 2 +- packages/client/src/pages/about.vue | 10 ++-- packages/client/src/pages/admin/_header_.vue | 2 +- .../client/src/pages/admin/bot-protection.vue | 2 +- packages/client/src/pages/admin/hashtags.vue | 2 +- packages/client/src/pages/admin/index.vue | 6 +- .../client/src/pages/admin/instance-block.vue | 4 +- packages/client/src/pages/admin/relays.vue | 4 +- packages/client/src/pages/auth.vue | 2 +- packages/client/src/pages/emojis.emoji.vue | 2 +- packages/client/src/pages/follow.vue | 2 +- packages/client/src/pages/gallery/post.vue | 4 +- packages/client/src/pages/instance-info.vue | 10 ++-- .../pages/messaging/messaging-room.form.vue | 6 +- .../src/pages/messaging/messaging-room.vue | 4 +- packages/client/src/pages/note.vue | 4 +- packages/client/src/pages/page.vue | 10 ++-- .../src/pages/settings/notifications.vue | 2 +- .../pages/settings/preferences-backups.vue | 2 +- packages/client/src/pages/settings/sounds.vue | 2 +- .../client/src/pages/settings/webhook.vue | 2 +- packages/client/src/pages/user/home.vue | 4 +- .../client/src/pages/welcome.entrance.a.vue | 6 +- .../client/src/pages/welcome.entrance.b.vue | 2 +- .../client/src/pages/welcome.entrance.c.vue | 2 +- packages/client/src/pizzax.ts | 14 ++--- packages/client/src/plugin.ts | 2 +- packages/client/src/reactiveAccount.ts | 6 +- packages/client/src/scripts/aiscript/api.ts | 2 +- .../client/src/scripts/check-word-mute.ts | 2 +- packages/client/src/scripts/chiptune2.ts | 4 +- .../client/src/scripts/collect-page-vars.ts | 8 +-- packages/client/src/scripts/emojilist.ts | 12 ++-- .../client/src/scripts/format-time-string.ts | 12 +++- packages/client/src/scripts/get-note-menu.ts | 22 +++---- .../client/src/scripts/get-note-summary.ts | 2 +- packages/client/src/scripts/get-user-menu.ts | 4 +- packages/client/src/scripts/get-user-name.ts | 2 +- packages/client/src/scripts/hpml/evaluator.ts | 6 +- packages/client/src/scripts/hpml/index.ts | 2 +- packages/client/src/scripts/hpml/lib.ts | 2 +- .../client/src/scripts/hpml/type-checker.ts | 8 +-- packages/client/src/scripts/physics.ts | 2 +- packages/client/src/scripts/scroll.ts | 4 +- packages/client/src/scripts/upload.ts | 4 +- .../client/src/scripts/use-note-capture.ts | 10 ++-- packages/client/src/theme-store.ts | 2 +- packages/client/src/ui/_common_/navbar.vue | 2 +- packages/client/src/ui/_common_/upload.vue | 4 +- packages/client/src/ui/visitor/a.vue | 6 +- packages/client/src/ui/visitor/b.vue | 24 +------- packages/client/src/ui/visitor/kanban.vue | 6 +- packages/client/src/widgets/federation.vue | 2 +- packages/client/src/widgets/server-info.vue | 4 +- 93 files changed, 267 insertions(+), 267 deletions(-) diff --git a/packages/client/src/account.ts b/packages/client/src/account.ts index 5859bdead..2957ab085 100644 --- a/packages/client/src/account.ts +++ b/packages/client/src/account.ts @@ -55,7 +55,7 @@ export async function signout() { export async function getAccounts(): Promise< { id: Account["id"]; token: Account["token"] }[] > { - return (await get("accounts")) || []; + return (await get("accounts")) ?? []; } export async function addAccount(id: Account["id"], token: Account["token"]) { diff --git a/packages/client/src/components/MkAbuseReportWindow.vue b/packages/client/src/components/MkAbuseReportWindow.vue index c6fc768a6..e93b834f8 100644 --- a/packages/client/src/components/MkAbuseReportWindow.vue +++ b/packages/client/src/components/MkAbuseReportWindow.vue @@ -59,7 +59,7 @@ const emit = defineEmits<{ }>(); const uiWindow = ref>(); -const comment = ref(props.initialComment || ""); +const comment = ref(props.initialComment ?? ""); function send() { os.apiWithDialog( diff --git a/packages/client/src/components/MkAutocomplete.vue b/packages/client/src/components/MkAutocomplete.vue index 5fcee6e5a..3a97f4584 100644 --- a/packages/client/src/components/MkAutocomplete.vue +++ b/packages/client/src/components/MkAutocomplete.vue @@ -268,7 +268,7 @@ function exec() { } else if (props.type === "hashtag") { if (!props.q || props.q === "") { hashtags.value = JSON.parse( - localStorage.getItem("hashtags") || "[]", + localStorage.getItem("hashtags") ?? "[]", ); fetching.value = false; } else { diff --git a/packages/client/src/components/MkCaptcha.vue b/packages/client/src/components/MkCaptcha.vue index 146c512fb..76c9b91fe 100644 --- a/packages/client/src/components/MkCaptcha.vue +++ b/packages/client/src/components/MkCaptcha.vue @@ -78,14 +78,14 @@ const src = computed(() => { }); const captcha = computed( - () => window[variable.value] || ({} as unknown as Captcha), + () => window[variable.value] ?? ({} as Captcha), ); if (loaded) { available.value = true; } else { ( - document.getElementById(props.provider) || + document.getElementById(props.provider) ?? document.head.appendChild( Object.assign(document.createElement("script"), { async: true, diff --git a/packages/client/src/components/MkDateSeparatedList.vue b/packages/client/src/components/MkDateSeparatedList.vue index 6699f0313..8dae76ba8 100644 --- a/packages/client/src/components/MkDateSeparatedList.vue +++ b/packages/client/src/components/MkDateSeparatedList.vue @@ -50,7 +50,7 @@ export default defineComponent({ const renderChildren = () => props.items.map((item, i) => { - if (!slots || !slots.default) return; + if (slots == null || slots.default == null) return; const el = slots.default({ item, diff --git a/packages/client/src/components/MkDialog.vue b/packages/client/src/components/MkDialog.vue index a5e553a5e..40332e3d5 100644 --- a/packages/client/src/components/MkDialog.vue +++ b/packages/client/src/components/MkDialog.vue @@ -65,8 +65,10 @@ v-model="inputValue" autofocus :autocomplete="input.autocomplete" - :type="input.type == 'search' ? 'search' : input.type || 'text'" - :placeholder="input.placeholder || undefined" + :type=" + input.type === 'search' ? 'search' : input.type ?? 'text' + " + :placeholder="input.placeholder ?? undefined" :style="{ width: input.type === 'search' ? '300px' : null, }" @@ -294,7 +296,7 @@ const okButtonDisabled = computed(() => { if (props.input) { if (props.input.minLength) { if ( - (inputValue.value || inputValue.value === "") && + inputValue.value != null && (inputValue.value as string).length < props.input.minLength ) { disabledReason.value = "charactersBelow"; diff --git a/packages/client/src/components/MkDrive.file.vue b/packages/client/src/components/MkDrive.file.vue index 5105fc0f0..fce7646e7 100644 --- a/packages/client/src/components/MkDrive.file.vue +++ b/packages/client/src/components/MkDrive.file.vue @@ -185,7 +185,7 @@ function describe() { }, { done: (result) => { - if (!result || result.canceled) return; + if (result == null || result.canceled) return; const comment = result.result; os.api("drive/files/update", { fileId: props.file.id, diff --git a/packages/client/src/components/MkDrive.vue b/packages/client/src/components/MkDrive.vue index 1ca9b2ff0..e22594d9a 100644 --- a/packages/client/src/components/MkDrive.vue +++ b/packages/client/src/components/MkDrive.vue @@ -363,7 +363,7 @@ function urlUpload() { type: "url", placeholder: i18n.ts.uploadFromUrlDescription, }).then(({ canceled, result: url }) => { - if (canceled || !url) return; + if (canceled || url == null) return; os.api("drive/files/upload-from-url", { url, folderId: folder.value ? folder.value.id : undefined, diff --git a/packages/client/src/components/MkEmojiPicker.vue b/packages/client/src/components/MkEmojiPicker.vue index bdd934492..4b0d8702f 100644 --- a/packages/client/src/components/MkEmojiPicker.vue +++ b/packages/client/src/components/MkEmojiPicker.vue @@ -106,7 +106,7 @@ .map((e) => ':' + e.name + ':') " @chosen="chosen" - >{{ category || i18n.ts.other }}{{ category ?? i18n.ts.other }}
@@ -423,7 +423,7 @@ function reset() { function getKey( emoji: string | firefish.entities.CustomEmoji | UnicodeEmojiDef, ): string { - return typeof emoji === "string" ? emoji : emoji.emoji || `:${emoji.name}:`; + return typeof emoji === "string" ? emoji : emoji.emoji ?? `:${emoji.name}:`; } function chosen(emoji: any, ev?: MouseEvent) { @@ -450,7 +450,7 @@ function chosen(emoji: any, ev?: MouseEvent) { } function paste(event: ClipboardEvent) { - const paste = (event.clipboardData || window.clipboardData).getData("text"); + const paste = (event.clipboardData ?? window.clipboardData).getData("text"); if (done(paste)) { event.preventDefault(); } diff --git a/packages/client/src/components/MkFollowButton.vue b/packages/client/src/components/MkFollowButton.vue index f52a685e6..c900d91b6 100644 --- a/packages/client/src/components/MkFollowButton.vue +++ b/packages/client/src/components/MkFollowButton.vue @@ -9,7 +9,7 @@
diff --git a/packages/client/src/components/MkInstanceCardMini.vue b/packages/client/src/components/MkInstanceCardMini.vue index bd7556f12..7654335b7 100644 --- a/packages/client/src/components/MkInstanceCardMini.vue +++ b/packages/client/src/components/MkInstanceCardMini.vue @@ -15,7 +15,7 @@ {{ instance.name ?? instance.host }} {{ instance.host }} / - {{ instance.softwareName || "?" }} + {{ instance.softwareName ?? "?" }} {{ instance.softwareVersion }} diff --git a/packages/client/src/components/MkInstanceTicker.vue b/packages/client/src/components/MkInstanceTicker.vue index 65d7a85cb..1172da991 100644 --- a/packages/client/src/components/MkInstanceTicker.vue +++ b/packages/client/src/components/MkInstanceTicker.vue @@ -33,7 +33,7 @@ const ticker = ref(null); // if no instance data is given, this is for the local instance const instance = props.instance ?? { - faviconUrl: Instance.faviconUrl || Instance.iconUrl || "/favicon.ico", + faviconUrl: Instance.faviconUrl ?? Instance.iconUrl ?? "/favicon.ico", name: instanceName, themeColor: ( document.querySelector( diff --git a/packages/client/src/components/MkMention.vue b/packages/client/src/components/MkMention.vue index dd2c2e564..fccfa2f2a 100644 --- a/packages/client/src/components/MkMention.vue +++ b/packages/client/src/components/MkMention.vue @@ -11,7 +11,7 @@ @{{ username }} @{{ toUnicode(host) }} diff --git a/packages/client/src/components/MkMenu.vue b/packages/client/src/components/MkMenu.vue index 35fb5a6bf..33eb677ba 100644 --- a/packages/client/src/components/MkMenu.vue +++ b/packages/client/src/components/MkMenu.vue @@ -21,7 +21,7 @@ diff --git a/packages/client/src/components/global/MkUserName.vue b/packages/client/src/components/global/MkUserName.vue index 28ce470fd..89af41fcf 100644 --- a/packages/client/src/components/global/MkUserName.vue +++ b/packages/client/src/components/global/MkUserName.vue @@ -2,7 +2,7 @@ { }; export const userName = (user: firefish.entities.User) => { - return user.name || user.username; + return user.name ?? user.username; }; export const userPage = (user: firefish.Acct, path?, absolute = false) => { diff --git a/packages/client/src/init.ts b/packages/client/src/init.ts index 0076e1f1e..c971b38c4 100644 --- a/packages/client/src/init.ts +++ b/packages/client/src/init.ts @@ -123,7 +123,7 @@ function checkForSplash() { // #region Set lang attr const html = document.documentElement; - html.setAttribute("lang", lang || "en-US"); + html.setAttribute("lang", lang ?? "en-US"); html.setAttribute("dir", langmap[lang].rtl === true ? "rtl" : "ltr"); //#endregion @@ -134,7 +134,7 @@ function checkForSplash() { if (loginId) { const target = getUrlWithoutLoginId(location.href); - if (!$i || $i.id !== loginId) { + if ($i == null || $i.id !== loginId) { const account = await getAccountFromId(loginId); if (account) { await login(account.token, target); @@ -437,7 +437,7 @@ function checkForSplash() { if (Date.now() - lastUsedDate > 1000 * 60 * 60 * 2) { toast( i18n.t("welcomeBackWithName", { - name: $i.name || $i.username, + name: $i.name ?? $i.username, }), ); } diff --git a/packages/client/src/os.ts b/packages/client/src/os.ts index f0cb0c905..e90641b12 100644 --- a/packages/client/src/os.ts +++ b/packages/client/src/os.ts @@ -314,7 +314,7 @@ export function confirm(props: { }, { done: (result) => { - resolve(result || { canceled: true }); + resolve(result ?? { canceled: true }); }, }, "closed", @@ -342,7 +342,7 @@ export function yesno(props: { }, { done: (result) => { - resolve(result || { canceled: true }); + resolve(result ?? { canceled: true }); }, }, "closed", @@ -383,7 +383,7 @@ export function inputText(props: { }, { done: (result) => { - resolve(result || { canceled: true }); + resolve(result ?? { canceled: true }); }, }, "closed", @@ -421,7 +421,7 @@ export function inputParagraph(props: { }, { done: (result) => { - resolve(result || { canceled: true }); + resolve(result ?? { canceled: true }); }, }, "closed", @@ -461,7 +461,7 @@ export function inputNumber(props: { }, { done: (result) => { - resolve(result || { canceled: true }); + resolve(result ?? { canceled: true }); }, }, "closed", @@ -553,7 +553,7 @@ export function select( }, { done: (result) => { - resolve(result || { canceled: true }); + resolve(result ?? { canceled: true }); }, }, "closed", diff --git a/packages/client/src/pages/about.emojis.vue b/packages/client/src/pages/about.emojis.vue index 6a33651d5..24bd4cf58 100644 --- a/packages/client/src/pages/about.emojis.vue +++ b/packages/client/src/pages/about.emojis.vue @@ -31,7 +31,7 @@ :key="category" class="emojis" > - +
- {{ $instance.name || host }} + {{ $instance.name ?? host }}
@@ -99,7 +99,7 @@ > {{ i18n.t("_aboutFirefish.donateHost", { - host: $instance.name || host, + host: $instance.name ?? host, }) }} @@ -209,7 +209,7 @@ withDefaults( const stats = ref(null); const instanceIcon = ref(); let iconClicks = 0; -const iconSrc = ref(instance.iconUrl || instance.faviconUrl || "/favicon.ico"); +const iconSrc = ref(instance.faviconUrl ?? instance.iconUrl ?? "/favicon.ico"); const instanceIconAnimation = ref(""); const tabs = ["overview", "emojis", "charts"]; const tab = ref(tabs[0]); @@ -276,8 +276,8 @@ function easterEgg() { setTimeout(() => { if (iconClicks % 6 === 0) { iconSrc.value = - instance.iconUrl || - instance.faviconUrl || + instance.faviconUrl ?? + instance.iconUrl ?? "/favicon.ico"; } else { iconSrc.value = "/static-assets/woozy.png"; diff --git a/packages/client/src/pages/admin/_header_.vue b/packages/client/src/pages/admin/_header_.vue index bdd1ae8c7..fe28ab871 100644 --- a/packages/client/src/pages/admin/_header_.vue +++ b/packages/client/src/pages/admin/_header_.vue @@ -148,7 +148,7 @@ function onTabClick(tab: Tab, ev: MouseEvent): void { } const calcBg = () => { - const rawBg = metadata?.bg || "var(--bg)"; + const rawBg = metadata?.bg ?? "var(--bg)"; const tinyBg = tinycolor( rawBg.startsWith("var(") ? getComputedStyle(document.documentElement).getPropertyValue( diff --git a/packages/client/src/pages/admin/bot-protection.vue b/packages/client/src/pages/admin/bot-protection.vue index 766fdc008..85cd9edb4 100644 --- a/packages/client/src/pages/admin/bot-protection.vue +++ b/packages/client/src/pages/admin/bot-protection.vue @@ -32,7 +32,7 @@ diff --git a/packages/client/src/pages/admin/hashtags.vue b/packages/client/src/pages/admin/hashtags.vue index 12e24e161..d203d2d93 100644 --- a/packages/client/src/pages/admin/hashtags.vue +++ b/packages/client/src/pages/admin/hashtags.vue @@ -47,7 +47,7 @@ async function init() { function save() { os.apiWithDialog("admin/update-meta", { hiddenTags: - hiddenTags.value.split("\n").map((h: string) => h.trim()) || [], + hiddenTags.value.split("\n").map((h: string) => h.trim()) ?? [], }).then(() => { fetchInstance(); }); diff --git a/packages/client/src/pages/admin/index.vue b/packages/client/src/pages/admin/index.vue index 281b99152..53f696d9d 100644 --- a/packages/client/src/pages/admin/index.vue +++ b/packages/client/src/pages/admin/index.vue @@ -5,7 +5,11 @@
{{ - instance.name || `(${i18n.ts.unknown})` + instance.name ?? `(${i18n.ts.unknown})` }}
@@ -51,12 +51,12 @@ diff --git a/packages/client/src/pages/messaging/messaging-room.form.vue b/packages/client/src/pages/messaging/messaging-room.form.vue index da5fff785..7e33ef164 100644 --- a/packages/client/src/pages/messaging/messaging-room.form.vue +++ b/packages/client/src/pages/messaging/messaging-room.form.vue @@ -238,7 +238,7 @@ function clear() { } function saveDraft() { - const drafts = JSON.parse(localStorage.getItem("message_drafts") || "{}"); + const drafts = JSON.parse(localStorage.getItem("message_drafts") ?? "{}"); drafts[draftKey.value] = { updatedAt: new Date(), @@ -252,7 +252,7 @@ function saveDraft() { } function deleteDraft() { - const drafts = JSON.parse(localStorage.getItem("message_drafts") || "{}"); + const drafts = JSON.parse(localStorage.getItem("message_drafts") ?? "{}"); delete drafts[draftKey.value]; @@ -270,7 +270,7 @@ onMounted(() => { new Autocomplete(textEl.value, text); // 書きかけの投稿を復元 - const draft = JSON.parse(localStorage.getItem("message_drafts") || "{}")[ + const draft = JSON.parse(localStorage.getItem("message_drafts") ?? "{}")[ draftKey.value ]; if (draft) { diff --git a/packages/client/src/pages/messaging/messaging-room.vue b/packages/client/src/pages/messaging/messaging-room.vue index b3b20da4c..cf2bea168 100644 --- a/packages/client/src/pages/messaging/messaging-room.vue +++ b/packages/client/src/pages/messaging/messaging-room.vue @@ -11,7 +11,7 @@