Multiple photos on new post

This commit is contained in:
Adolfo Reyna
2022-12-22 23:33:37 -05:00
parent 1c0dbbbe84
commit 4c95095882
2 changed files with 50 additions and 45 deletions

2
App.js
View File

@@ -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;
} }

View File

@@ -20,21 +20,25 @@ 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;
let allUploads = [];
results.assets.forEach(photo => {
const uri = const uri =
Platform.OS === "android" Platform.OS === "android"
? photo.uri ? photo.uri
@@ -50,23 +54,24 @@ let NewPostView = ({writeTo})=>{
type, type,
}); });
try { try {
let uploadedFile = await fetch("https://social.emmint.com/upload.php", { allUploads.push(fetch("https://social.emmint.com/upload.php", {
method: "POST", method: "POST",
body: formData, body: formData,
headers: { "Content-Type": "multipart/form-data" } headers: { "Content-Type": "multipart/form-data" }
}) })
.then((res) => res.json()) .then((res) => res.json())
.then((data) => { .then((data) => {
console.log(data);
return data.fileName; return data.fileName;
}) })
.catch((err) => console.error(err)); .catch((err) => console.error(err)));
return uploadedFile;
} catch (err) { } catch (err) {
console.log(err); console.log(err);
alert("Something went wrong"); alert("Something went wrong");
} }
});
uploadedFiles = Promise.all(allUploads);
return uploadedFiles;
}; };
const handleNewPostButton = async () => { const handleNewPostButton = async () => {