remove empty form input

This commit is contained in:
Namekuji 2023-05-31 01:14:13 -04:00
parent c321a6ee39
commit 8480ced256
No known key found for this signature in database
GPG key ID: B541BD6E646CABC7
3 changed files with 52 additions and 29 deletions

View file

@ -38,14 +38,14 @@ export const meta = {
id: "bf326f31-d430-4f97-9933-5d61e4d48a23", id: "bf326f31-d430-4f97-9933-5d61e4d48a23",
}, },
alreadyMoved: { alreadyMoved: {
message: 'You have already moved your account.', message: "You have already moved your account.",
code: 'ALREADY_MOVED', code: "ALREADY_MOVED",
id: '56f20ec9-fd06-4fa5-841b-edd6d7d4fa31', id: "56f20ec9-fd06-4fa5-841b-edd6d7d4fa31",
}, },
yourself: { yourself: {
message: 'You can\'t set yourself as your own alias.', message: "You can't set yourself as your own alias.",
code: 'FORBIDDEN_TO_SET_YOURSELF', code: "FORBIDDEN_TO_SET_YOURSELF",
id: '25c90186-4ab0-49c8-9bba-a1fa6c202ba4', id: "25c90186-4ab0-49c8-9bba-a1fa6c202ba4",
}, },
}, },
} as const; } as const;
@ -54,10 +54,10 @@ export const paramDef = {
type: "object", type: "object",
properties: { properties: {
alsoKnownAs: { alsoKnownAs: {
type: 'array', type: "array",
maxItems: 10, maxItems: 10,
uniqueItems: true, uniqueItems: true,
items: { type: 'string' }, items: { type: "string" },
}, },
}, },
required: ["alsoKnownAs"], required: ["alsoKnownAs"],

View file

@ -98,12 +98,10 @@ export default define(meta, paramDef, async (ps, user) => {
const { username, host } = parse(ps.moveToAccount); const { username, host } = parse(ps.moveToAccount);
if (!host) throw new ApiError(meta.errors.notRemote); if (!host) throw new ApiError(meta.errors.notRemote);
const moveTo: User = await resolveUser(username, host).catch( const moveTo: User = await resolveUser(username, host).catch((e) => {
(e) => {
apiLogger.warn(`failed to resolve remote user: ${e}`); apiLogger.warn(`failed to resolve remote user: ${e}`);
throw new ApiError(meta.errors.noSuchMoveTarget); throw new ApiError(meta.errors.noSuchMoveTarget);
}, });
);
let fromUrl: string | null = user.uri; let fromUrl: string | null = user.uri;
if (!fromUrl) { if (!fromUrl) {
fromUrl = `${config.url}/users/${user.id}`; fromUrl = `${config.url}/users/${user.id}`;

View file

@ -2,9 +2,13 @@
<div class="_formRoot"> <div class="_formRoot">
<FormSection> <FormSection>
<template #label>{{ i18n.ts.moveTo }}</template> <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"> <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> <template #label>{{ i18n.ts.moveToLabel }}</template>
</FormInput> </FormInput>
<FormButton primary danger @click="move(moveToAccount)"> <FormButton primary danger @click="move(moveToAccount)">
@ -14,14 +18,30 @@
<FormSection> <FormSection>
<template #label>{{ i18n.ts.moveFrom }}</template> <template #label>{{ i18n.ts.moveFrom }}</template>
<FormInfo warn class="_formBlock">{{ i18n.ts.moveFromDescription }}</FormInfo> <FormInfo warn class="_formBlock">{{
<FormInput v-for="(_, i) in accountAlias" v-model="accountAlias[i]" class="_formBlock"> i18n.ts.moveFromDescription
<template #prefix><i class="ph-airplane-landing ph-bold ph-lg"></i></template> }}</FormInfo>
<template #label>{{ `#${i + 1} ${i18n.ts.moveFromLabel}` }}</template> <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> </FormInput>
<FormButton class="button" :disabled="accountAlias.length >= 10" inline style="margin-right: 8px" @click="add"><i <FormButton
class="ph-plus ph-bold ph-lg"></i> class="button"
{{ i18n.ts.add }}</FormButton> :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"> <FormButton class="button" inline primary @click="save">
<i class="ph-floppy-disk-back ph-bold ph-lg"></i> <i class="ph-floppy-disk-back ph-bold ph-lg"></i>
{{ i18n.ts.save }} {{ i18n.ts.save }}
@ -39,7 +59,7 @@ import * as os from "@/os";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
import { $i } from "@/account"; import { $i } from "@/account";
import { toString } from 'calckey-js/built/acct'; import { toString } from "calckey-js/built/acct";
let moveToAccount = $ref(""); let moveToAccount = $ref("");
let accountAlias = $ref([""]); let accountAlias = $ref([""]);
@ -48,21 +68,26 @@ await init();
async function init() { async function init() {
if ($i?.alsoKnownAs && $i.alsoKnownAs.length > 0) { if ($i?.alsoKnownAs && $i.alsoKnownAs.length > 0) {
const aka = await os.api('users/show', { userIds: $i.alsoKnownAs }); const aka = await os.api("users/show", { userIds: $i.alsoKnownAs });
accountAlias = (aka && aka.length > 0) ? aka.map(user => `@${toString(user)}`) : ['']; accountAlias =
aka && aka.length > 0
? aka.map((user) => `@${toString(user)}`)
: [""];
} else {
accountAlias = [""];
} }
} }
async function save(): Promise<void> { async function save(): Promise<void> {
const i = os.apiWithDialog("i/known-as", { const i = await os.apiWithDialog("i/known-as", {
alsoKnownAs: accountAlias.map(e => e.trim()).filter(e => e !== ""), alsoKnownAs: accountAlias.map((e) => e.trim()).filter((e) => e !== ""),
}); });
$i.alsoKnownAs = i.alsoKnownAs; $i.alsoKnownAs = i.alsoKnownAs;
await init(); await init();
} }
function add(): void { function add(): void {
accountAlias.push(''); accountAlias.push("");
} }
async function move(account): Promise<void> { async function move(account): Promise<void> {