signal-desktop/ts/state/smart/ProfileEditorModal.tsx

84 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2021 Signal Messenger, LLC
2021-07-19 19:26:06 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2022-10-18 17:12:02 +00:00
import React from 'react';
2021-07-19 19:26:06 +00:00
import { connect } from 'react-redux';
import { mapDispatchToProps } from '../actions';
import type { PropsDataType as ProfileEditorModalPropsType } from '../../components/ProfileEditorModal';
import { ProfileEditorModal } from '../../components/ProfileEditorModal';
import type { PropsDataType } from '../../components/ProfileEditor';
2023-02-13 18:51:41 +00:00
import { storageServiceUploadJob } from '../../services/storage';
2022-10-18 17:12:02 +00:00
import { SmartEditUsernameModalBody } from './EditUsernameModalBody';
import type { StateType } from '../reducer';
2021-07-19 19:26:06 +00:00
import { getIntl } from '../selectors/user';
2023-02-13 18:51:41 +00:00
import {
getEmojiSkinTone,
getUsernamesEnabled,
getHasCompletedUsernameOnboarding,
} from '../selectors/items';
2022-10-18 17:12:02 +00:00
import { getMe } from '../selectors/conversations';
2021-07-19 19:26:06 +00:00
import { selectRecentEmojis } from '../selectors/emojis';
2022-10-18 17:12:02 +00:00
import { getUsernameEditState } from '../selectors/username';
function renderEditUsernameModalBody(props: {
onClose: () => void;
}): JSX.Element {
return <SmartEditUsernameModalBody {...props} />;
}
2021-07-19 19:26:06 +00:00
2023-02-13 18:51:41 +00:00
async function markCompletedUsernameOnboarding(): Promise<void> {
await window.storage.put('hasCompletedUsernameOnboarding', true);
storageServiceUploadJob();
}
2021-07-19 19:26:06 +00:00
function mapStateToProps(
state: StateType
): Omit<PropsDataType, 'onEditStateChange' | 'onProfileChanged'> &
ProfileEditorModalPropsType {
2021-08-06 00:17:05 +00:00
const {
profileAvatarPath,
2021-08-06 00:17:05 +00:00
avatars: userAvatarData = [],
aboutText,
aboutEmoji,
color,
firstName,
familyName,
id: conversationId,
username,
2021-08-06 00:17:05 +00:00
} = getMe(state);
2021-07-19 19:26:06 +00:00
const recentEmojis = selectRecentEmojis(state);
const skinTone = getEmojiSkinTone(state);
const isUsernameFlagEnabled = getUsernamesEnabled(state);
2023-02-13 18:51:41 +00:00
const hasCompletedUsernameOnboarding =
getHasCompletedUsernameOnboarding(state);
2022-10-18 17:12:02 +00:00
const usernameEditState = getUsernameEditState(state);
2021-07-19 19:26:06 +00:00
return {
aboutEmoji,
aboutText,
profileAvatarPath,
2021-08-06 00:17:05 +00:00
color,
conversationId,
2021-07-19 19:26:06 +00:00
familyName,
firstName: String(firstName),
2023-02-13 18:51:41 +00:00
hasCompletedUsernameOnboarding,
2021-07-19 19:26:06 +00:00
hasError: state.globalModals.profileEditorHasError,
i18n: getIntl(state),
isUsernameFlagEnabled,
2023-02-13 18:51:41 +00:00
markCompletedUsernameOnboarding,
2021-07-19 19:26:06 +00:00
recentEmojis,
skinTone,
2021-08-06 00:17:05 +00:00
userAvatarData,
username,
2022-10-18 17:12:02 +00:00
usernameEditState,
renderEditUsernameModalBody,
2021-07-19 19:26:06 +00:00
};
}
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartProfileEditorModal = smart(ProfileEditorModal);