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",
},
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"],

View file

@ -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) => {
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}`;

View file

@ -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> {