diff --git a/native/components/emoji-avatar-creation.react.js b/native/components/emoji-avatar-creation.react.js --- a/native/components/emoji-avatar-creation.react.js +++ b/native/components/emoji-avatar-creation.react.js @@ -9,26 +9,52 @@ } from 'react-native'; import EmojiPicker from 'rn-emoji-keyboard'; +import { changeThreadSettingsActionTypes } from 'lib/actions/thread-actions.js'; import { updateUserAvatarActionTypes } from 'lib/actions/user-actions.js'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; +import { savedEmojiAvatarSelectorForThread } from 'lib/selectors/thread-selectors.js'; import { savedEmojiAvatarSelectorForCurrentUser } from 'lib/selectors/user-selectors.js'; import type { ClientEmojiAvatar } from 'lib/types/avatar-types.js'; import Avatar from '../components/avatar.react.js'; import Button from '../components/button.react.js'; import ColorRows from '../components/color-rows.react.js'; +import type { NavigationRoute } from '../navigation/route-names.js'; +import type { ProfileNavigationProp } from '../profile/profile.react.js'; import { useSelector } from '../redux/redux-utils.js'; import { useStyles } from '../themes/colors.js'; -import { useSaveUserAvatar } from '../utils/avatar-utils.js'; +import { + useSaveUserAvatar, + useSaveThreadAvatar, +} from '../utils/avatar-utils.js'; -const loadingStatusSelector = createLoadingStatusSelector( +const userAvatarLoadingStatusSelector = createLoadingStatusSelector( updateUserAvatarActionTypes, ); -function EmojiAvatarCreation(): React.Node { - const savedEmojiAvatarFunc = useSelector( - savedEmojiAvatarSelectorForCurrentUser, - ); +const threadAvatarLoadingStatusSelector = createLoadingStatusSelector( + changeThreadSettingsActionTypes, + `${changeThreadSettingsActionTypes.started}:avatar`, +); + +export type EmojiAvatarCreationParams = { + +threadID?: string, + +containingThreadID?: ?string, +}; + +type Props = { + +navigation: ProfileNavigationProp<'EmojiAvatarCreation'>, + +route: NavigationRoute<'EmojiAvatarCreation'>, +}; + +function EmojiAvatarCreation(props: Props): React.Node { + const { threadID, containingThreadID } = props.route.params; + + const selector = threadID + ? savedEmojiAvatarSelectorForThread(threadID, containingThreadID) + : savedEmojiAvatarSelectorForCurrentUser; + + const savedEmojiAvatarFunc = useSelector(selector); const [pendingEmoji, setPendingEmoji] = React.useState( () => savedEmojiAvatarFunc().emoji, @@ -42,9 +68,13 @@ const styles = useStyles(unboundStyles); const saveUserAvatar = useSaveUserAvatar(); + const saveThreadAvatar = useSaveThreadAvatar(); - const saveAvatarCallLoading = useSelector( - state => loadingStatusSelector(state) === 'loading', + const saveUserAvatarCallLoading = useSelector( + state => userAvatarLoadingStatusSelector(state) === 'loading', + ); + const saveThreadAvatarCallLoading = useSelector( + state => threadAvatarLoadingStatusSelector(state) === 'loading', ); const onPressEditEmoji = React.useCallback(() => { @@ -58,8 +88,12 @@ color: pendingColor, }; - saveUserAvatar(newEmojiAvatarRequest); - }, [pendingColor, pendingEmoji, saveUserAvatar]); + if (!threadID) { + saveUserAvatar(newEmojiAvatarRequest); + } else { + saveThreadAvatar(newEmojiAvatarRequest, threadID); + } + }, [pendingColor, pendingEmoji, saveThreadAvatar, saveUserAvatar, threadID]); const onPressReset = React.useCallback(() => { const resetEmojiAvatar = savedEmojiAvatarFunc(); @@ -87,7 +121,7 @@ ); const loadingContainer = React.useMemo(() => { - if (!saveAvatarCallLoading) { + if (!saveUserAvatarCallLoading && !saveThreadAvatarCallLoading) { return null; } @@ -96,7 +130,11 @@ ); - }, [saveAvatarCallLoading, styles.loadingContainer]); + }, [ + saveThreadAvatarCallLoading, + saveUserAvatarCallLoading, + styles.loadingContainer, + ]); return ( @@ -124,14 +162,14 @@ diff --git a/native/navigation/route-names.js b/native/navigation/route-names.js --- a/native/navigation/route-names.js +++ b/native/navigation/route-names.js @@ -21,6 +21,7 @@ import type { SidebarListModalParams } from '../chat/sidebar-list-modal.react.js'; import type { SubchannelListModalParams } from '../chat/subchannels-list-modal.react.js'; import type { TextMessageTooltipModalParams } from '../chat/text-message-tooltip-modal.react.js'; +import type { EmojiAvatarCreationParams } from '../components/emoji-avatar-creation.react.js'; import type { CameraModalParams } from '../media/camera-modal.react.js'; import type { ImageModalParams } from '../media/image-modal.react.js'; import type { VideoPlaybackModalParams } from '../media/video-playback-modal.react.js'; @@ -128,6 +129,7 @@ +MessageList: MessageListParams, +ComposeSubchannel: ComposeSubchannelParams, +ThreadSettings: ThreadSettingsParams, + +EmojiAvatarCreation: EmojiAvatarCreationParams, +DeleteThread: DeleteThreadParams, +FullScreenThreadMediaGallery: FullScreenThreadMediaGalleryParams, }; @@ -139,7 +141,7 @@ export type ProfileParamList = { +ProfileScreen: void, - +EmojiAvatarCreation: void, + +EmojiAvatarCreation: EmojiAvatarCreationParams, +EditPassword: void, +DeleteAccount: void, +BuildInfo: void,