pl-fe: fix profile fields editing on Mastodon, also pl-api params fixes

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2025-12-05 18:57:46 +01:00
parent fd43a22d7b
commit 70836fea14
3 changed files with 18 additions and 11 deletions

View File

@ -153,7 +153,7 @@ const baseAccountSchema = v.object({
pronouns: v.fallback(v.array(v.string()), []),
/** Mention policy */
mention_policy: v.fallback(v.picklist(['none', 'only_known', 'only_followers']), 'none'),
mention_policy: v.fallback(v.picklist(['none', 'only_known', 'only_contacts']), 'none'),
/** The reported subscribers of this user */
subscribers_count: v.fallback(v.number(), 0),
/** Identity proofs */

View File

@ -71,7 +71,7 @@ interface UpdateCredentialsParams {
/** Boolean. Whether public posts should be searchable to anyone. */
indexable?: boolean;
/** Hash. The profile fields to be set. Inside this hash, the key is an integer cast to a string (although the exact integer does not matter), and the value is another hash including name and value. By default, max 4 fields. */
fields_attributes?: Array<{
fields_attributes?: Record<string, {
/** String. The name of the profile field. By default, max 255 characters. */
name: string;
/** String. The value of the profile field. By default, max 255 characters. */
@ -81,7 +81,7 @@ interface UpdateCredentialsParams {
/** String. Default post privacy for authored statuses. Can be public, unlisted, or private. */
privacy?: string;
/** Boolean. Whether to mark authored statuses as sensitive by default. */
sensitive?: string;
sensitive?: boolean;
/** String. Default language to use for authored statuses (ISO 6391) */
language?: string;
};
@ -124,12 +124,12 @@ interface UpdateCredentialsParams {
*
* Requires features{@link Features.accountAvatarDescription}.
*/
avatar_description?: boolean;
avatar_description?: string;
/**
* Description of header image, for alt-text.
* Requires features{@link Features.accountAvatarDescription}.
*/
header_description?: boolean;
header_description?: string;
/**
* Custom CSS to use when rendering this account's profile or statuses. String must be no more than 5,000 characters (~5kb).
* Requires `instance.configuration.accounts.allow_custom_css`.

View File

@ -1,5 +1,5 @@
import pick from 'lodash/pick';
import { type CredentialAccount, GOTOSOCIAL } from 'pl-api';
import { type CredentialAccount, GOTOSOCIAL, type UpdateCredentialsParams } from 'pl-api';
import React, { useState, useEffect } from 'react';
import { defineMessages, useIntl, FormattedMessage } from 'react-intl';
@ -133,9 +133,9 @@ interface AccountCredentials {
/** Whether the user speaks as a cat. */
speak_as_cat?: boolean;
/** Mention policy */
mention_policy?: string;
web_layout?: string;
web_visibility?: string;
mention_policy?: 'none' | 'only_known' | 'only_contacts';
web_layout?: 'microblog' | 'gallery';
web_visibility?: 'public' | 'unlisted' | 'none';
custom_css?: string;
}
@ -244,8 +244,15 @@ const EditProfilePage: React.FC = () => {
const handleSubmit: React.FormEventHandler = (event) => {
const promises = [];
const params = { ...data };
if (params.fields_attributes?.length === 0) params.fields_attributes = [{ name: '', value: '' }];
const { fields_attributes, ...rest } = data;
const params: UpdateCredentialsParams = {
...rest,
};
if (fields_attributes?.length === 0) params.fields_attributes = { '0': { name: '', value: '' } };
else if (fields_attributes) params.fields_attributes = Object.fromEntries(
fields_attributes.map((field, i) => [i.toString(), field]),
);
if (header.file !== undefined) params.header = header.file || '';
if (avatar.file !== undefined) params.avatar = avatar.file || '';