import React, {useState} from 'react' import {ComAtprotoBlobUpload} from '../../../third-party/api/index' import * as Toast from '../util/Toast' import {StyleSheet, Text, TouchableOpacity, View} from 'react-native' import LinearGradient from 'react-native-linear-gradient' import {BottomSheetScrollView, BottomSheetTextInput} from '@gorhom/bottom-sheet' import {Image as PickedImage} from 'react-native-image-crop-picker' import {ErrorMessage} from '../util/ErrorMessage' import {useStores} from '../../../state' import {ProfileViewModel} from '../../../state/models/profile-view' import {s, colors, gradients} from '../../lib/styles' import { enforceLen, MAX_DISPLAY_NAME, MAX_DESCRIPTION, } from '../../../lib/strings' import {UserBanner} from '../util/UserBanner' import {UserAvatar} from '../util/UserAvatar' export const snapPoints = ['80%'] export function Component({ profileView, onUpdate, }: { profileView: ProfileViewModel onUpdate?: () => void }) { const store = useStores() const [error, setError] = useState('') const [displayName, setDisplayName] = useState( profileView.displayName || '', ) const [description, setDescription] = useState( profileView.description || '', ) const [userBanner, setUserBanner] = useState( profileView.userBanner, ) const [userAvatar, setUserAvatar] = useState( profileView.avatar, ) const [newUserAvatar, setNewUserAvatar] = useState() const onPressCancel = () => { store.shell.closeModal() } const onSelectNewAvatar = (img: PickedImage) => { console.log(img) setNewUserAvatar(img) setUserAvatar(img.path) } const onPressSave = async () => { if (error) { setError('') } try { await profileView.updateProfile( { displayName, description, }, newUserAvatar, userBanner, // TEMP ) Toast.show('Profile updated') onUpdate?.() store.shell.closeModal() } catch (e: any) { if (e instanceof ComAtprotoBlobUpload.InvalidBlobError) { setError(e.message) } else { // TODO replace when error detection is correct setError(e.message) // setError( // 'Failed to save your profile. Check your internet connection and try again.', // ) } } } return ( Edit my profile {error !== '' && ( )} Display Name setDisplayName(enforceLen(v, MAX_DISPLAY_NAME))} /> Description setDescription(enforceLen(v, MAX_DESCRIPTION))} /> Save Changes Cancel ) } const styles = StyleSheet.create({ inner: { padding: 14, }, title: { textAlign: 'center', fontWeight: 'bold', fontSize: 24, marginBottom: 18, }, label: { fontWeight: 'bold', paddingHorizontal: 4, paddingBottom: 4, marginTop: 20, }, textInput: { borderWidth: 1, borderColor: colors.gray3, borderRadius: 6, paddingHorizontal: 14, paddingVertical: 10, fontSize: 16, }, textArea: { borderWidth: 1, borderColor: colors.gray3, borderRadius: 6, paddingHorizontal: 12, paddingTop: 10, fontSize: 16, height: 100, textAlignVertical: 'top', }, btn: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', width: '100%', borderRadius: 32, padding: 10, marginBottom: 10, }, avi: { position: 'absolute', top: 80, left: 10, width: 84, height: 84, borderWidth: 2, borderRadius: 42, borderColor: colors.white, backgroundColor: colors.white, }, photos: { marginBottom: 36, marginHorizontal: -14, }, })