hippofish/packages/client/src/pages/settings/migration.vue

113 lines
2.9 KiB
Vue
Raw Normal View History

<template>
2023-04-08 02:01:42 +02:00
<div class="_formRoot">
<FormSection>
<template #label>{{ i18n.ts.moveTo }}</template>
2023-05-31 07:14:13 +02:00
<FormInfo warn class="_formBlock">{{
i18n.ts.moveAccountDescription
}}</FormInfo>
2023-04-08 02:01:42 +02:00
<FormInput v-model="moveToAccount" class="_formBlock">
2023-05-31 07:14:13 +02:00
<template #prefix
><i :class="icon('ph-airplane-takeoff')"></i
2023-05-31 07:14:13 +02:00
></template>
2023-04-08 02:01:42 +02:00
<template #label>{{ i18n.ts.moveToLabel }}</template>
</FormInput>
<FormButton primary danger @click="move(moveToAccount)">
{{ i18n.ts.moveAccount }}
</FormButton>
</FormSection>
2023-04-08 02:01:42 +02:00
<FormSection>
<template #label>{{ i18n.ts.moveFrom }}</template>
2023-05-31 07:14:13 +02:00
<FormInfo warn class="_formBlock">{{
i18n.ts.moveFromDescription
}}</FormInfo>
<FormInput
v-for="(_, i) in accountAlias"
v-model="accountAlias[i]"
class="_formBlock"
>
<template #prefix
><i :class="icon('ph-airplane-landing')"></i
2023-05-31 07:14:13 +02:00
></template>
<template #label>{{
`#${i + 1} ${i18n.ts.moveFromLabel}`
}}</template>
2023-04-08 02:01:42 +02:00
</FormInput>
2023-05-31 07:14:13 +02:00
<FormButton
class="button"
:disabled="accountAlias.length >= 10"
inline
style="margin-right: 8px"
@click="add"
><i :class="icon('ph-plus')"></i> {{ i18n.ts.add }}</FormButton
2023-05-31 07:14:13 +02:00
>
2023-05-31 05:10:12 +02:00
<FormButton class="button" inline primary @click="save">
<i :class="icon('ph-floppy-disk-back')"></i>
2023-04-08 02:01:42 +02:00
{{ i18n.ts.save }}
</FormButton>
</FormSection>
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
2023-09-02 01:27:33 +02:00
import { toString } from "firefish-js/built/acct";
2023-04-08 02:01:42 +02:00
import FormSection from "@/components/form/section.vue";
import FormInput from "@/components/form/input.vue";
import FormButton from "@/components/MkButton.vue";
2023-05-31 05:10:12 +02:00
import FormInfo from "@/components/MkInfo.vue";
2023-04-08 02:01:42 +02:00
import * as os from "@/os";
import { i18n } from "@/i18n";
import { definePageMetadata } from "@/scripts/page-metadata";
import { $i } from "@/reactiveAccount";
import icon from "@/scripts/icon";
const moveToAccount = ref("");
const accountAlias = ref([""]);
2023-05-31 05:10:12 +02:00
await init();
async function init() {
if ($i?.alsoKnownAs && $i.alsoKnownAs.length > 0) {
2023-05-31 07:14:13 +02:00
const aka = await os.api("users/show", { userIds: $i.alsoKnownAs });
accountAlias.value =
2023-05-31 07:14:13 +02:00
aka && aka.length > 0
? aka.map((user) => `@${toString(user)}`)
: [""];
} else {
accountAlias.value = [""];
2023-05-31 05:10:12 +02:00
}
}
async function save(): Promise<void> {
2023-05-31 07:14:13 +02:00
const i = await os.apiWithDialog("i/known-as", {
alsoKnownAs: accountAlias.value
.map((e) => e.trim())
.filter((e) => e !== ""),
2022-12-12 01:42:40 +01:00
});
2023-05-31 05:10:12 +02:00
$i.alsoKnownAs = i.alsoKnownAs;
await init();
}
function add(): void {
accountAlias.value.push("");
}
2022-12-12 02:33:45 +01:00
async function move(account): Promise<void> {
2022-12-12 02:28:11 +01:00
const confirm = await os.confirm({
2023-04-08 02:01:42 +02:00
type: "warning",
text: i18n.t("migrationConfirm", { account: account.toString() }),
2022-12-12 02:28:11 +01:00
});
if (confirm.canceled) return;
2023-04-08 02:01:42 +02:00
os.apiWithDialog("i/move", {
2022-12-12 02:33:45 +01:00
moveToAccount: account,
});
}
definePageMetadata({
title: i18n.ts.security,
icon: `${icon("ph-lock")}`,
});
</script>