Fix newpost and ready for new version
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { View, TextInput, Image } from "react-native";
|
||||
import { Text, Button, Divider } from "react-native-paper";
|
||||
import { SafeAreaView } from "react-native-safe-area-context";
|
||||
@@ -9,11 +9,28 @@ import i18n from "../i18nMessages";
|
||||
import Media from '../components/Media';
|
||||
|
||||
|
||||
let NewPostView = ({ writeTo }) => {
|
||||
let NewPostView = (props) => {
|
||||
let [postContent, setPostContent] = useState('');
|
||||
let [extraContent, setExtraContent] = useState([]);
|
||||
let [toProfile, setToProfile] = useState([]);
|
||||
const [photo, setPhoto] = React.useState(null);
|
||||
const navigation = useNavigation();
|
||||
|
||||
useEffect(() => {
|
||||
let subscribed = true;
|
||||
const getProfileData = async () => {
|
||||
if (!props.route.params?.toProfile) return 0;
|
||||
await API.getUserProfile(props.route.params.toProfile).then((profileObj) => {
|
||||
if (!subscribed) return 0;
|
||||
setToProfile(profileObj);
|
||||
});
|
||||
};
|
||||
getProfileData();
|
||||
return () => {
|
||||
subscribed = false;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const pickImage = async () => {
|
||||
// No permissions request is necessary for launching the image library
|
||||
let result = await ImagePicker.launchImageLibraryAsync({
|
||||
@@ -27,8 +44,8 @@ let NewPostView = ({ writeTo }) => {
|
||||
setPhoto(result);
|
||||
let newPhotoURLs = await handleUploadPhoto(result);
|
||||
let newExtraContent = [extraContent]
|
||||
newPhotoURLs.forEach((newPhotoURL)=>{
|
||||
newExtraContent = ["@image:" + newPhotoURL].concat(newExtraContent);
|
||||
newPhotoURLs.forEach((newPhotoURL) => {
|
||||
newExtraContent = ["@image:" + newPhotoURL].concat(newExtraContent);
|
||||
});
|
||||
setExtraContent(newExtraContent);
|
||||
setPhoto(null);
|
||||
@@ -64,7 +81,7 @@ let NewPostView = ({ writeTo }) => {
|
||||
return data.fileName;
|
||||
})
|
||||
.catch((err) => console.error(err)));
|
||||
|
||||
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
alert("Something went wrong");
|
||||
@@ -76,7 +93,7 @@ let NewPostView = ({ writeTo }) => {
|
||||
|
||||
const handleNewPostButton = async () => {
|
||||
//setPostContent('');
|
||||
API.newPost(postContent + " " + extraContent.join(" ")).then((newPost) => {
|
||||
API.newPost(postContent + " " + extraContent.join(" "), props.route.params.toProfile).then((newPost) => {
|
||||
setPostContent('');
|
||||
setExtraContent([]);
|
||||
navigation.goBack();
|
||||
@@ -93,6 +110,12 @@ let NewPostView = ({ writeTo }) => {
|
||||
{i18n.t("message.post")}
|
||||
</Button>
|
||||
</View>
|
||||
{
|
||||
toProfile._id ?
|
||||
<Text style={{ paddingLeft: 10, paddingBottom: 5 }}>
|
||||
Posting on: {toProfile._id ? toProfile.profile.firstName + " " + toProfile.profile.lastName : ''}
|
||||
</Text> : <></>
|
||||
}
|
||||
<Divider bold={true} />
|
||||
<TextInput
|
||||
value={postContent}
|
||||
|
||||
@@ -104,23 +104,26 @@ let Profile = ({ navigation, route }) => {
|
||||
backgroundColor: "#c44d56",
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
elevation: 10,
|
||||
zIndex: 1,
|
||||
}}>
|
||||
<IconButton icon={showNewPost ? 'remove' : "add"} mode="outlined" color="white" onPress={()=>{
|
||||
setShowNewPost(!showNewPost);
|
||||
//setShowNewPost(!showNewPost);
|
||||
navigation.navigate('NewPost', {toProfile: profile._id})
|
||||
}} />
|
||||
</View>
|
||||
<Button title="Images" icon={tag == 'images' ? 'remove' : "image"} mode="outlined" onPress={()=>{
|
||||
<Button style={{paddingLeft:12, backgroundColor:"#fff"}} title="Images" icon={tag == 'images' ? 'remove' : "image"} mode="outlined" onPress={()=>{
|
||||
if(tag == 'images') return setTag('');
|
||||
setTag('images');
|
||||
}}>Images</Button>
|
||||
<Button title="Media" icon={tag == 'media' ? 'remove' : "subscriptions"} mode="outlined" onPress={()=>{
|
||||
}}>{tag == 'images' ? "Images" : ''}</Button>
|
||||
<Button style={{paddingLeft:12, backgroundColor:"#fff"}} title="Media" icon={tag == 'media' ? 'remove' : "subscriptions"} mode="outlined" onPress={()=>{
|
||||
if(tag == 'media') return setTag('');
|
||||
setTag('media');
|
||||
}}>Media</Button>
|
||||
<Button title="Embedded" icon={tag == 'embedded' ? 'remove' : "folder"} mode="outlined" onPress={()=>{
|
||||
}}>{tag == 'media' ? "Media" : ''}</Button>
|
||||
<Button style={{paddingLeft:12, backgroundColor:"#fff"}} title="Embedded" icon={tag == 'embedded' ? 'remove' : "folder"} mode="outlined" onPress={()=>{
|
||||
if(tag == 'embedded') return setTag('');
|
||||
setTag('embedded');
|
||||
}}>Files</Button>
|
||||
}}>{tag == 'embedded' ? "Files" : ''}</Button>
|
||||
</View>
|
||||
{ showNewPost ?
|
||||
<NewPost newPostCB={(newPost) => setPosts([newPost, ...Posts])} />
|
||||
|
||||
Reference in New Issue
Block a user