2024-09-07 08:38:18 +01:00
|
|
|
<script setup lang="ts">
|
2023-01-08 06:21:09 +00:00
|
|
|
import type { mastodon } from 'masto'
|
2022-12-26 08:50:11 +00:00
|
|
|
import { useForm } from 'slimeform'
|
|
|
|
|
|
|
|
definePageMeta({
|
2022-12-29 20:14:05 +00:00
|
|
|
middleware: 'auth',
|
2022-12-26 08:50:11 +00:00
|
|
|
})
|
|
|
|
|
2023-01-04 13:57:12 +00:00
|
|
|
const { t } = useI18n()
|
|
|
|
|
2023-04-16 20:33:51 +01:00
|
|
|
useHydratedHead({
|
2023-01-04 13:57:12 +00:00
|
|
|
title: () => `${t('settings.profile.appearance.title')} | ${t('nav.settings')}`,
|
|
|
|
})
|
|
|
|
|
2024-02-21 15:20:08 +00:00
|
|
|
const { client } = useMasto()
|
2023-01-15 08:38:02 +00:00
|
|
|
|
2023-01-19 16:33:17 +00:00
|
|
|
const avatarInput = ref<any>()
|
|
|
|
const headerInput = ref<any>()
|
|
|
|
|
2024-02-21 15:20:08 +00:00
|
|
|
const account = computed(() => currentUser.value?.account)
|
2022-12-26 08:50:11 +00:00
|
|
|
|
2024-02-21 15:20:08 +00:00
|
|
|
const onlineSrc = computed(() => ({
|
|
|
|
avatar: account.value?.avatar || '',
|
|
|
|
header: account.value?.header || '',
|
2022-12-26 08:50:11 +00:00
|
|
|
}))
|
|
|
|
|
2023-03-19 12:12:20 +00:00
|
|
|
const { form, reset, submitter, isDirty, isError } = useForm({
|
2023-01-02 15:00:11 +00:00
|
|
|
form: () => {
|
|
|
|
// For complex types of objects, a deep copy is required to ensure correct comparison of initial and modified values
|
2023-01-10 08:33:20 +00:00
|
|
|
const fieldsAttributes = Array.from({ length: maxAccountFieldCount.value }, (_, i) => {
|
2024-02-21 15:20:08 +00:00
|
|
|
const field = { ...account.value?.fields?.[i] || { name: '', value: '' } }
|
2023-01-02 22:00:23 +00:00
|
|
|
|
2023-11-27 12:17:58 +00:00
|
|
|
field.value = convertMetadata(field.value)
|
2023-01-02 22:00:23 +00:00
|
|
|
|
|
|
|
return field
|
2023-01-02 15:00:11 +00:00
|
|
|
})
|
|
|
|
return {
|
2024-02-21 15:20:08 +00:00
|
|
|
displayName: account.value?.displayName ?? '',
|
|
|
|
note: account.value?.source.note.replaceAll('\r', '') ?? '',
|
2023-01-02 15:00:11 +00:00
|
|
|
|
|
|
|
avatar: null as null | File,
|
|
|
|
header: null as null | File,
|
|
|
|
|
|
|
|
fieldsAttributes,
|
|
|
|
|
2024-02-21 15:20:08 +00:00
|
|
|
bot: account.value?.bot ?? false,
|
|
|
|
locked: account.value?.locked ?? false,
|
2023-01-08 14:08:11 +00:00
|
|
|
|
2023-01-02 15:00:11 +00:00
|
|
|
// These look more like account and privacy settings than appearance settings
|
|
|
|
// discoverable: false,
|
|
|
|
// locked: false,
|
|
|
|
}
|
|
|
|
},
|
2022-12-26 08:50:11 +00:00
|
|
|
})
|
|
|
|
|
2023-01-19 10:50:56 +00:00
|
|
|
const isCanSubmit = computed(() => !isError.value && isDirty.value)
|
2024-02-21 15:20:08 +00:00
|
|
|
const failedMessages = ref<string[]>([])
|
2022-12-26 08:50:11 +00:00
|
|
|
|
|
|
|
const { submit, submitting } = submitter(async ({ dirtyFields }) => {
|
2023-01-03 10:13:48 +00:00
|
|
|
if (!isCanSubmit.value)
|
|
|
|
return
|
|
|
|
|
2024-02-21 15:20:08 +00:00
|
|
|
const res = await client.value.v1.accounts.updateCredentials(dirtyFields.value as mastodon.rest.v1.UpdateCredentialsParams)
|
2022-12-26 08:50:11 +00:00
|
|
|
.then(account => ({ account }))
|
|
|
|
.catch((error: Error) => ({ error }))
|
|
|
|
|
|
|
|
if ('error' in res) {
|
2023-07-29 09:52:57 +01:00
|
|
|
console.error(res.error)
|
2024-02-21 15:20:08 +00:00
|
|
|
failedMessages.value.push(res.error.message)
|
2022-12-26 08:50:11 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-16 20:39:33 +01:00
|
|
|
const server = currentUser.value!.server
|
|
|
|
|
|
|
|
if (!res.account.acct.includes('@'))
|
|
|
|
res.account.acct = `${res.account.acct}@${server}`
|
|
|
|
|
|
|
|
cacheAccount(res.account, server, true)
|
2023-01-15 08:38:02 +00:00
|
|
|
currentUser.value!.account = res.account
|
2022-12-26 08:50:11 +00:00
|
|
|
reset()
|
|
|
|
})
|
2023-01-08 09:06:15 +00:00
|
|
|
|
2023-03-30 20:01:24 +01:00
|
|
|
async function refreshInfo() {
|
2023-01-15 08:38:02 +00:00
|
|
|
if (!currentUser.value)
|
|
|
|
return
|
2023-01-08 09:06:15 +00:00
|
|
|
// Keep the information to be edited up to date
|
2023-01-15 08:38:02 +00:00
|
|
|
await refreshAccountInfo()
|
2023-01-08 09:06:15 +00:00
|
|
|
if (!isDirty)
|
|
|
|
reset()
|
|
|
|
}
|
|
|
|
|
2023-01-19 16:33:17 +00:00
|
|
|
useDropZone(avatarInput, (files) => {
|
|
|
|
if (files?.[0])
|
|
|
|
form.avatar = files[0]
|
|
|
|
})
|
|
|
|
useDropZone(headerInput, (files) => {
|
|
|
|
if (files?.[0])
|
|
|
|
form.header = files[0]
|
|
|
|
})
|
|
|
|
|
2023-01-15 08:38:02 +00:00
|
|
|
onHydrated(refreshInfo)
|
2023-01-08 09:06:15 +00:00
|
|
|
onReactivated(refreshInfo)
|
2022-12-26 08:50:11 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<MainContent back>
|
|
|
|
<template #title>
|
|
|
|
<div text-lg font-bold flex items-center gap-2 @click="$scrollToTop">
|
|
|
|
<span>{{ $t('settings.profile.appearance.title') }}</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<form space-y-5 @submit.prevent="submit">
|
2024-02-24 12:24:21 +00:00
|
|
|
<div v-if="account">
|
2022-12-26 08:50:11 +00:00
|
|
|
<!-- banner -->
|
|
|
|
<div of-hidden bg="gray-500/20" aspect="3">
|
|
|
|
<CommonInputImage
|
2023-01-19 16:33:17 +00:00
|
|
|
ref="headerInput"
|
2022-12-26 08:50:11 +00:00
|
|
|
v-model="form.header"
|
|
|
|
:original="onlineSrc.header"
|
|
|
|
w-full h-full
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<CommonCropImage v-model="form.header" :stencil-aspect-ratio="3 / 1" />
|
|
|
|
|
|
|
|
<!-- avatar -->
|
2023-01-06 19:14:00 +00:00
|
|
|
<div px-4 flex="~ gap4">
|
2022-12-26 08:50:11 +00:00
|
|
|
<CommonInputImage
|
2023-01-19 16:33:17 +00:00
|
|
|
ref="avatarInput"
|
2022-12-26 08:50:11 +00:00
|
|
|
v-model="form.avatar"
|
|
|
|
:original="onlineSrc.avatar"
|
|
|
|
mt--10
|
|
|
|
rounded-full border="bg-base 4"
|
|
|
|
w="sm:30 24" min-w="sm:30 24" h="sm:30 24"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<CommonCropImage v-model="form.avatar" />
|
2023-01-08 09:06:15 +00:00
|
|
|
|
|
|
|
<div px4>
|
2023-01-08 14:08:11 +00:00
|
|
|
<div flex justify-between>
|
|
|
|
<AccountDisplayName
|
|
|
|
:account="{ ...account, displayName: form.displayName }"
|
|
|
|
font-bold sm:text-2xl text-xl
|
|
|
|
/>
|
2023-07-02 18:55:18 +01:00
|
|
|
<div flex="~ row" items-center gap2>
|
|
|
|
<label>
|
|
|
|
<AccountLockIndicator show-label px2 py1>
|
|
|
|
<template #prepend>
|
|
|
|
<input v-model="form.locked" type="checkbox" cursor-pointer>
|
|
|
|
</template>
|
|
|
|
</AccountLockIndicator>
|
|
|
|
</label>
|
|
|
|
<label>
|
|
|
|
<AccountBotIndicator show-label px2 py1>
|
|
|
|
<template #prepend>
|
|
|
|
<input v-model="form.bot" type="checkbox" cursor-pointer>
|
|
|
|
</template>
|
|
|
|
</AccountBotIndicator>
|
|
|
|
</label>
|
|
|
|
</div>
|
2023-01-08 14:08:11 +00:00
|
|
|
</div>
|
2023-01-08 09:06:15 +00:00
|
|
|
<AccountHandle :account="account" />
|
|
|
|
</div>
|
2022-12-26 08:50:11 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div px4 py3 space-y-5>
|
|
|
|
<!-- display name -->
|
|
|
|
<label space-y-2 block>
|
|
|
|
<p font-medium>
|
|
|
|
{{ $t('settings.profile.appearance.display_name') }}
|
|
|
|
</p>
|
|
|
|
<input v-model="form.displayName" type="text" input-base>
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<!-- note -->
|
|
|
|
<label space-y-2 block>
|
|
|
|
<p font-medium>
|
|
|
|
{{ $t('settings.profile.appearance.bio') }}
|
|
|
|
</p>
|
|
|
|
<textarea v-model="form.note" maxlength="500" min-h-10ex input-base />
|
|
|
|
</label>
|
|
|
|
|
2023-01-02 15:00:11 +00:00
|
|
|
<!-- metadata -->
|
|
|
|
|
2024-02-24 12:24:21 +00:00
|
|
|
<SettingsProfileMetadata v-model="form" />
|
2023-01-02 15:00:11 +00:00
|
|
|
|
2023-01-02 21:17:11 +00:00
|
|
|
<!-- actions -->
|
|
|
|
<div flex="~ gap2" justify-end>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
btn-text text-sm
|
|
|
|
flex gap-x-2 items-center
|
|
|
|
text-red
|
|
|
|
@click="reset()"
|
|
|
|
>
|
|
|
|
<div aria-hidden="true" i-ri:eraser-line />
|
|
|
|
{{ $t('action.reset') }}
|
|
|
|
</button>
|
|
|
|
|
2022-12-26 08:50:11 +00:00
|
|
|
<button
|
2023-07-29 09:52:57 +01:00
|
|
|
v-if="failedMessages.length === 0"
|
2022-12-26 08:50:11 +00:00
|
|
|
type="submit"
|
|
|
|
btn-solid rounded-full text-sm
|
2023-01-02 21:17:11 +00:00
|
|
|
flex gap-x-2 items-center
|
2022-12-26 08:50:11 +00:00
|
|
|
:disabled="submitting || !isCanSubmit"
|
|
|
|
>
|
2023-01-13 16:00:32 +00:00
|
|
|
<span v-if="submitting" aria-hidden="true" block animate-spin preserve-3d>
|
|
|
|
<span block i-ri:loader-2-fill aria-hidden="true" />
|
|
|
|
</span>
|
|
|
|
<span v-else aria-hidden="true" block i-ri:save-line />
|
2023-01-02 21:17:11 +00:00
|
|
|
{{ $t('action.save') }}
|
2022-12-26 08:50:11 +00:00
|
|
|
</button>
|
2023-07-29 09:52:57 +01:00
|
|
|
|
|
|
|
<button
|
|
|
|
v-else
|
|
|
|
type="submit"
|
|
|
|
btn-danger rounded-full text-sm
|
|
|
|
flex gap-x-2 items-center
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
aria-hidden="true" block i-carbon:face-dizzy-filled
|
|
|
|
/>
|
|
|
|
<span>{{ $t('state.save_failed') }}</span>
|
|
|
|
</button>
|
2022-12-26 08:50:11 +00:00
|
|
|
</div>
|
2023-07-29 09:52:57 +01:00
|
|
|
|
|
|
|
<CommonErrorMessage v-if="failedMessages.length > 0" described-by="save-failed">
|
|
|
|
<header id="save-failed" flex justify-between>
|
|
|
|
<div flex items-center gap-x-2 font-bold>
|
|
|
|
<div aria-hidden="true" i-ri:error-warning-fill />
|
|
|
|
<p>{{ $t('state.save_failed') }}</p>
|
|
|
|
</div>
|
|
|
|
<CommonTooltip placement="bottom" :content="$t('action.clear_save_failed')">
|
|
|
|
<button
|
|
|
|
flex rounded-4 p1 hover:bg-active cursor-pointer transition-100 :aria-label="$t('action.clear_save_failed')"
|
|
|
|
@click="failedMessages = []"
|
|
|
|
>
|
|
|
|
<span aria-hidden="true" w="1.75em" h="1.75em" i-ri:close-line />
|
|
|
|
</button>
|
|
|
|
</CommonTooltip>
|
|
|
|
</header>
|
|
|
|
<ol ps-2 sm:ps-1>
|
|
|
|
<li v-for="(error, i) in failedMessages" :key="i" flex="~ col sm:row" gap-y-1 sm:gap-x-2>
|
|
|
|
<strong>{{ i + 1 }}.</strong>
|
|
|
|
<span>{{ error }}</span>
|
|
|
|
</li>
|
|
|
|
</ol>
|
|
|
|
</CommonErrorMessage>
|
2022-12-26 08:50:11 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</MainContent>
|
|
|
|
</template>
|