2022-12-26 11:50:11 +03:00
|
|
|
<script lang="ts" setup>
|
2023-01-02 18:00:11 +03:00
|
|
|
import type { UpdateCredentialsParams } from 'masto'
|
2022-12-26 11:50:11 +03:00
|
|
|
import { useForm } from 'slimeform'
|
|
|
|
|
|
|
|
definePageMeta({
|
2022-12-29 23:14:05 +03:00
|
|
|
middleware: 'auth',
|
2022-12-26 11:50:11 +03:00
|
|
|
// Keep alive the form page will reduce raw data timeliness and its status timeliness
|
|
|
|
keepalive: false,
|
|
|
|
})
|
|
|
|
|
2023-01-02 18:00:11 +03:00
|
|
|
const account = $computed(() => currentUser.value?.account)
|
2022-12-26 11:50:11 +03:00
|
|
|
|
|
|
|
const onlineSrc = $computed(() => ({
|
2023-01-02 18:00:11 +03:00
|
|
|
avatar: account?.avatar || '',
|
|
|
|
header: account?.header || '',
|
2022-12-26 11:50:11 +03:00
|
|
|
}))
|
|
|
|
|
|
|
|
const { form, reset, submitter, dirtyFields, isError } = useForm({
|
2023-01-02 18:00:11 +03:00
|
|
|
form: () => {
|
|
|
|
// For complex types of objects, a deep copy is required to ensure correct comparison of initial and modified values
|
|
|
|
const fieldsAttributes = Array.from({ length: 4 }, (_, i) => {
|
|
|
|
return { ...account?.fields?.[i] || { name: '', value: '' } }
|
|
|
|
})
|
|
|
|
return {
|
|
|
|
displayName: account?.displayName ?? '',
|
|
|
|
note: account?.source.note.replaceAll('\r', '') ?? '',
|
|
|
|
|
|
|
|
avatar: null as null | File,
|
|
|
|
header: null as null | File,
|
|
|
|
|
|
|
|
fieldsAttributes,
|
|
|
|
|
|
|
|
// These look more like account and privacy settings than appearance settings
|
|
|
|
// discoverable: false,
|
|
|
|
// bot: false,
|
|
|
|
// locked: false,
|
|
|
|
}
|
|
|
|
},
|
2022-12-26 11:50:11 +03:00
|
|
|
})
|
|
|
|
|
2023-01-01 22:42:11 +03:00
|
|
|
watch(isMastoInitialised, async (val) => {
|
|
|
|
if (!val)
|
|
|
|
return
|
|
|
|
|
|
|
|
// Keep the information to be edited up to date
|
2022-12-26 11:50:11 +03:00
|
|
|
await pullMyAccountInfo()
|
|
|
|
reset()
|
|
|
|
})
|
|
|
|
|
|
|
|
const isCanSubmit = computed(() => !isError.value && !isEmptyObject(dirtyFields.value))
|
|
|
|
|
|
|
|
const { submit, submitting } = submitter(async ({ dirtyFields }) => {
|
2023-01-02 18:00:11 +03:00
|
|
|
const res = await useMasto().accounts.updateCredentials(dirtyFields.value as UpdateCredentialsParams)
|
2022-12-26 11:50:11 +03:00
|
|
|
.then(account => ({ account }))
|
|
|
|
.catch((error: Error) => ({ error }))
|
|
|
|
|
|
|
|
if ('error' in res) {
|
|
|
|
// TODO: Show error message
|
|
|
|
console.error('Error(updateCredentials):', res.error)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-02 18:00:11 +03:00
|
|
|
setAccountInfo(account!.id, res.account)
|
2022-12-26 11:50:11 +03:00
|
|
|
reset()
|
|
|
|
})
|
|
|
|
</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">
|
|
|
|
<div>
|
|
|
|
<!-- banner -->
|
|
|
|
<div of-hidden bg="gray-500/20" aspect="3">
|
|
|
|
<CommonInputImage
|
2023-01-01 23:43:09 +03:00
|
|
|
v-if="isHydrated"
|
2022-12-26 11:50:11 +03:00
|
|
|
v-model="form.header"
|
|
|
|
:original="onlineSrc.header"
|
|
|
|
w-full h-full
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<CommonCropImage v-model="form.header" :stencil-aspect-ratio="3 / 1" />
|
|
|
|
|
|
|
|
<!-- avatar -->
|
|
|
|
<div px-4>
|
|
|
|
<CommonInputImage
|
2023-01-01 23:43:09 +03:00
|
|
|
v-if="isHydrated"
|
2022-12-26 11:50:11 +03: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" />
|
|
|
|
</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 18:00:11 +03:00
|
|
|
<!-- metadata -->
|
|
|
|
<div space-y-2>
|
|
|
|
<div font-medium>
|
|
|
|
Profile metadata
|
|
|
|
</div>
|
|
|
|
<div text-sm text-secondary>
|
|
|
|
You can have up to 4 items displayed as a table on your profile
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<SettingsProfileMetadata v-if="isHydrated" v-model:form="form" />
|
|
|
|
</div>
|
|
|
|
|
2022-12-26 11:50:11 +03:00
|
|
|
<!-- submit -->
|
|
|
|
<div text-right>
|
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
btn-solid rounded-full text-sm
|
|
|
|
flex-inline gap-x-2 items-center
|
|
|
|
:disabled="submitting || !isCanSubmit"
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
aria-hidden="true"
|
|
|
|
inline-block
|
|
|
|
:class="submitting ? 'i-ri:loader-2-fill animate animate-spin' : 'i-ri:save-line'"
|
|
|
|
/>
|
|
|
|
<span>
|
|
|
|
{{ $t('action.save') }}
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</MainContent>
|
|
|
|
</template>
|