fix(settings): refresh profile after initted

zio/stable
三咲智子 2023-01-02 03:42:11 +08:00
parent 496da96072
commit fbf1906bd4
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
2 changed files with 13 additions and 18 deletions

View File

@ -139,8 +139,8 @@ export function setAccountInfo(userId: string, account: AccountCredentials) {
} }
export async function pullMyAccountInfo() { export async function pullMyAccountInfo() {
const me = await useMasto().accounts.verifyCredentials() const account = await useMasto().accounts.verifyCredentials()
setAccountInfo(currentUserId.value, me) setAccountInfo(currentUserId.value, account)
} }
export function getUsersIndexByUserId(userId: string) { export function getUsersIndexByUserId(userId: string) {

View File

@ -1,5 +1,4 @@
<script lang="ts" setup> <script lang="ts" setup>
import { invoke } from '@vueuse/shared'
import { useForm } from 'slimeform' import { useForm } from 'slimeform'
definePageMeta({ definePageMeta({
@ -8,24 +7,17 @@ definePageMeta({
keepalive: false, keepalive: false,
}) })
const router = useRouter() const acccount = $computed(() => currentUser.value?.account)
const my = $computed(() => currentUser.value?.account)
watch($$(my), (value) => {
if (!value)
router.push('/')
})
const onlineSrc = $computed(() => ({ const onlineSrc = $computed(() => ({
avatar: my?.avatar || '', avatar: acccount?.avatar || '',
header: my?.header || '', header: acccount?.header || '',
})) }))
const { form, reset, submitter, dirtyFields, isError } = useForm({ const { form, reset, submitter, dirtyFields, isError } = useForm({
form: () => ({ form: () => ({
displayName: my?.displayName ?? '', displayName: acccount?.displayName ?? '',
note: my?.source.note.replaceAll('\r', '') ?? '', note: acccount?.source.note.replaceAll('\r', '') ?? '',
avatar: null as null | File, avatar: null as null | File,
header: null as null | File, header: null as null | File,
@ -37,8 +29,11 @@ const { form, reset, submitter, dirtyFields, isError } = useForm({
}), }),
}) })
watch(isMastoInitialised, async (val) => {
if (!val)
return
// Keep the information to be edited up to date // Keep the information to be edited up to date
invoke(async () => {
await pullMyAccountInfo() await pullMyAccountInfo()
reset() reset()
}) })
@ -56,7 +51,7 @@ const { submit, submitting } = submitter(async ({ dirtyFields }) => {
return return
} }
setAccountInfo(my!.id, res.account) setAccountInfo(acccount!.id, res.account)
reset() reset()
}) })
</script> </script>