diff --git a/native/avatars/emoji-avatar-creation.react.js b/native/avatars/emoji-avatar-creation.react.js index f74cb24b6..de83f5bb8 100644 --- a/native/avatars/emoji-avatar-creation.react.js +++ b/native/avatars/emoji-avatar-creation.react.js @@ -1,215 +1,210 @@ // @flow import * as React from 'react'; import { View, Text, TouchableWithoutFeedback, ActivityIndicator, } from 'react-native'; import EmojiPicker from 'rn-emoji-keyboard'; import type { UpdateUserAvatarRequest, ClientEmojiAvatar, } from 'lib/types/avatar-types'; import Avatar from './avatar.react.js'; import Button from '../components/button.react.js'; import ColorRows from '../components/color-rows.react.js'; -import { useSelector } from '../redux/redux-utils.js'; -import type { AppState } from '../redux/state-types.js'; import { useStyles } from '../themes/colors.js'; type Props = { +saveAvatarCall: (newAvatarRequest: UpdateUserAvatarRequest) => mixed, +saveAvatarCallLoading: boolean, - +savedEmojiAvatarSelector: (state: AppState) => () => ClientEmojiAvatar, + +savedEmojiAvatarFunc: () => ClientEmojiAvatar, }; function EmojiAvatarCreation(props: Props): React.Node { - const { saveAvatarCall, saveAvatarCallLoading, savedEmojiAvatarSelector } = - props; - - const savedEmojiAvatarFunc = useSelector(savedEmojiAvatarSelector); + const { saveAvatarCall, saveAvatarCallLoading, savedEmojiAvatarFunc } = props; const [pendingEmoji, setPendingEmoji] = React.useState( () => savedEmojiAvatarFunc().emoji, ); const [pendingColor, setPendingColor] = React.useState( () => savedEmojiAvatarFunc().color, ); const [emojiKeyboardOpen, setEmojiKeyboardOpen] = React.useState(false); const styles = useStyles(unboundStyles); const onPressEditEmoji = React.useCallback(() => { setEmojiKeyboardOpen(true); }, []); const onPressSetAvatar = React.useCallback(() => { const newEmojiAvatarRequest = { type: 'emoji', emoji: pendingEmoji, color: pendingColor, }; saveAvatarCall(newEmojiAvatarRequest); }, [pendingColor, pendingEmoji, saveAvatarCall]); const onPressReset = React.useCallback(() => { const resetEmojiAvatar = savedEmojiAvatarFunc(); setPendingEmoji(resetEmojiAvatar.emoji); setPendingColor(resetEmojiAvatar.color); }, [savedEmojiAvatarFunc]); const onEmojiSelected = React.useCallback(emoji => { setPendingEmoji(emoji.emoji); }, []); const onEmojiKeyboardClose = React.useCallback( () => setEmojiKeyboardOpen(false), [], ); const stagedAvatarInfo: ClientEmojiAvatar = React.useMemo( () => ({ type: 'emoji', emoji: pendingEmoji, color: pendingColor, }), [pendingColor, pendingEmoji], ); const loadingContainer = React.useMemo(() => { if (!saveAvatarCallLoading) { return null; } return ( ); }, [saveAvatarCallLoading, styles.loadingContainer]); return ( {loadingContainer} Edit Emoji ); } const unboundStyles = { container: { flex: 1, justifyContent: 'space-between', }, emojiAvatarCreationContainer: { paddingTop: 16, }, stagedAvatarSection: { backgroundColor: 'panelForeground', paddingVertical: 24, alignItems: 'center', }, editEmojiText: { color: 'purpleLink', marginTop: 16, fontWeight: '500', fontSize: 16, lineHeight: 24, textAlign: 'center', }, colorRowsSection: { paddingVertical: 24, marginTop: 24, backgroundColor: 'panelForeground', alignItems: 'center', }, selectedColorOuterRing: { backgroundColor: 'modalSubtext', }, buttonsContainer: { paddingHorizontal: 16, paddingBottom: 8, }, saveButton: { backgroundColor: 'purpleButton', paddingVertical: 12, borderRadius: 8, }, saveButtonText: { color: 'whiteText', textAlign: 'center', fontWeight: '500', fontSize: 16, lineHeight: 24, }, resetButton: { padding: 12, borderRadius: 8, marginTop: 8, alignSelf: 'center', }, resetButtonText: { color: 'redText', textAlign: 'center', fontWeight: '500', fontSize: 16, lineHeight: 24, }, loadingContainer: { position: 'absolute', backgroundColor: 'black', width: 112, height: 112, borderRadius: 56, opacity: 0.6, justifyContent: 'center', }, }; export default EmojiAvatarCreation; diff --git a/native/chat/settings/emoji-thread-avatar-creation.react.js b/native/chat/settings/emoji-thread-avatar-creation.react.js index f248951d0..546d42214 100644 --- a/native/chat/settings/emoji-thread-avatar-creation.react.js +++ b/native/chat/settings/emoji-thread-avatar-creation.react.js @@ -1,55 +1,57 @@ // @flow import invariant from 'invariant'; import * as React from 'react'; import { savedEmojiAvatarSelectorForThread } from 'lib/selectors/thread-selectors.js'; import type { RawThreadInfo, ThreadInfo } from 'lib/types/thread-types.js'; import { EditThreadAvatarContext } from '../../avatars/edit-thread-avatar-provider.react.js'; import EmojiAvatarCreation from '../../avatars/emoji-avatar-creation.react.js'; import type { ChatNavigationProp } from '../../chat/chat.react.js'; import { displayActionResultModal } from '../../navigation/action-result-modal.js'; import type { NavigationRoute } from '../../navigation/route-names.js'; +import { useSelector } from '../../redux/redux-utils.js'; export type EmojiThreadAvatarCreationParams = { +threadInfo: RawThreadInfo | ThreadInfo, }; type Props = { +navigation: ChatNavigationProp<'EmojiThreadAvatarCreation'>, +route: NavigationRoute<'EmojiThreadAvatarCreation'>, }; function EmojiThreadAvatarCreation(props: Props): React.Node { const { id: threadID, containingThreadID } = props.route.params.threadInfo; const selector = savedEmojiAvatarSelectorForThread( threadID, containingThreadID, ); + const savedEmojiAvatarFunc = useSelector(selector); const editThreadAvatarContext = React.useContext(EditThreadAvatarContext); invariant(editThreadAvatarContext, 'editThreadAvatarContext should be set'); const { setThreadAvatar, threadAvatarSaveInProgress } = editThreadAvatarContext; const setAvatar = React.useCallback( async avatarRequest => { const result = await setThreadAvatar(threadID, avatarRequest); displayActionResultModal('Avatar updated!'); return result; }, [setThreadAvatar, threadID], ); return ( ); } export default EmojiThreadAvatarCreation; diff --git a/native/profile/emoji-user-avatar-creation.react.js b/native/profile/emoji-user-avatar-creation.react.js index 08bf175b6..ab93c33b5 100644 --- a/native/profile/emoji-user-avatar-creation.react.js +++ b/native/profile/emoji-user-avatar-creation.react.js @@ -1,36 +1,41 @@ // @flow import invariant from 'invariant'; import * as React from 'react'; import { savedEmojiAvatarSelectorForCurrentUser } from 'lib/selectors/user-selectors.js'; import { EditUserAvatarContext } from '../avatars/edit-user-avatar-provider.react.js'; import EmojiAvatarCreation from '../avatars/emoji-avatar-creation.react.js'; import { displayActionResultModal } from '../navigation/action-result-modal.js'; +import { useSelector } from '../redux/redux-utils.js'; // eslint-disable-next-line no-unused-vars function EmojiUserAvatarCreation(props: { ... }): React.Node { const editUserAvatarContext = React.useContext(EditUserAvatarContext); invariant(editUserAvatarContext, 'editUserAvatarContext should be set'); const { setUserAvatar, userAvatarSaveInProgress } = editUserAvatarContext; const setAvatar = React.useCallback( async avatarRequest => { const result = await setUserAvatar(avatarRequest); displayActionResultModal('Avatar updated!'); return result; }, [setUserAvatar], ); + const savedEmojiAvatarFunc = useSelector( + savedEmojiAvatarSelectorForCurrentUser, + ); + return ( ); } export default EmojiUserAvatarCreation;