pl-fe is officially woke

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-09-05 23:50:43 +02:00
parent a3adf16798
commit 1c9f819bee
6 changed files with 12 additions and 7 deletions

View file

@ -2,10 +2,10 @@ import { z } from 'zod';
import { dateSchema } from './utils'; import { dateSchema } from './utils';
const markerSchema = z.preprocess((marker: any) => ({ const markerSchema = z.preprocess((marker: any) => marker ? ({
unread_count: marker.pleroma?.unread_count, unread_count: marker.pleroma?.unread_count,
...marker, ...marker,
}), z.object({ }) : null, z.object({
last_read_id: z.string(), last_read_id: z.string(),
version: z.number().int(), version: z.number().int(),
updated_at: dateSchema, updated_at: dateSchema,

View file

@ -4,7 +4,7 @@ import { announcementSchema } from './announcement';
import { announcementReactionSchema } from './announcement-reaction'; import { announcementReactionSchema } from './announcement-reaction';
import { chatSchema } from './chat'; import { chatSchema } from './chat';
import { conversationSchema } from './conversation'; import { conversationSchema } from './conversation';
import { markerSchema } from './marker'; import { markersSchema } from './marker';
import { notificationSchema } from './notification'; import { notificationSchema } from './notification';
import { statusSchema } from './status'; import { statusSchema } from './status';
@ -82,7 +82,7 @@ const respondStreamingEventSchema = baseStreamingEventSchema.extend({
const markerStreamingEventSchema = baseStreamingEventSchema.extend({ const markerStreamingEventSchema = baseStreamingEventSchema.extend({
event: z.literal('marker'), event: z.literal('marker'),
payload: z.preprocess((payload: any) => JSON.parse(payload), markerSchema), payload: z.preprocess((payload: any) => JSON.parse(payload), markersSchema),
}); });
/** @see {@link https://docs.joinmastodon.org/methods/streaming/#events} */ /** @see {@link https://docs.joinmastodon.org/methods/streaming/#events} */

View file

@ -14,6 +14,7 @@ const messages = defineMessages({
/** Type of the inner Streamfield input component. */ /** Type of the inner Streamfield input component. */
type StreamfieldComponent<T> = React.ComponentType<{ type StreamfieldComponent<T> = React.ComponentType<{
index: number;
value: T; value: T;
onChange: (value: T) => void; onChange: (value: T) => void;
autoFocus: boolean; autoFocus: boolean;
@ -70,9 +71,10 @@ const Streamfield: React.FC<IStreamfield> = ({
{(values.length > 0) && ( {(values.length > 0) && (
<Stack space={1}> <Stack space={1}>
{values.map((value, i) => value?._destroy ? null : ( {values.map((value, i) => value?._destroy ? null : (
<HStack space={2} alignItems='center'> <HStack key={i} space={2} alignItems='center'>
<Component <Component
key={i} key={i}
index={i}
onChange={handleChange(i)} onChange={handleChange(i)}
value={value} value={value}
autoFocus={i > 0} autoFocus={i > 0}

View file

@ -46,6 +46,7 @@ const messages = defineMessages({
header: { id: 'edit_profile.header', defaultMessage: 'Edit profile' }, header: { id: 'edit_profile.header', defaultMessage: 'Edit profile' },
metaFieldLabel: { id: 'edit_profile.fields.meta_fields.label_placeholder', defaultMessage: 'Label' }, metaFieldLabel: { id: 'edit_profile.fields.meta_fields.label_placeholder', defaultMessage: 'Label' },
metaFieldContent: { id: 'edit_profile.fields.meta_fields.content_placeholder', defaultMessage: 'Content' }, metaFieldContent: { id: 'edit_profile.fields.meta_fields.content_placeholder', defaultMessage: 'Content' },
firstMetaFieldLabel: { id: 'edit_profile.fields.meta_fields.label_placeholder.first', defaultMessage: 'Label (e.g. pronouns)' },
success: { id: 'edit_profile.success', defaultMessage: 'Your profile has been successfully saved!' }, success: { id: 'edit_profile.success', defaultMessage: 'Your profile has been successfully saved!' },
error: { id: 'edit_profile.error', defaultMessage: 'Profile update failed' }, error: { id: 'edit_profile.error', defaultMessage: 'Profile update failed' },
bioPlaceholder: { id: 'edit_profile.fields.bio_placeholder', defaultMessage: 'Tell us about yourself.' }, bioPlaceholder: { id: 'edit_profile.fields.bio_placeholder', defaultMessage: 'Tell us about yourself.' },
@ -142,7 +143,7 @@ const accountToCredentials = (account: Account): AccountCredentials => {
}; };
}; };
const ProfileField: StreamfieldComponent<AccountCredentialsField> = ({ value, onChange }) => { const ProfileField: StreamfieldComponent<AccountCredentialsField> = ({ index, value, onChange }) => {
const intl = useIntl(); const intl = useIntl();
const handleChange = (key: string): React.ChangeEventHandler<HTMLInputElement> => e => { const handleChange = (key: string): React.ChangeEventHandler<HTMLInputElement> => e => {
@ -156,7 +157,7 @@ const ProfileField: StreamfieldComponent<AccountCredentialsField> = ({ value, on
outerClassName='w-2/5 grow' outerClassName='w-2/5 grow'
value={value.name} value={value.name}
onChange={handleChange('name')} onChange={handleChange('name')}
placeholder={intl.formatMessage(messages.metaFieldLabel)} placeholder={index === 0 ? intl.formatMessage(messages.firstMetaFieldLabel) : intl.formatMessage(messages.metaFieldLabel)}
/> />
<Input <Input
type='text' type='text'

View file

@ -655,6 +655,7 @@
"edit_profile.fields.locked_label": "Lock account", "edit_profile.fields.locked_label": "Lock account",
"edit_profile.fields.meta_fields.content_placeholder": "Content", "edit_profile.fields.meta_fields.content_placeholder": "Content",
"edit_profile.fields.meta_fields.label_placeholder": "Label", "edit_profile.fields.meta_fields.label_placeholder": "Label",
"edit_profile.fields.meta_fields.label_placeholder.first": "Label (e.g. pronouns)",
"edit_profile.fields.meta_fields_label": "Profile fields", "edit_profile.fields.meta_fields_label": "Profile fields",
"edit_profile.fields.rss_label": "Enable RSS feed for public posts", "edit_profile.fields.rss_label": "Enable RSS feed for public posts",
"edit_profile.fields.stranger_notifications_label": "Block notifications from strangers", "edit_profile.fields.stranger_notifications_label": "Block notifications from strangers",

View file

@ -655,6 +655,7 @@
"edit_profile.fields.locked_label": "Zablokuj konto", "edit_profile.fields.locked_label": "Zablokuj konto",
"edit_profile.fields.meta_fields.content_placeholder": "Treść", "edit_profile.fields.meta_fields.content_placeholder": "Treść",
"edit_profile.fields.meta_fields.label_placeholder": "Podpis", "edit_profile.fields.meta_fields.label_placeholder": "Podpis",
"edit_profile.fields.meta_fields.label_placeholder.first": "Podpis (np. zaimki)",
"edit_profile.fields.meta_fields_label": "Pola profilu", "edit_profile.fields.meta_fields_label": "Pola profilu",
"edit_profile.fields.rss_label": "Włącz kanał RSS dla publicznych wpisów", "edit_profile.fields.rss_label": "Włącz kanał RSS dla publicznych wpisów",
"edit_profile.fields.stranger_notifications_label": "Blokuj powiadomienia od nieznajomych", "edit_profile.fields.stranger_notifications_label": "Blokuj powiadomienia od nieznajomych",