From 4fc58aedd79bcc90c20d1914986edbc2ddde3821 Mon Sep 17 00:00:00 2001 From: KeviNmp4 Date: Tue, 14 May 2024 22:47:13 +0200 Subject: [PATCH 01/10] Added: folder with routes to review and add review page, added package RangeSlider; in _layout.js added add review as invisible --- api/src/public/api.json | 2 +- frontend/app/(app)/(tabs)/_layout.js | 6 +- frontend/app/(app)/(tabs)/review.js | 10 - .../app/(app)/(tabs)/review/.index.js.swp | Bin 0 -> 12288 bytes frontend/app/(app)/(tabs)/review/add.js | 233 ++++++++++++++++++ frontend/app/(app)/(tabs)/review/index.js | 74 ++++++ frontend/package-lock.json | 205 +++++++++++++++ frontend/package.json | 1 + 8 files changed, 519 insertions(+), 12 deletions(-) delete mode 100644 frontend/app/(app)/(tabs)/review.js create mode 100644 frontend/app/(app)/(tabs)/review/.index.js.swp create mode 100644 frontend/app/(app)/(tabs)/review/add.js create mode 100644 frontend/app/(app)/(tabs)/review/index.js diff --git a/api/src/public/api.json b/api/src/public/api.json index e5ab6ef..97de5a0 100644 --- a/api/src/public/api.json +++ b/api/src/public/api.json @@ -1 +1 @@ -{"version":"2.0.0","endpoints":{"user":{"signup":{"name":"user","operation":"signup","route":"/api/v1/auth/signup","method":"POST","description":"user signup api","body":{"username":"testuser","email":"text@example.com","password":"Test1234"},"response":"status object"},"signin":{"name":"user","operation":"signin","route":"/api/v1/auth/signin","method":"POST","description":"user signin api","body":{"email":"text@example.com","password":"Test1234"},"response":"status object"},"logout":{"name":"user","operation":"logout","route":"/api/v1/auth/logout","method":"POST","description":"user logout api","body":{},"response":"status object"},"status":{"name":"user","operation":"status","route":"/api/v1/auth/status","method":"GET","description":"user login status api","response":"status code | user object"}},"beer":{"add":{"name":"beer","operation":"add","route":"/api/v1/beer/add","method":"POST","description":"beer add api","body":{"brand":"Pilsner Urqell","name":"Kozel","degree":11,"packaging":"can","photos":"optional field | max 4 images | formData"},"response":"status object | beer object"},"get":{"name":"beer","operation":"get","route":"/api/v1/beer/get","method":"GET","description":"beer get api","response":"status object | array of beer objects"},"del":{"name":"beer","operation":"del","route":"/api/v1/beer/del","method":"POST","description":"beer del api","body":{"_id":"6352b303b71cb62222f39895"},"response":"status object"},"edit":{"name":"beer","operation":"edit","route":"/api/v1/beer/edit","method":"POST","description":"beer edit api","body":{"_id":"6355b95dc03fad77bc380146","brand":"Pilsner Urqell","name":"Radegast","degree":12,"packaging":"bottle","imgs":[],"photos":"optional field | max 4 images | formData"},"response":"status object | beer data"}},"docs":{"get_all":{"name":"docs","operation":"get_all","route":"/api/v1","method":"GET","description":"Get docs json","response":"docs json"}}}} \ No newline at end of file +{"version":"2.0.0","endpoints":{"user":{"signup":{"name":"user","operation":"signup","route":"/api/v1/auth/signup","method":"POST","description":"user signup api","body":{"username":"testuser","email":"text@example.com","password":"Test1234"},"response":"status object"},"signin":{"name":"user","operation":"signin","route":"/api/v1/auth/signin","method":"POST","description":"user signin api","body":{"email":"text@example.com","password":"Test1234"},"response":"status object"},"logout":{"name":"user","operation":"logout","route":"/api/v1/auth/logout","method":"POST","description":"user logout api","body":{},"response":"status object"},"status":{"name":"user","operation":"status","route":"/api/v1/auth/status","method":"GET","description":"user login status api","response":"status code | user object"}},"beer":{"add":{"name":"beer","operation":"add","route":"/api/v1/beer/add","method":"POST","description":"beer add api","body":{"brand":"Pilsner Urqell","name":"Kozel","degree":11,"packaging":"can","photos":"optional field | max 4 images | formData"},"response":"status object | beer object"},"get":{"name":"beer","operation":"get","route":"/api/v1/beer/get","method":"GET","description":"beer get api","response":"status object | array of beer objects"},"del":{"name":"beer","operation":"del","route":"/api/v1/beer/del","method":"POST","description":"beer del api","body":{"_id":"6352b303b71cb62222f39895"},"response":"status object"},"edit":{"name":"beer","operation":"edit","route":"/api/v1/beer/edit","method":"POST","description":"beer edit api","body":{"_id":"6355b95dc03fad77bc380146","brand":"Pilsner Urqell","name":"Radegast","degree":12,"packaging":"bottle","imgs":[],"photos":"optional field | max 4 images | formData"},"response":"status object | beer data"}},"docs":{"get_all":{"name":"docs","operation":"get_all","route":"/api/v1","method":"GET","description":"Get docs json","response":"docs json"}},"review":{"add":{"name":"review","operation":"add","route":"/api/v1/review/add","method":"POST","description":"review add api","body":{"beer_id":"6352b303b71cb62222f39895","foam":3,"bitter_sweetness":2,"taste":5,"packaging":3,"sourness":false,"would_again":true},"response":"status object | review object"},"get":{"name":"review","operation":"get","route":"/api/v1/review/get","method":"GET","description":"review get api","response":"status object | array of review objects"},"del":{"name":"review","operation":"del","route":"/api/v1/review/del","method":"POST","description":"review del api","body":{"_id":"6352b303b71cb62222f39895"},"response":"status object"}}}} \ No newline at end of file diff --git a/frontend/app/(app)/(tabs)/_layout.js b/frontend/app/(app)/(tabs)/_layout.js index be70c82..8b8d7d7 100644 --- a/frontend/app/(app)/(tabs)/_layout.js +++ b/frontend/app/(app)/(tabs)/_layout.js @@ -43,7 +43,7 @@ export default function TabLayout() { }} /> ( @@ -66,6 +66,10 @@ export default function TabLayout() { name="beer/add" options={{ href: null, title: "Add beer" }} /> + ); diff --git a/frontend/app/(app)/(tabs)/review.js b/frontend/app/(app)/(tabs)/review.js deleted file mode 100644 index 0b22c72..0000000 --- a/frontend/app/(app)/(tabs)/review.js +++ /dev/null @@ -1,10 +0,0 @@ -import { View } from "react-native"; -import Text from "@components/Text"; - -export default function Tab() { - return ( - - Tab REVIEW - - ); -} diff --git a/frontend/app/(app)/(tabs)/review/.index.js.swp b/frontend/app/(app)/(tabs)/review/.index.js.swp new file mode 100644 index 0000000000000000000000000000000000000000..b42827bc3c5bef7845e09d43459d4c122cf50626 GIT binary patch literal 12288 zcmeI2&x;&I6vrz$h;3XIh2X(J*(TTnvpu_pfM#bFvzs-p>?Y&>h(cI4wcRzdz1!0@ zsjk_Xu^BxmUh+4H9*sBAix&wJA_yJ?#gl)7*C3*PtGee$)-eEz$#!BunJfOtO8a6tAJI&Dqt0`3RndmLIqez$k&e& z@|%O;@&Etf-~V@>B;;do0Nwznz;odDCkXiod;`7!pMhK8CU_s511@+3{5eI)FW@ft z5_|+Q&;<&lAOe>_6`TQ6;NIhe{0P1W--5f~D{u?k1Y4j6PJw$T2>Ahg3i==h9BhM4 z@FutdE`!tHBsc+neT^KS#TWu0j;!NMze=-&27k5 z0jq#jz$#!BunPQN6&RG}h%+b?$7wOyjFJVRlxUr&?zuCr?rpO$jFRSgI(t?(cZ3YN zTw`I>Nzpem?t3c=)h@cmJ&Ph15}ulp^|h}^aX8NIn{Gq2|2Eg_LPqbP8kEHtnl0k! z=I-6unHdvUUKP3$rRpDDvN&oc%a|C^x&cRtsWfTrby5{I`irLM6fP#m8ZqzXi3B=| zDB;K=BfQrZQc?7!il(X`^OV-;x_(&S2xHB4N|^x1+F-$M_#jGhXUkypSnY%ktFOgO>5V`pbRHBsOVPoS`;xa~ z7I4oURuf}ayJm?TM(0QSZ!i@8*uyDnN>?LrRP#YUxFR75w6AoZpbG55KY zLVCEG*atLVD%ho_Lmw>1Nx8ZRVLYvluP=F$`KHxvY+2T2k)p^M)zl*Katrev(1}YP zV)lr|`ou&@5O+dujtssK2v1-qxtEqU@~+%3T#ei|I3n_{pU&D+1d!F|$$`K0cKynB zeRE-Dd2#zfeR+FxZDlZAi6&Rq%O-dw`})q(eiG0|Cka#}5^5ZpoJttg9}jwM%fvh} zg2UEH`BJ071Lcj@F^}$=PPV@qu0!5nomh=0-e5cMgejwzIry1= zFQ1}3azO_amFq3);_L^?of{kHTW2)>Y9QbyfwXDGZ11sczIh5ilXm&Q*ie51jxf{R f+UUkGPJL9%6JMq>9UhTUI40cbgsJF& { + const permissionResult = + await ImagePicker.requestMediaLibraryPermissionsAsync(); + + if (permissionResult.granted === false) { + alert("You've refused to allow this appp to access your photos!"); + return; + } + + // No permissions request is necessary for launching the image library + const result = await ImagePicker.launchImageLibraryAsync({ + mediaTypes: ImagePicker.MediaTypeOptions.Images, + allowsEditing: true, + aspect: [3, 4], + // quality: 1, + }); + + // Explore the result + console.log(result); + + if (!result.canceled) { + setImage(result.assets[0].uri); + } + }; + + const openCamera = async () => { + // Ask the user for the permission to access the camera + const permissionResult = await ImagePicker.requestCameraPermissionsAsync(); + + if (permissionResult.granted === false) { + alert("You've refused to allow this app to access your camera!"); + return; + } + + const result = await ImagePicker.launchCameraAsync(); + + // Explore the result + console.log(result); + + if (!result.canceled) { + setImage(result.assets[0].uri); + } + }; + + function validateDegreeInput(text) { + let newText = ""; + let numbers = "0123456789."; + + for (var i = 0; i < text.length; i++) { + if (numbers.indexOf(text[i]) > -1) { + newText = newText + text[i]; + setBDegree(newText); + } else { + // your call back function + alert("Please enter numbers only."); + setBDegree(""); + } + } + } + + async function addBeer() { + // TODO: after the request - redirect to /beer/{new_beer_id}?; plus some modal about successful state + const req = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/beer/add`, { + method: "POST", + credentials: "include", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + brand: b_brand, + name: b_name, + degree: b_degree, + packaging: b_packaging, + photos: null, + }), + }); + const res = await req.json(); + + if (res.code == 201 && res.data._id) { + window.location.href = `/beer/${res.data._id}`; + } else { + alert( + "Beer was not added successfully. Please check your data and try again.", + ); + } + } + + return ( + + + + Spill your thoughts about the beer you just sipped! + + setBName(text)} + placeholderTextColor="#aaaaaa" + /> + setBBrand(text)} + placeholderTextColor="#aaaaaa" + /> + validateDegreeInput(text)} + placeholderTextColor="#aaaaaa" + keyboardType="numeric" + maxLength={3} + /> + + + {/* +