Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3746018
D8841.id30162.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D8841.id30162.diff
View Options
diff --git a/web/avatars/edit-thread-avatar-menu.react.js b/web/avatars/edit-thread-avatar-menu.react.js
--- a/web/avatars/edit-thread-avatar-menu.react.js
+++ b/web/avatars/edit-thread-avatar-menu.react.js
@@ -7,9 +7,11 @@
import SWMansionIcon from 'lib/components/SWMansionIcon.react.js';
import type { RawThreadInfo, ThreadInfo } from 'lib/types/thread-types.js';
+import { useUploadAvatarMedia } from './avatar-hooks.react.js';
import css from './edit-avatar-menu.css';
import MenuItem from '../components/menu-item.react.js';
import Menu from '../components/menu.react.js';
+import { allowedMimeTypeString } from '../media/file-utils.js';
const editIcon = (
<div className={css.editAvatarBadge}>
@@ -45,10 +47,52 @@
[removeThreadAvatar],
);
- const menuItems = React.useMemo(() => [removeMenuItem], [removeMenuItem]);
+ const imageInputRef = React.useRef();
+ const onImageMenuItemClicked = React.useCallback(
+ () => imageInputRef.current?.click(),
+ [],
+ );
+
+ const uploadAvatarMedia = useUploadAvatarMedia();
+ const onImageSelected = React.useCallback(
+ async event => {
+ const uploadResult = await uploadAvatarMedia(event.target.files[0]);
+ baseSetThreadAvatar(threadInfo.id, {
+ type: 'image',
+ uploadID: uploadResult.id,
+ });
+ },
+ [baseSetThreadAvatar, threadInfo.id, uploadAvatarMedia],
+ );
+
+ const imageMenuItem = React.useMemo(
+ () => (
+ <MenuItem
+ key="image"
+ text="Select image"
+ icon="image-1"
+ onClick={onImageMenuItemClicked}
+ />
+ ),
+ [onImageMenuItemClicked],
+ );
+
+ const menuItems = React.useMemo(() => {
+ const items = [imageMenuItem];
+ if (threadInfo.avatar) {
+ items.push(removeMenuItem);
+ }
+ return items;
+ }, [imageMenuItem, removeMenuItem, threadInfo.avatar]);
return (
<div>
+ <input
+ type="file"
+ onChange={onImageSelected}
+ ref={imageInputRef}
+ accept={allowedMimeTypeString}
+ />
<Menu icon={editIcon}>{menuItems}</Menu>
</div>
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 10, 5:36 PM (18 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2846658
Default Alt Text
D8841.id30162.diff (2 KB)
Attached To
Mode
D8841: [web] Add image avatar support to `EditThreadAvatarMenu`
Attached
Detach File
Event Timeline
Log In to Comment