diff --git a/Views/NewPost.js b/Views/NewPost.js index 58c133f..3e7c1f4 100644 --- a/Views/NewPost.js +++ b/Views/NewPost.js @@ -42,10 +42,10 @@ let NewPostView = (props) => { mediaTypes: ImagePicker.MediaTypeOptions.Images, //allowsEditing: true, //aspect: [4, 3], - quality: 0.7, + quality: 0.2, allowsMultipleSelection: true, }); - if (!result.cancelled) { + if (!result.canceled) { setPhoto(result); let newPhotoURLs = await handleUploadPhoto(result); let newExtraContent = [extraContent] diff --git a/Views/ProfileSettings.js b/Views/ProfileSettings.js index 5038af1..92a01ee 100644 --- a/Views/ProfileSettings.js +++ b/Views/ProfileSettings.js @@ -29,27 +29,31 @@ let ProfileSettings = ()=>{ mediaTypes: ImagePicker.MediaTypeOptions.Images, allowsEditing: true, aspect: [4, 3], - quality: 0.7, + quality: 0.2, //allowsMultipleSelection: true, }); - if (!result.cancelled) { + if (!result.canceled) { setPhoto(result); - let newPhotoURL = await handleUploadPhoto(result); + let newPhotoURL = await handleUploadPhoto(result.assets[0]); if(newPhotoURL !== ""){ setphotoUrl(newPhotoURL); GlobalState.me.profile.photo = newPhotoURL; - setUpdateKey(updateKey+1); + viewer.profile.photo = newPhotoURL; + setUpdateKey(updateKey + 1); } setPhoto(null); } }; const handleUploadPhoto = async (photo) => { + console.log(photo) if (!photo) return; const uri = Platform.OS === "android" ? photo.uri : photo.uri.replace("file://", ""); + + console.log(uri); const filename = photo.uri.split("/").pop(); const match = /\.(\w+)$/.exec(filename); const ext = match?.[1]; @@ -69,9 +73,10 @@ let ProfileSettings = ()=>{ }) .then((res) => res.json()) .then((data) => { + console.log(data); return data.fileName; - }) - .catch((err) => console.error(err)); + }); + console.log(uploadedFile); } catch (err) { console.log(err); alert("Something went wrong uploading the photo."); diff --git a/app.json b/app.json index dd29fbd..daa1e8c 100644 --- a/app.json +++ b/app.json @@ -30,7 +30,7 @@ }, "package": "com.emi.social", "googleServicesFile": "./google-services.json", - "versionCode": 4 + "versionCode": 5 }, "web": { "favicon": "./assets/favicon.png" diff --git a/components/NewPost.js b/components/NewPost.js index 8ee102e..83120d7 100644 --- a/components/NewPost.js +++ b/components/NewPost.js @@ -21,53 +21,58 @@ let NewPost = ({ profileid, newPostCB }) => { mediaTypes: ImagePicker.MediaTypeOptions.Images, //allowsEditing: true, //aspect: [4, 3], - //quality: 1, + quality: 0.2, allowsMultipleSelection: true, }); - if (!result.cancelled) { + if (!result.canceled) { setPhoto(result); - let newPhotoURL = await handleUploadPhoto(result); - let newExtraContent = ["@image:" + newPhotoURL].concat(extraContent); + let newPhotoURLs = await handleUploadPhoto(result); + let newExtraContent = [extraContent] + newPhotoURLs.forEach((newPhotoURL) => { + newExtraContent = ["@image:" + newPhotoURL].concat(newExtraContent); + }); setExtraContent(newExtraContent); - console.log(newExtraContent.join(" ")); setPhoto(null); } }; - const handleUploadPhoto = async (photo) => { - if (!photo) return; - const uri = - Platform.OS === "android" - ? photo.uri - : photo.uri.replace("file://", ""); - const filename = photo.uri.split("/").pop(); - const match = /\.(\w+)$/.exec(filename); - const ext = match?.[1]; - const type = match ? `image/${match[1]}` : `image`; - const formData = new FormData(); - formData.append("banner", { - uri, - name: `image.${ext}`, - type, - }); - try { - let uploadedFile = await fetch("https://social.emmint.com/upload.php", { - method: "POST", - body: formData, - headers: { "Content-Type": "multipart/form-data" } - }) - .then((res) => res.json()) - .then((data) => { - console.log(data); - return data.fileName; + const handleUploadPhoto = async (results) => { + if (!results) return; + let allUploads = []; + results.assets.forEach(photo => { + const uri = + Platform.OS === "android" + ? photo.uri + : photo.uri.replace("file://", ""); + const filename = photo.uri.split("/").pop(); + const match = /\.(\w+)$/.exec(filename); + const ext = match?.[1]; + const type = match ? `image/${match[1]}` : `image`; + const formData = new FormData(); + formData.append("banner", { + uri, + name: `image.${ext}`, + type, + }); + try { + allUploads.push(fetch("https://social.emmint.com/upload.php", { + method: "POST", + body: formData, + headers: { "Content-Type": "multipart/form-data" } }) - .catch((err) => console.error(err)); - return uploadedFile; - } catch (err) { - console.log(err); - alert("Something went wrong"); - } + .then((res) => res.json()) + .then((data) => { + return data.fileName; + }) + .catch((err) => console.error(err))); + } catch (err) { + console.log(err); + alert("Something went wrong uploading the photo."); + } + }); + uploadedFiles = Promise.all(allUploads); + return uploadedFiles; }; const handleNewPostButton = async () => { diff --git a/package-lock.json b/package-lock.json index f7745af..b5b0e3e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,7 +30,6 @@ "react-dom": "18.1.0", "react-native": "0.70.8", "react-native-autoheight-webview": "^1.6.1", - "react-native-circular-slider": "^1.0.1", "react-native-hyperlink": "0.0.19", "react-native-paper": "^4.11.2", "react-native-safe-area-context": "4.4.1", @@ -5034,11 +5033,6 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, - "node_modules/boolbase": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", - "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==" - }, "node_modules/bplist-creator": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/bplist-creator/-/bplist-creator-0.1.0.tgz", @@ -5834,65 +5828,6 @@ "hyphenate-style-name": "^1.0.3" } }, - "node_modules/css-select": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", - "integrity": "sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==", - "dependencies": { - "boolbase": "^1.0.0", - "css-what": "^6.1.0", - "domhandler": "^5.0.2", - "domutils": "^3.0.1", - "nth-check": "^2.0.1" - }, - "funding": { - "url": "https://github.com/sponsors/fb55" - } - }, - "node_modules/css-tree": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.1.3.tgz", - "integrity": "sha512-tRpdppF7TRazZrjJ6v3stzv93qxRcSsFmW6cX0Zm2NVKpxE1WV1HblnghVv9TreireHkqI/VDEsfolRF1p6y7Q==", - "dependencies": { - "mdn-data": "2.0.14", - "source-map": "^0.6.1" - }, - "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/css-tree/node_modules/source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/css-what": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz", - "integrity": "sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==", - "engines": { - "node": ">= 6" - }, - "funding": { - "url": "https://github.com/sponsors/fb55" - } - }, - "node_modules/d3-color": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/d3-color/-/d3-color-1.4.1.tgz", - "integrity": "sha512-p2sTHSLCJI2QKunbGb7ocOh7DgTAn8IrLx21QRc/BSnodXM4sv6aLQlnfpvehFMLZEfBc6g9pH9SWQccFYfJ9Q==" - }, - "node_modules/d3-interpolate": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/d3-interpolate/-/d3-interpolate-1.4.0.tgz", - "integrity": "sha512-V9znK0zc3jOPV4VD2zZn0sDhZU3WAE2bmlxdIwwQPPzPjvyLkd8B3JUVdS1IDUFDkWZ72c9qnv1GK2ZagTZ8EA==", - "dependencies": { - "d3-color": "1" - } - }, "node_modules/dag-map": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/dag-map/-/dag-map-1.0.2.tgz", @@ -6157,57 +6092,6 @@ "node": ">=8" } }, - "node_modules/dom-serializer": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", - "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", - "dependencies": { - "domelementtype": "^2.3.0", - "domhandler": "^5.0.2", - "entities": "^4.2.0" - }, - "funding": { - "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" - } - }, - "node_modules/domelementtype": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", - "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/fb55" - } - ] - }, - "node_modules/domhandler": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", - "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", - "dependencies": { - "domelementtype": "^2.3.0" - }, - "engines": { - "node": ">= 4" - }, - "funding": { - "url": "https://github.com/fb55/domhandler?sponsor=1" - } - }, - "node_modules/domutils": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.1.0.tgz", - "integrity": "sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==", - "dependencies": { - "dom-serializer": "^2.0.0", - "domelementtype": "^2.3.0", - "domhandler": "^5.0.3" - }, - "funding": { - "url": "https://github.com/fb55/domutils?sponsor=1" - } - }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -6239,17 +6123,6 @@ "once": "^1.4.0" } }, - "node_modules/entities": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", - "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", - "engines": { - "node": ">=0.12" - }, - "funding": { - "url": "https://github.com/fb55/entities?sponsor=1" - } - }, "node_modules/env-editor": { "version": "0.4.2", "resolved": "https://registry.npmjs.org/env-editor/-/env-editor-0.4.2.tgz", @@ -8977,11 +8850,6 @@ "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", "integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==" }, - "node_modules/lodash.range": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/lodash.range/-/lodash.range-3.2.0.tgz", - "integrity": "sha512-Fgkb7SinmuzqgIhNhAElo0BL/R1rHCnhwSZf78omqSwvWqD0kD2ssOAutQonDKH/ldS8BxA72ORYI09qAY9CYg==" - }, "node_modules/lodash.throttle": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz", @@ -9111,11 +8979,6 @@ "resolved": "https://registry.npmjs.org/md5hex/-/md5hex-1.0.0.tgz", "integrity": "sha512-c2YOUbp33+6thdCUi34xIyOU/a7bvGKj/3DB1iaPMTuPHf/Q2d5s4sn1FaCOO43XkXggnb08y5W2PU8UNYNLKQ==" }, - "node_modules/mdn-data": { - "version": "2.0.14", - "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.14.tgz", - "integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==" - }, "node_modules/mdurl": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", @@ -10086,17 +9949,6 @@ "node": ">=4" } }, - "node_modules/nth-check": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", - "integrity": "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==", - "dependencies": { - "boolbase": "^1.0.0" - }, - "funding": { - "url": "https://github.com/fb55/nth-check?sponsor=1" - } - }, "node_modules/nullthrows": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/nullthrows/-/nullthrows-1.1.1.tgz", @@ -11004,16 +10856,6 @@ "react-native-webview": ">= 10.9.0" } }, - "node_modules/react-native-circular-slider": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/react-native-circular-slider/-/react-native-circular-slider-1.0.1.tgz", - "integrity": "sha512-wBYjkiRXb7prT1hdbJzMa7h36xxfkKcO+qGh780OQNSNgwFPExwE3S1/u8qBivhIt/yOsirqA/FdykoEHVJ+hg==", - "dependencies": { - "d3-interpolate": "^1.1.2", - "lodash.range": "^3.2.0", - "react-native-svg": ">=4.3.3" - } - }, "node_modules/react-native-codegen": { "version": "0.70.6", "resolved": "https://registry.npmjs.org/react-native-codegen/-/react-native-codegen-0.70.6.tgz", @@ -11093,19 +10935,6 @@ "react-native": "*" } }, - "node_modules/react-native-svg": { - "version": "13.9.0", - "resolved": "https://registry.npmjs.org/react-native-svg/-/react-native-svg-13.9.0.tgz", - "integrity": "sha512-Ey18POH0dA0ob/QiwCBVrxIiwflhYuw0P0hBlOHeY4J5cdbs8ngdKHeWC/Kt9+ryP6fNoEQ1PUgPYw2Bs/rp5Q==", - "dependencies": { - "css-select": "^5.1.0", - "css-tree": "^1.1.3" - }, - "peerDependencies": { - "react": "*", - "react-native": "*" - } - }, "node_modules/react-native-vector-icons": { "version": "9.2.0", "resolved": "https://registry.npmjs.org/react-native-vector-icons/-/react-native-vector-icons-9.2.0.tgz",