Profile editing: Uploading avatar and header images (#38189)

This commit is contained in:
Echo authored and GitHub committed 2026-03-16 11:39:52 +00:00
1 parent 9c8be1e721
commit 21c27eb3af
14 files changed
+647 -39

No files matched your search

@@ -12,11 +12,9 @@ import { openModal } from '@/mastodon/actions/modal';
import { Dropdown } from '@/mastodon/components/dropdown_menu';
import { IconButton } from '@/mastodon/components/icon_button';
import type { MenuItem } from '@/mastodon/models/dropdown_menu';
import {
createAppSelector,
useAppDispatch,
useAppSelector,
} from '@/mastodon/store';
import type { ImageLocation } from '@/mastodon/reducers/slices/profile_edit';
import { selectImageInfo } from '@/mastodon/reducers/slices/profile_edit';
import { useAppDispatch, useAppSelector } from '@/mastodon/store';
import AddIcon from '@/material-icons/400-24px/add.svg?react';
import DeleteIcon from '@/material-icons/400-24px/delete.svg?react';
import EditIcon from '@/material-icons/400-24px/edit.svg?react';
@@ -50,36 +48,15 @@ const messages = defineMessages({
},
});
export type ImageLocation = 'avatar' | 'header';
const selectImageInfo = createAppSelector(
[
(state) => state.profileEdit.profile,
(_, location: ImageLocation) => location,
],
(profile, location) => {
if (!profile) {
return {
hasImage: false,
hasAlt: false,
};
}
return {
hasImage: !!profile[`${location}Static`],
hasAlt: !!profile[`${location}Description`],
};
},
);
export const AccountImageEdit: FC<{
className?: string;
location: ImageLocation;
}> = ({ className, location }) => {
const intl = useIntl();
const { hasAlt, hasImage } = useAppSelector((state) =>
const { alt, src } = useAppSelector((state) =>
selectImageInfo(state, location),
);
const hasAlt = !!alt;
const dispatch = useAppDispatch();
const handleModal = useCallback(
@@ -125,7 +102,7 @@ export const AccountImageEdit: FC<{
const iconClassName = classNames(classes.imageButton, className);
if (!hasImage) {
if (!src) {
return (
<IconButton
title={intl.formatMessage(messages.add)}