Multiple photos on new post
This commit is contained in:
2
App.js
2
App.js
@@ -71,7 +71,7 @@ async function registerForPushNotificationsAsync() {
|
|||||||
}
|
}
|
||||||
token = (await Notifications.getExpoPushTokenAsync({ projectId: "c2bb4d4e-4d4d-4f34-a873-7cad78c6023c", })).data;
|
token = (await Notifications.getExpoPushTokenAsync({ projectId: "c2bb4d4e-4d4d-4f34-a873-7cad78c6023c", })).data;
|
||||||
} else {
|
} else {
|
||||||
alert('Must use physical device for Push Notifications');
|
//alert('Must use physical device for Push Notifications');
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import i18n from "../i18nMessages";
|
|||||||
import Media from '../components/Media';
|
import Media from '../components/Media';
|
||||||
|
|
||||||
|
|
||||||
let NewPostView = ({writeTo})=>{
|
let NewPostView = ({ writeTo }) => {
|
||||||
let [postContent, setPostContent] = useState('');
|
let [postContent, setPostContent] = useState('');
|
||||||
let [extraContent, setExtraContent] = useState([]);
|
let [extraContent, setExtraContent] = useState([]);
|
||||||
const [photo, setPhoto] = React.useState(null);
|
const [photo, setPhoto] = React.useState(null);
|
||||||
@@ -20,53 +20,58 @@ let NewPostView = ({writeTo})=>{
|
|||||||
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
||||||
//allowsEditing: true,
|
//allowsEditing: true,
|
||||||
//aspect: [4, 3],
|
//aspect: [4, 3],
|
||||||
//quality: 1,
|
quality: 0.7,
|
||||||
allowsMultipleSelection: true,
|
allowsMultipleSelection: true,
|
||||||
});
|
});
|
||||||
if (!result.cancelled) {
|
if (!result.cancelled) {
|
||||||
setPhoto(result);
|
setPhoto(result);
|
||||||
let newPhotoURL = await handleUploadPhoto(result);
|
let newPhotoURLs = await handleUploadPhoto(result);
|
||||||
let newExtraContent = ["@image:" + newPhotoURL].concat(extraContent);
|
let newExtraContent = [extraContent]
|
||||||
|
newPhotoURLs.forEach((newPhotoURL)=>{
|
||||||
|
newExtraContent = ["@image:" + newPhotoURL].concat(newExtraContent);
|
||||||
|
});
|
||||||
setExtraContent(newExtraContent);
|
setExtraContent(newExtraContent);
|
||||||
console.log(newExtraContent.join(" "));
|
|
||||||
setPhoto(null);
|
setPhoto(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUploadPhoto = async (photo) => {
|
const handleUploadPhoto = async (results) => {
|
||||||
if (!photo) return;
|
if (!results) return;
|
||||||
const uri =
|
let allUploads = [];
|
||||||
Platform.OS === "android"
|
results.assets.forEach(photo => {
|
||||||
? photo.uri
|
const uri =
|
||||||
: photo.uri.replace("file://", "");
|
Platform.OS === "android"
|
||||||
const filename = photo.uri.split("/").pop();
|
? photo.uri
|
||||||
const match = /\.(\w+)$/.exec(filename);
|
: photo.uri.replace("file://", "");
|
||||||
const ext = match?.[1];
|
const filename = photo.uri.split("/").pop();
|
||||||
const type = match ? `image/${match[1]}` : `image`;
|
const match = /\.(\w+)$/.exec(filename);
|
||||||
const formData = new FormData();
|
const ext = match?.[1];
|
||||||
formData.append("banner", {
|
const type = match ? `image/${match[1]}` : `image`;
|
||||||
uri,
|
const formData = new FormData();
|
||||||
name: `image.${ext}`,
|
formData.append("banner", {
|
||||||
type,
|
uri,
|
||||||
});
|
name: `image.${ext}`,
|
||||||
try {
|
type,
|
||||||
let uploadedFile = await fetch("https://social.emmint.com/upload.php", {
|
});
|
||||||
method: "POST",
|
try {
|
||||||
body: formData,
|
allUploads.push(fetch("https://social.emmint.com/upload.php", {
|
||||||
headers: { "Content-Type": "multipart/form-data" }
|
method: "POST",
|
||||||
})
|
body: formData,
|
||||||
.then((res) => res.json())
|
headers: { "Content-Type": "multipart/form-data" }
|
||||||
.then((data) => {
|
|
||||||
console.log(data);
|
|
||||||
return data.fileName;
|
|
||||||
})
|
})
|
||||||
.catch((err) => console.error(err));
|
.then((res) => res.json())
|
||||||
return uploadedFile;
|
.then((data) => {
|
||||||
} catch (err) {
|
return data.fileName;
|
||||||
console.log(err);
|
})
|
||||||
alert("Something went wrong");
|
.catch((err) => console.error(err)));
|
||||||
}
|
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
alert("Something went wrong");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
uploadedFiles = Promise.all(allUploads);
|
||||||
|
return uploadedFiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleNewPostButton = async () => {
|
const handleNewPostButton = async () => {
|
||||||
@@ -81,14 +86,14 @@ let NewPostView = ({writeTo})=>{
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView>
|
||||||
<View style={{padding: 10}}>
|
<View style={{ padding: 10 }}>
|
||||||
<View style={{flexDirection:"row", marginBottom:10, justifyContent:"space-around"}}>
|
<View style={{ flexDirection: "row", marginBottom: 10, justifyContent: "space-around" }}>
|
||||||
<Text style={{fontSize: 25}}>{i18n.t("message.statusUpdate")}:</Text>
|
<Text style={{ fontSize: 25 }}>{i18n.t("message.statusUpdate")}:</Text>
|
||||||
<Button icon="send" mode="outlined" onPress={handleNewPostButton}>
|
<Button icon="send" mode="outlined" onPress={handleNewPostButton}>
|
||||||
{i18n.t("message.post")}
|
{i18n.t("message.post")}
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
<Divider bold={true}/>
|
<Divider bold={true} />
|
||||||
<TextInput
|
<TextInput
|
||||||
value={postContent}
|
value={postContent}
|
||||||
onChangeText={setPostContent}
|
onChangeText={setPostContent}
|
||||||
@@ -102,8 +107,8 @@ let NewPostView = ({writeTo})=>{
|
|||||||
}}
|
}}
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
/>
|
/>
|
||||||
<Divider bold={true} />
|
<Divider bold={true} />
|
||||||
<View style={{flexDirection:"row", marginTop:10, justifyContent:"space-around"}}>
|
<View style={{ flexDirection: "row", marginTop: 10, justifyContent: "space-around" }}>
|
||||||
<Button icon="add-a-photo" mode="outlined" onPress={pickImage}>
|
<Button icon="add-a-photo" mode="outlined" onPress={pickImage}>
|
||||||
Add Photos
|
Add Photos
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user