Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3295478
D7428.id25132.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D7428.id25132.diff
View Options
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<string>(
() => 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 @@
<ActivityIndicator size="large" color="white" />
</View>
);
- }, [saveAvatarCallLoading, styles.loadingContainer]);
+ }, [
+ saveThreadAvatarCallLoading,
+ saveUserAvatarCallLoading,
+ styles.loadingContainer,
+ ]);
return (
<View style={styles.container}>
@@ -124,14 +162,14 @@
<Button
onPress={onPressSetAvatar}
style={styles.saveButton}
- disabled={saveAvatarCallLoading}
+ disabled={saveUserAvatarCallLoading || saveThreadAvatarCallLoading}
>
<Text style={styles.saveButtonText}>Save Avatar</Text>
</Button>
<Button
onPress={onPressReset}
style={styles.resetButton}
- disabled={saveAvatarCallLoading}
+ disabled={saveUserAvatarCallLoading || saveThreadAvatarCallLoading}
>
<Text style={styles.resetButtonText}>Reset</Text>
</Button>
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,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 9:48 PM (19 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2531477
Default Alt Text
D7428.id25132.diff (5 KB)
Attached To
Mode
D7428: [native] extend emoji avatar creation to handle thread avatars
Attached
Detach File
Event Timeline
Log In to Comment