monkeeShark/packages/frontend/src/pages/settings/profile.vue

235 lines
6.5 KiB
Vue
Raw Normal View History

<template>
2023-01-06 04:40:17 +00:00
<div class="_gaps_m">
2021-11-28 11:07:37 +00:00
<div class="llvierxe" :style="{ backgroundImage: $i.bannerUrl ? `url(${ $i.bannerUrl })` : null }">
2022-07-17 20:03:39 +00:00
<div class="avatar">
2023-01-16 05:18:11 +00:00
<MkAvatar class="avatar" :user="$i" @click="changeAvatar"/>
2022-07-17 14:18:05 +00:00
<MkButton primary rounded class="avatarEdit" @click="changeAvatar">{{ i18n.ts._profile.changeAvatar }}</MkButton>
2020-11-28 15:18:54 +00:00
</div>
2022-07-17 14:18:05 +00:00
<MkButton primary rounded class="bannerEdit" @click="changeBanner">{{ i18n.ts._profile.changeBanner }}</MkButton>
2021-11-28 11:07:37 +00:00
</div>
2023-01-07 06:09:46 +00:00
<MkInput v-model="profile.name" :max="30" manual-save>
<template #label>{{ i18n.ts._profile.name }}</template>
2023-01-07 06:09:46 +00:00
</MkInput>
2023-01-07 06:09:46 +00:00
<MkTextarea v-model="profile.description" :max="500" tall manual-save>
<template #label>{{ i18n.ts._profile.description }}</template>
<template #caption>{{ i18n.ts._profile.youCanIncludeHashtags }}</template>
2023-01-07 06:09:46 +00:00
</MkTextarea>
2023-01-07 06:09:46 +00:00
<MkInput v-model="profile.location" manual-save>
<template #label>{{ i18n.ts.location }}</template>
2022-12-20 06:24:31 +00:00
<template #prefix><i class="ti ti-map-pin"></i></template>
2023-01-07 06:09:46 +00:00
</MkInput>
2023-01-07 06:09:46 +00:00
<MkInput v-model="profile.birthday" type="date" manual-save>
<template #label>{{ i18n.ts.birthday }}</template>
2022-12-20 06:24:31 +00:00
<template #prefix><i class="ti ti-cake"></i></template>
2023-01-07 06:09:46 +00:00
</MkInput>
2023-01-07 06:09:46 +00:00
<MkSelect v-model="profile.lang">
<template #label>{{ i18n.ts.language }}</template>
<option v-for="x in Object.keys(langmap)" :key="x" :value="x">{{ langmap[x].nativeName }}</option>
2023-01-07 06:09:46 +00:00
</MkSelect>
2021-02-13 03:28:26 +00:00
2023-01-05 12:04:56 +00:00
<FormSlot>
2023-01-09 00:41:25 +00:00
<MkFolder>
2022-12-20 06:24:31 +00:00
<template #icon><i class="ti ti-list"></i></template>
<template #label>{{ i18n.ts._profile.metadataEdit }}</template>
2023-01-06 04:40:17 +00:00
<div class="_gaps_m">
2023-01-05 12:04:56 +00:00
<FormSplit v-for="(record, i) in fields" :min-width="250">
2023-01-07 06:09:46 +00:00
<MkInput v-model="record.name" small>
2022-02-25 09:53:08 +00:00
<template #label>{{ i18n.ts._profile.metadataLabel }} #{{ i + 1 }}</template>
2023-01-07 06:09:46 +00:00
</MkInput>
<MkInput v-model="record.value" small>
2022-02-25 09:53:08 +00:00
<template #label>{{ i18n.ts._profile.metadataContent }} #{{ i + 1 }}</template>
2023-01-07 06:09:46 +00:00
</MkInput>
2022-02-25 09:53:08 +00:00
</FormSplit>
2023-01-05 12:04:56 +00:00
<div>
<MkButton :disabled="fields.length >= 16" inline style="margin-right: 8px;" @click="addField"><i class="ti ti-plus"></i> {{ i18n.ts.add }}</MkButton>
<MkButton inline primary @click="saveFields"><i class="ti ti-check"></i> {{ i18n.ts.save }}</MkButton>
</div>
</div>
2023-01-09 00:41:25 +00:00
</MkFolder>
<template #caption>{{ i18n.ts._profile.metadataDescription }}</template>
2021-11-28 11:07:37 +00:00
</FormSlot>
2023-01-09 00:41:25 +00:00
<MkFolder>
2022-12-27 05:25:20 +00:00
<template #label>{{ i18n.ts.advancedSettings }}</template>
2023-01-06 04:40:17 +00:00
<div class="_gaps_m">
2023-01-07 05:59:54 +00:00
<MkSwitch v-model="profile.isCat">{{ i18n.ts.flagAsCat }}<template #caption>{{ i18n.ts.flagAsCatDescription }}</template></MkSwitch>
<MkSwitch v-model="profile.isBot">{{ i18n.ts.flagAsBot }}<template #caption>{{ i18n.ts.flagAsBotDescription }}</template></MkSwitch>
2022-12-27 05:25:20 +00:00
</div>
2023-01-09 00:41:25 +00:00
</MkFolder>
2022-12-27 05:25:20 +00:00
2023-01-07 05:59:54 +00:00
<MkSwitch v-model="profile.showTimelineReplies">{{ i18n.ts.flagShowTimelineReplies }}<template #caption>{{ i18n.ts.flagShowTimelineRepliesDescription }} {{ i18n.ts.reflectMayTakeTime }}</template></MkSwitch>
2021-11-28 11:07:37 +00:00
</div>
</template>
<script lang="ts" setup>
import { reactive, watch } from 'vue';
import MkButton from '@/components/MkButton.vue';
2023-01-07 06:09:46 +00:00
import MkInput from '@/components/MkInput.vue';
import MkTextarea from '@/components/MkTextarea.vue';
2023-01-07 05:59:54 +00:00
import MkSwitch from '@/components/MkSwitch.vue';
2023-01-07 06:09:46 +00:00
import MkSelect from '@/components/MkSelect.vue';
import FormSplit from '@/components/form/split.vue';
2023-01-09 00:41:25 +00:00
import MkFolder from '@/components/MkFolder.vue';
2021-11-28 11:07:37 +00:00
import FormSlot from '@/components/form/slot.vue';
2021-11-11 17:02:25 +00:00
import { selectFile } from '@/scripts/select-file';
import * as os from '@/os';
import { i18n } from '@/i18n';
import { $i } from '@/account';
import { langmap } from '@/scripts/langmap';
import { definePageMetadata } from '@/scripts/page-metadata';
import { claimAchievement } from '@/scripts/achievements';
const profile = reactive({
name: $i.name,
description: $i.description,
location: $i.location,
birthday: $i.birthday,
lang: $i.lang,
isBot: $i.isBot,
isCat: $i.isCat,
showTimelineReplies: $i.showTimelineReplies,
});
Migrate to Vue3 (#6587) * Update reaction.vue * fix bug * wip * wip * wjio * wip * Revert "wip" This reverts commit e427f2160adf4e8a4147006e25a89854edab0033. * wip * wip * wip * Update init.ts * Update drive-window.vue * wip * wip * Use PascalCase for components * Use PascalCase for components * update dep * wip * wip * wip * Update init.ts * wip * Update paging.ts * Update test.vue * watch deep * wip * lint * wip * wip * wip * wip * wiop * wip * Update webpack.config.ts * alllow null poll * wip * wip * wip * wiop * UI redesign & refactor (#6714) * wip * wip * wip * wip * wip * Update drive.vue * Update word-mute.vue * wip * wip * wip * clean up * wip * Update default.vue * wip * Update notes.vue * Update mfm.ts * Update index.home.vue * Update post-form.vue * Update post-form-attaches.vue * wip * Update post-form.vue * Update sidebar.vue * wip * wip * Update index.vue * wip * Update default.vue * Update index.vue * Update index.vue * wip * Update post-form-attaches.vue * Update note.vue * wip * clean up * Update notes.vue * wip * wip * Update ja-JP.yml * wip * wip * Update index.vue * wip * wip * wip * wip * wip * wip * wip * wip * Update default.vue * wip * Update _dark.json5 * wip * wip * wip * clean up * wip * wip * Update index.vue * Update test.vue * wip * wip * fix * wip * wip * wip * wip * clena yop * wip * wip * Update store.ts * Update messaging-room.vue * Update default.widgets.vue * fix * wip * wip * Update modal.vue * wip * Update os.ts * Update os.ts * Update deck.vue * Update init.ts * wip * Update ja-JP.yml * v-sizeは単にwindowのresizeを監視するだけで良いかもしれない * Update modal.vue * wip * Update tooltip.ts * wip * wip * wip * wip * wip * Update image-viewer.vue * wip * wip * Update style.scss * Update style.scss * Update visitor.vue * wip * Update init.ts * Update init.ts * wip * wip * Update visitor.vue * Update visitor.vue * Update visitor.vue * Update visitor.vue * wip * wip * Update modal.vue * Update header.vue * Update menu.vue * Update about.vue * Update about-misskey.vue * wip * wip * Update visitor.vue * Update tooltip.ts * wip * Update drive.vue * wip * Update style.scss * Update header.vue * wip * wip * Update users.user.vue * Update announcements.vue * wip * wip * wip * Update emojis.vue * wip * Update emojis.vue * Update style.scss * Update users.vue * wip * Update style.scss * wip * Update welcome.entrance.vue * Update radio.vue * Update size.ts * Update emoji-edit-dialog.vue * wip * Update emojis.vue * wip * Update emojis.vue * Update emojis.vue * Update emojis.vue * wip * wip * wip * wip * Update file-dialog.vue * wip * wip * Update token-generate-window.vue * Update notification-setting-window.vue * wip * wip * Update _error_.vue * Update ja-JP.yml * wip * wip * Update store.ts * Update emojis.vue * Update emojis.vue * Update emojis.vue * Update announcements.vue * Update store.ts * wip * Update page-editor.vue * wip * wip * Update modal.vue * wip * Update select-file.ts * Update timeline.vue * Update emojis.vue * Update os.ts * wip * Update user-select.vue * Update mfm.ts * Update get-file-info.ts * Update drive.vue * Update init.ts * Update mfm.ts * wip * wip * Update window.vue * Update note.vue * wip * wip * Update user-info.vue * wip * wip * wip * wip * wip * Update header.vue * Update header.vue * wip * Update explore.vue * wip * wip * wip * Update webpack.config.ts * wip * wip * wip * wip * wip * wip * Update autocomplete.ts * wip * wip * wip * Update toast.vue * wip * Update post-form-dialog.vue * wip * wip * wip * wip * wip * Update users.vue * wip * Update explore.vue * wip * wip * wip * Update package.json * wip * Update icon-dialog.vue * wip * wip * Update user-preview.ts * wip * wip * wip * wip * wip * Update instance.vue * Update user-name.vue * Update federation.vue * Update instance.vue * wip * wip * Update tag.vue * wip * wip * wip * wip * wip * Update instance.vue * wip * Update os.ts * Update os.ts * wip * wip * wip * Update router.ts * wip * Update init.ts * Update note.vue * Update messages.vue * wip * wip * wip * wip * wip * google * wip * wip * wip * wip * Update theme-editor.vue * wip * wip * Update room.vue * Update channel-editor.vue * wip * Update window.vue * Update window.vue * wip * Update window.vue * Update window.vue * wip * Update menu.vue * wip * wip * wip * wip * Update messaging-room.vue * wip * Update post-form.vue * Update default.widgets.vue * Update window.vue * wip
2020-10-17 11:12:00 +00:00
watch(() => profile, () => {
save();
}, {
deep: true,
});
const fields = reactive($i.fields.map(field => ({ name: field.name, value: field.value })));
function addField() {
fields.push({
name: '',
value: '',
});
}
while (fields.length < 4) {
addField();
}
function saveFields() {
os.apiWithDialog('i/update', {
fields: fields.filter(field => field.name !== '' && field.value !== ''),
});
}
function save() {
os.apiWithDialog('i/update', {
name: profile.name || null,
description: profile.description || null,
location: profile.location || null,
birthday: profile.birthday || null,
lang: profile.lang || null,
isBot: !!profile.isBot,
isCat: !!profile.isCat,
showTimelineReplies: !!profile.showTimelineReplies,
});
claimAchievement('profileFilled');
if (profile.name === 'syuilo' || profile.name === 'しゅいろ') {
claimAchievement('setNameToSyuilo');
}
if (profile.isCat) {
claimAchievement('markedAsCat');
}
}
function changeAvatar(ev) {
2022-01-28 02:53:12 +00:00
selectFile(ev.currentTarget ?? ev.target, i18n.ts.avatar).then(async (file) => {
let originalOrCropped = file;
const { canceled } = await os.confirm({
type: 'question',
text: i18n.t('cropImageAsk'),
okText: i18n.ts.cropYes,
cancelText: i18n.ts.cropNo,
});
if (!canceled) {
originalOrCropped = await os.cropImage(file, {
aspectRatio: 1,
});
}
const i = await os.apiWithDialog('i/update', {
avatarId: originalOrCropped.id,
});
$i.avatarId = i.avatarId;
$i.avatarUrl = i.avatarUrl;
claimAchievement('profileFilled');
});
}
2021-02-13 03:28:26 +00:00
function changeBanner(ev) {
2022-01-28 02:53:12 +00:00
selectFile(ev.currentTarget ?? ev.target, i18n.ts.banner).then(async (file) => {
let originalOrCropped = file;
const { canceled } = await os.confirm({
type: 'question',
text: i18n.t('cropImageAsk'),
okText: i18n.ts.cropYes,
cancelText: i18n.ts.cropNo,
});
if (!canceled) {
originalOrCropped = await os.cropImage(file, {
aspectRatio: 2,
});
}
const i = await os.apiWithDialog('i/update', {
bannerId: originalOrCropped.id,
});
$i.bannerId = i.bannerId;
$i.bannerUrl = i.bannerUrl;
});
}
const headerActions = $computed(() => []);
const headerTabs = $computed(() => []);
definePageMetadata({
title: i18n.ts.profile,
icon: 'ti ti-user',
});
</script>
<style lang="scss" scoped>
2020-01-29 22:13:36 +00:00
.llvierxe {
2020-11-28 15:18:54 +00:00
position: relative;
background-size: cover;
background-position: center;
2022-07-17 20:03:39 +00:00
border: solid 1px var(--divider);
2021-11-28 11:07:37 +00:00
border-radius: 10px;
2022-07-13 12:41:06 +00:00
overflow: clip;
2020-01-29 22:13:36 +00:00
2021-11-28 11:07:37 +00:00
> .avatar {
display: inline-block;
text-align: center;
padding: 16px;
> .avatar {
display: inline-block;
width: 72px;
height: 72px;
margin: 0 auto 16px auto;
}
2020-11-28 15:18:54 +00:00
}
2021-11-28 11:07:37 +00:00
> .bannerEdit {
2020-11-28 15:18:54 +00:00
position: absolute;
2021-11-28 11:07:37 +00:00
top: 16px;
right: 16px;
}
}
</style>