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 @@ -4,11 +4,13 @@ import * as React from 'react'; import { EditThreadAvatarContext } from 'lib/components/base-edit-thread-avatar-provider.react.js'; +import { useModalContext } from 'lib/components/modal-provider.react.js'; 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 ThreadEmojiAvatarSelectionModal from './thread-emoji-avatar-selection-modal.react.js'; import MenuItem from '../components/menu-item.react.js'; import Menu from '../components/menu.react.js'; import { allowedMimeTypeString } from '../media/file-utils.js'; @@ -77,13 +79,32 @@ [onImageMenuItemClicked], ); + const { pushModal } = useModalContext(); + const openEmojiSelectionModal = React.useCallback( + () => + pushModal(), + [pushModal, threadInfo], + ); + + const emojiMenuItem = React.useMemo( + () => ( + + ), + [openEmojiSelectionModal], + ); + const menuItems = React.useMemo(() => { - const items = [imageMenuItem]; + const items = [emojiMenuItem, imageMenuItem]; if (threadInfo.avatar) { items.push(removeMenuItem); } return items; - }, [imageMenuItem, removeMenuItem, threadInfo.avatar]); + }, [emojiMenuItem, imageMenuItem, removeMenuItem, threadInfo.avatar]); return (
diff --git a/web/avatars/thread-emoji-avatar-selection-modal.react.js b/web/avatars/thread-emoji-avatar-selection-modal.react.js new file mode 100644 --- /dev/null +++ b/web/avatars/thread-emoji-avatar-selection-modal.react.js @@ -0,0 +1,54 @@ +// @flow + +import invariant from 'invariant'; +import * as React from 'react'; + +import { EditThreadAvatarContext } from 'lib/components/base-edit-thread-avatar-provider.react.js'; +import { + getDefaultAvatar, + useAvatarForThread, +} from 'lib/shared/avatar-utils.js'; +import type { + ClientAvatar, + ClientEmojiAvatar, +} from 'lib/types/avatar-types.js'; +import type { RawThreadInfo, ThreadInfo } from 'lib/types/thread-types.js'; + +import EmojiAvatarSelectionModal from './emoji-avatar-selection-modal.react.js'; + +type Props = { + +threadInfo: ThreadInfo | RawThreadInfo, +}; + +function ThreadEmojiAvatarSelectionModal(props: Props): React.Node { + const { threadInfo } = props; + const editThreadAvatarContext = React.useContext(EditThreadAvatarContext); + invariant(editThreadAvatarContext, 'editThreadAvatarContext should be set'); + + const { baseSetThreadAvatar, threadAvatarSaveInProgress } = + editThreadAvatarContext; + + const currentThreadAvatar: ClientAvatar = useAvatarForThread(threadInfo); + const defaultThreadAvatar: ClientEmojiAvatar = getDefaultAvatar( + threadInfo.id, + threadInfo.color, + ); + + const setEmojiAvatar = React.useCallback( + async (pendingEmojiAvatar: ClientEmojiAvatar): Promise => { + await baseSetThreadAvatar(threadInfo.id, pendingEmojiAvatar); + }, + [baseSetThreadAvatar, threadInfo.id], + ); + + return ( + + ); +} + +export default ThreadEmojiAvatarSelectionModal;