import React, {useState} from 'react' import Toast from '../util/Toast' import {StyleSheet, Text, TextInput, TouchableOpacity, View} from 'react-native' import LinearGradient from 'react-native-linear-gradient' 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 * as Profile from '../../../third-party/api/src/client/types/app/bsky/actor/profile' export const snapPoints = ['80%'] export function Component({profileView}: {profileView: ProfileViewModel}) { const store = useStores() const [error, setError] = useState('') const [displayName, setDisplayName] = useState( profileView.displayName || '', ) const [description, setDescription] = useState( profileView.description || '', ) const onPressSave = async () => { if (error) { setError('') } try { await profileView.updateProfile( (existing?: Profile.Record): Profile.Record => { if (existing) { existing.displayName = displayName existing.description = description return existing } return { displayName, description, } }, ) Toast.show('Profile updated', { position: Toast.positions.TOP, }) store.shell.closeModal() } catch (e: any) { console.error(e) 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 ) } const styles = StyleSheet.create({ inner: { padding: 14, }, group: { marginBottom: 10, }, label: { fontWeight: 'bold', paddingHorizontal: 4, paddingBottom: 4, }, 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, }, })