From 4966b2152eb213bac34cbcb0ff01c246b7746f5c Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Wed, 14 Dec 2022 15:35:15 -0600 Subject: Add post embeds (images and external links) --- src/view/com/composer/ComposePost.tsx | 56 ++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'src/view/com/composer/ComposePost.tsx') 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(null) const [isProcessing, setIsProcessing] = useState(false) + const [processingState, setProcessingState] = useState('') const [error, setError] = useState('') const [text, setText] = useState('') const [selectedPhotos, setSelectedPhotos] = useState([]) @@ -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({ )} + {isProcessing ? ( + + {processingState} + + ) : undefined} {error !== '' && ( @@ -198,7 +208,7 @@ export const ComposePost = observer(function ComposePost({ size={10} /> - {error} + {error} )} {replyTo ? ( @@ -240,18 +250,15 @@ export const ComposePost = observer(function ComposePost({ - {IMAGES_ENABLED && - localPhotos.photos != null && - text === '' && - selectedPhotos.length === 0 && ( - - )} + {localPhotos.photos != null && selectedPhotos.length < 4 && ( + + )} @@ -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, -- cgit 1.4.1