1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
import React, {useState} from 'react'
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 {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 = ['60%']
export function Component({
profileView,
onUpdate,
}: {
profileView: ProfileViewModel
onUpdate?: () => void
}) {
const store = useStores()
const [error, setError] = useState<string>('')
const [displayName, setDisplayName] = useState<string>(
profileView.displayName || '',
)
const [description, setDescription] = useState<string>(
profileView.description || '',
)
const onPressCancel = () => {
store.shell.closeModal()
}
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')
onUpdate?.()
store.shell.closeModal()
} catch (e: any) {
console.error(e)
setError(
'Failed to save your profile. Check your internet connection and try again.',
)
}
}
return (
<View style={s.flex1}>
<BottomSheetScrollView style={styles.inner}>
<Text style={styles.title}>Edit my profile</Text>
{error !== '' && (
<View style={s.mb10}>
<ErrorMessage message={error} />
</View>
)}
<View style={styles.group}>
<Text style={styles.label}>Display Name</Text>
<BottomSheetTextInput
style={styles.textInput}
placeholder="e.g. Alice Roberts"
value={displayName}
onChangeText={v => setDisplayName(enforceLen(v, MAX_DISPLAY_NAME))}
/>
</View>
<View style={styles.group}>
<Text style={styles.label}>Description</Text>
<BottomSheetTextInput
style={[styles.textArea]}
placeholder="e.g. Artist, dog-lover, and memelord."
multiline
value={description}
onChangeText={v => setDescription(enforceLen(v, MAX_DESCRIPTION))}
/>
</View>
<TouchableOpacity style={s.mt10} onPress={onPressSave}>
<LinearGradient
colors={[gradients.primary.start, gradients.primary.end]}
start={{x: 0, y: 0}}
end={{x: 1, y: 1}}
style={[styles.btn]}>
<Text style={[s.white, s.bold]}>Save Changes</Text>
</LinearGradient>
</TouchableOpacity>
<TouchableOpacity style={s.mt5} onPress={onPressCancel}>
<View style={[styles.btn]}>
<Text style={[s.black, s.bold]}>Cancel</Text>
</View>
</TouchableOpacity>
</BottomSheetScrollView>
</View>
)
}
const styles = StyleSheet.create({
inner: {
padding: 14,
},
title: {
textAlign: 'center',
fontWeight: 'bold',
fontSize: 24,
marginBottom: 18,
},
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,
},
})
|