import React, { memo, useCallback, useEffect, useRef, } from '../../../lib/teact/teact'; import { getActions } from '../../../global'; import type { FC } from '../../../lib/teact/teact'; import type { ApiPhoto } from '../../../api/types'; import useFlag from '../../../hooks/useFlag'; import useLang from '../../../hooks/useLang'; import ListItem from '../../ui/ListItem'; import SelectAvatar from '../../ui/SelectAvatar'; import Avatar from '../../common/Avatar'; import ConfirmDialog from '../../ui/ConfirmDialog'; import styles from './SettingsPrivacyPublicPhoto.module.scss'; type OwnProps = { currentUserId: string; hasCurrentUserFullInfo?: boolean; currentUserFallbackPhoto?: ApiPhoto; }; const SettingsPrivacyPublicProfilePhoto: FC = ({ currentUserId, hasCurrentUserFullInfo, currentUserFallbackPhoto, }) => { const { loadFullUser, uploadProfilePhoto, deleteProfilePhoto, showNotification, } = getActions(); const lang = useLang(); const [isDeleteFallbackPhotoModalOpen, openDeleteFallbackPhotoModal, closeDeleteFallbackPhotoModal] = useFlag(false); // eslint-disable-next-line no-null/no-null const inputRef = useRef(null); useEffect(() => { if (!hasCurrentUserFullInfo) { loadFullUser({ userId: currentUserId }); } }, [hasCurrentUserFullInfo, currentUserId, loadFullUser]); const handleSelectFile = useCallback((file: File) => { uploadProfilePhoto({ file, isFallback: true, }); showNotification({ message: lang('Privacy.ProfilePhoto.PublicPhotoSuccess'), }); }, [lang, showNotification, uploadProfilePhoto]); const handleConfirmDelete = useCallback(() => { closeDeleteFallbackPhotoModal(); deleteProfilePhoto({ photo: currentUserFallbackPhoto! }); }, [closeDeleteFallbackPhotoModal, deleteProfilePhoto, currentUserFallbackPhoto]); const handleOpenFileSelector = useCallback(() => { inputRef.current?.click(); }, []); return (
{lang(currentUserFallbackPhoto ? 'Privacy.ProfilePhoto.UpdatePublicPhoto' : 'Privacy.ProfilePhoto.SetPublicPhoto')} {currentUserFallbackPhoto && ( } onClick={openDeleteFallbackPhotoModal} destructive > {lang(currentUserFallbackPhoto.isVideo ? 'Privacy.ProfilePhoto.RemovePublicVideo' : 'Privacy.ProfilePhoto.RemovePublicPhoto')} )}

{lang('Privacy.ProfilePhoto.PublicPhotoInfo')}

); }; export default memo(SettingsPrivacyPublicProfilePhoto);