From 8480ced256f0822af001e49ee145974d527613e8 Mon Sep 17 00:00:00 2001
From: Namekuji <nmkj@wahh.foo>
Date: Wed, 31 May 2023 01:14:13 -0400
Subject: [PATCH] remove empty form input

---
 .../src/server/api/endpoints/i/known-as.ts    | 16 +++---
 .../src/server/api/endpoints/i/move.ts        | 10 ++--
 .../client/src/pages/settings/migration.vue   | 55 ++++++++++++++-----
 3 files changed, 52 insertions(+), 29 deletions(-)

diff --git a/packages/backend/src/server/api/endpoints/i/known-as.ts b/packages/backend/src/server/api/endpoints/i/known-as.ts
index d4d9061b30..0d0c06180a 100644
--- a/packages/backend/src/server/api/endpoints/i/known-as.ts
+++ b/packages/backend/src/server/api/endpoints/i/known-as.ts
@@ -38,14 +38,14 @@ export const meta = {
 			id: "bf326f31-d430-4f97-9933-5d61e4d48a23",
 		},
 		alreadyMoved: {
-			message: 'You have already moved your account.',
-			code: 'ALREADY_MOVED',
-			id: '56f20ec9-fd06-4fa5-841b-edd6d7d4fa31',
+			message: "You have already moved your account.",
+			code: "ALREADY_MOVED",
+			id: "56f20ec9-fd06-4fa5-841b-edd6d7d4fa31",
 		},
 		yourself: {
-			message: 'You can\'t set yourself as your own alias.',
-			code: 'FORBIDDEN_TO_SET_YOURSELF',
-			id: '25c90186-4ab0-49c8-9bba-a1fa6c202ba4',
+			message: "You can't set yourself as your own alias.",
+			code: "FORBIDDEN_TO_SET_YOURSELF",
+			id: "25c90186-4ab0-49c8-9bba-a1fa6c202ba4",
 		},
 	},
 } as const;
@@ -54,10 +54,10 @@ export const paramDef = {
 	type: "object",
 	properties: {
 		alsoKnownAs: {
-			type: 'array',
+			type: "array",
 			maxItems: 10,
 			uniqueItems: true,
-			items: { type: 'string' },
+			items: { type: "string" },
 		},
 	},
 	required: ["alsoKnownAs"],
diff --git a/packages/backend/src/server/api/endpoints/i/move.ts b/packages/backend/src/server/api/endpoints/i/move.ts
index ba2360b196..d972aaf1d9 100644
--- a/packages/backend/src/server/api/endpoints/i/move.ts
+++ b/packages/backend/src/server/api/endpoints/i/move.ts
@@ -98,12 +98,10 @@ export default define(meta, paramDef, async (ps, user) => {
 	const { username, host } = parse(ps.moveToAccount);
 	if (!host) throw new ApiError(meta.errors.notRemote);
 
-	const moveTo: User = await resolveUser(username, host).catch(
-		(e) => {
-			apiLogger.warn(`failed to resolve remote user: ${e}`);
-			throw new ApiError(meta.errors.noSuchMoveTarget);
-		},
-	);
+	const moveTo: User = await resolveUser(username, host).catch((e) => {
+		apiLogger.warn(`failed to resolve remote user: ${e}`);
+		throw new ApiError(meta.errors.noSuchMoveTarget);
+	});
 	let fromUrl: string | null = user.uri;
 	if (!fromUrl) {
 		fromUrl = `${config.url}/users/${user.id}`;
diff --git a/packages/client/src/pages/settings/migration.vue b/packages/client/src/pages/settings/migration.vue
index 610d1ce1fe..df65e6e25c 100644
--- a/packages/client/src/pages/settings/migration.vue
+++ b/packages/client/src/pages/settings/migration.vue
@@ -2,9 +2,13 @@
 	<div class="_formRoot">
 		<FormSection>
 			<template #label>{{ i18n.ts.moveTo }}</template>
-			<FormInfo warn class="_formBlock">{{ i18n.ts.moveAccountDescription }}</FormInfo>
+			<FormInfo warn class="_formBlock">{{
+				i18n.ts.moveAccountDescription
+			}}</FormInfo>
 			<FormInput v-model="moveToAccount" class="_formBlock">
-				<template #prefix><i class="ph-airplane-takeoff ph-bold ph-lg"></i></template>
+				<template #prefix
+					><i class="ph-airplane-takeoff ph-bold ph-lg"></i
+				></template>
 				<template #label>{{ i18n.ts.moveToLabel }}</template>
 			</FormInput>
 			<FormButton primary danger @click="move(moveToAccount)">
@@ -14,14 +18,30 @@
 
 		<FormSection>
 			<template #label>{{ i18n.ts.moveFrom }}</template>
-			<FormInfo warn class="_formBlock">{{ i18n.ts.moveFromDescription }}</FormInfo>
-			<FormInput v-for="(_, i) in accountAlias" v-model="accountAlias[i]" class="_formBlock">
-				<template #prefix><i class="ph-airplane-landing ph-bold ph-lg"></i></template>
-				<template #label>{{ `#${i + 1} ${i18n.ts.moveFromLabel}` }}</template>
+			<FormInfo warn class="_formBlock">{{
+				i18n.ts.moveFromDescription
+			}}</FormInfo>
+			<FormInput
+				v-for="(_, i) in accountAlias"
+				v-model="accountAlias[i]"
+				class="_formBlock"
+			>
+				<template #prefix
+					><i class="ph-airplane-landing ph-bold ph-lg"></i
+				></template>
+				<template #label>{{
+					`#${i + 1} ${i18n.ts.moveFromLabel}`
+				}}</template>
 			</FormInput>
-			<FormButton class="button" :disabled="accountAlias.length >= 10" inline style="margin-right: 8px" @click="add"><i
-					class="ph-plus ph-bold ph-lg"></i>
-				{{ i18n.ts.add }}</FormButton>
+			<FormButton
+				class="button"
+				:disabled="accountAlias.length >= 10"
+				inline
+				style="margin-right: 8px"
+				@click="add"
+				><i class="ph-plus ph-bold ph-lg"></i>
+				{{ i18n.ts.add }}</FormButton
+			>
 			<FormButton class="button" inline primary @click="save">
 				<i class="ph-floppy-disk-back ph-bold ph-lg"></i>
 				{{ i18n.ts.save }}
@@ -39,7 +59,7 @@ import * as os from "@/os";
 import { i18n } from "@/i18n";
 import { definePageMetadata } from "@/scripts/page-metadata";
 import { $i } from "@/account";
-import { toString } from 'calckey-js/built/acct';
+import { toString } from "calckey-js/built/acct";
 
 let moveToAccount = $ref("");
 let accountAlias = $ref([""]);
@@ -48,21 +68,26 @@ await init();
 
 async function init() {
 	if ($i?.alsoKnownAs && $i.alsoKnownAs.length > 0) {
-		const aka = await os.api('users/show', { userIds: $i.alsoKnownAs });
-		accountAlias = (aka && aka.length > 0) ? aka.map(user => `@${toString(user)}`) : [''];
+		const aka = await os.api("users/show", { userIds: $i.alsoKnownAs });
+		accountAlias =
+			aka && aka.length > 0
+				? aka.map((user) => `@${toString(user)}`)
+				: [""];
+	} else {
+		accountAlias = [""];
 	}
 }
 
 async function save(): Promise<void> {
-	const i = os.apiWithDialog("i/known-as", {
-		alsoKnownAs: accountAlias.map(e => e.trim()).filter(e => e !== ""),
+	const i = await os.apiWithDialog("i/known-as", {
+		alsoKnownAs: accountAlias.map((e) => e.trim()).filter((e) => e !== ""),
 	});
 	$i.alsoKnownAs = i.alsoKnownAs;
 	await init();
 }
 
 function add(): void {
-	accountAlias.push('');
+	accountAlias.push("");
 }
 
 async function move(account): Promise<void> {