diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-12-14 15:35:15 -0600 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-12-14 15:35:15 -0600 |
commit | 4966b2152eb213bac34cbcb0ff01c246b7746f5c (patch) | |
tree | 5cc90408631c984018f1b5a4b06f428d3d31d4a5 /src/view/com/composer/ComposePost.tsx | |
parent | 345ec83f26e209929ca86b3885227e8508fb2cb8 (diff) | |
download | voidsky-4966b2152eb213bac34cbcb0ff01c246b7746f5c.tar.zst |
Add post embeds (images and external links)
Diffstat (limited to 'src/view/com/composer/ComposePost.tsx')
-rw-r--r-- | src/view/com/composer/ComposePost.tsx | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/src/view/com/composer/ComposePost.tsx b/src/view/com/composer/ComposePost.tsx index 7f4de654c..c6d371bc6 100644 --- a/src/view/com/composer/ComposePost.tsx +++ b/src/view/com/composer/ComposePost.tsx @@ -29,7 +29,6 @@ import {detectLinkables} from '../../../lib/strings' import {UserLocalPhotosModel} from '../../../state/models/user-local-photos' import {PhotoCarouselPicker} from './PhotoCarouselPicker' import {SelectedPhoto} from './SelectedPhoto' -import {IMAGES_ENABLED} from '../../../build-flags' const MAX_TEXT_LENGTH = 256 const DANGER_TEXT_LENGTH = MAX_TEXT_LENGTH @@ -46,6 +45,7 @@ export const ComposePost = observer(function ComposePost({ const store = useStores() const textInput = useRef<TextInput>(null) const [isProcessing, setIsProcessing] = useState(false) + const [processingState, setProcessingState] = useState('') const [error, setError] = useState('') const [text, setText] = useState('') const [selectedPhotos, setSelectedPhotos] = useState<string[]>([]) @@ -81,6 +81,10 @@ export const ComposePost = observer(function ComposePost({ } }, []) + const onSelectPhotos = (photos: string[]) => { + setSelectedPhotos(photos) + } + const onChangeText = (newText: string) => { setText(newText) @@ -109,15 +113,16 @@ export const ComposePost = observer(function ComposePost({ } setIsProcessing(true) try { - const replyRef = replyTo - ? {uri: replyTo.uri, cid: replyTo.cid} - : undefined - await apilib.post(store, text, replyRef, autocompleteView.knownHandles) - } catch (e: any) { - console.error(`Failed to create post: ${e.toString()}`) - setError( - 'Post failed to upload. Please check your Internet connection and try again.', + await apilib.post( + store, + text, + replyTo?.uri, + selectedPhotos, + autocompleteView.knownHandles, + setProcessingState, ) + } catch (e: any) { + setError(e.message) setIsProcessing(false) return } @@ -189,6 +194,11 @@ export const ComposePost = observer(function ComposePost({ </View> )} </View> + {isProcessing ? ( + <View style={styles.processingLine}> + <Text>{processingState}</Text> + </View> + ) : undefined} {error !== '' && ( <View style={styles.errorLine}> <View style={styles.errorIcon}> @@ -198,7 +208,7 @@ export const ComposePost = observer(function ComposePost({ size={10} /> </View> - <Text style={s.red4}>{error}</Text> + <Text style={[s.red4, s.flex1]}>{error}</Text> </View> )} {replyTo ? ( @@ -240,18 +250,15 @@ export const ComposePost = observer(function ComposePost({ </View> <SelectedPhoto selectedPhotos={selectedPhotos} - setSelectedPhotos={setSelectedPhotos} + onSelectPhotos={onSelectPhotos} /> - {IMAGES_ENABLED && - localPhotos.photos != null && - text === '' && - selectedPhotos.length === 0 && ( - <PhotoCarouselPicker - selectedPhotos={selectedPhotos} - setSelectedPhotos={setSelectedPhotos} - localPhotos={localPhotos} - /> - )} + {localPhotos.photos != null && selectedPhotos.length < 4 && ( + <PhotoCarouselPicker + selectedPhotos={selectedPhotos} + onSelectPhotos={onSelectPhotos} + localPhotos={localPhotos} + /> + )} <View style={styles.bottomBar}> <View style={s.flex1} /> <Text style={[s.mr10, {color: progressColor}]}> @@ -322,6 +329,13 @@ const styles = StyleSheet.create({ paddingHorizontal: 20, paddingVertical: 6, }, + processingLine: { + backgroundColor: colors.gray1, + borderRadius: 6, + paddingHorizontal: 8, + paddingVertical: 6, + marginBottom: 6, + }, errorLine: { flexDirection: 'row', backgroundColor: colors.red1, |