diff --git a/application/mobile/.env.example b/application/mobile/.env.example index ca9963a0..452d05ff 100644 --- a/application/mobile/.env.example +++ b/application/mobile/.env.example @@ -1 +1 @@ -VITE_API_URL=http://localhost:8080 \ No newline at end of file +VITE_API_URL="https://fanatic-backend-bjbpof6jaq-oa.a.run.app" \ No newline at end of file diff --git a/application/mobile/App.js b/application/mobile/App.js index dd236d0d..f1bede5f 100644 --- a/application/mobile/App.js +++ b/application/mobile/App.js @@ -3,10 +3,14 @@ import { createNativeStackNavigator } from "@react-navigation/native-stack"; import LoginScreen from "./App/Screens/LoginScreen"; import RegisterScreen from "./App/Screens/RegisterScreen"; import FeedScreen from "./App/Screens/FeedScreen"; -import ProfileScreen from "./App/Screens/ProfileScreen"; +import SettingsScreen from "./App/Screens/SettingsScreen"; import PostCreationScreen from "./App/Screens/PostCreationScreen"; import SearchResultScreen from "./App/Screens/SearchResultScreen"; - +import PostScreen from "./App/Screens/PostScreen"; +import ChangePassword from "./App/Screens/ChangePassword"; +import DeleteAccount from "./App/Screens/DeleteAccount"; +import ProfileScreen from "./App/Screens/ProfileScreen"; +import CommunityScreen from "./App/Screens/CommunityScreen"; const Stack = createNativeStackNavigator(); export default function App() { @@ -29,10 +33,15 @@ export default function App() { options={{ headerShown: false }} /> + + + + + ); diff --git a/application/mobile/App/Screens/ChangePassword.js b/application/mobile/App/Screens/ChangePassword.js new file mode 100644 index 00000000..b7d21bb2 --- /dev/null +++ b/application/mobile/App/Screens/ChangePassword.js @@ -0,0 +1,121 @@ +import React, { useState, useRef } from "react"; +import { + Alert, + Text, + View, + StyleSheet, + TextInput, + StatusBar, + Image, + FlatList, + Dimensions, + TouchableOpacity, + Modal, +} from "react-native"; + + +export default function ChangePassword({navigation}){ + const [oldPass, setOld] = useState(""); + const [newPass, setNew] = useState(""); + const [newPass_, setNew_] = useState(""); + const backButton = () => { + navigation.goBack(); + } + + const changePass = () => { + if(newPass.length < 8){ + alert("Password length is too short") + return; + } + if(newPass != newPass_){ + alert("Passwords Are Not Matching") + return; + } + navigation.goBack(); + } + + return( + + + + + + + appFanatic. + + + + Your Old Password: + {setOld(val)}}/> + + + Your New Password: + {setNew(val)}}/> + + + + Your New Password: + (Enter Again) + + + {setNew_(val)}}/> + + + Change Password + + + ) +} + +const styles = StyleSheet.create({ + backgroundContainer: { + flex: 1, + backgroundColor: "white", + paddingTop: StatusBar.currentHeight, + justifyContent: "flex-start", + minHeight: Math.round(Dimensions.get("window").height), + }, + headerContainer: { + marginTop: "5%", + flexDirection: "row", + justifyContent: "center", + alignItems: "center", + }, + backIcon: { + width: 40, + height: 50, + resizeMode:"stretch", + }, + header: { + color: "blue", + fontSize: 25, + fontWeight: "600", + }, + textInContainer: { + height: "50%", + width: "80%", + marginTop: "2%", + marginLeft: "5%", + marginBottom: "5%", + borderWidth: 2, + padding: 5, + borderRadius: 5, + borderColor: "#0001", + }, + button: { + backgroundColor: 'blue', + padding: 10, + borderRadius: 5, + alignItems: 'center', + marginBottom: "5%", + }, + inputView: { + flexDirection: "row", + marginBottom: "5%", + marginLeft: "5%", + width: "60%", + } +}) \ No newline at end of file diff --git a/application/mobile/App/Screens/CommunityScreen.js b/application/mobile/App/Screens/CommunityScreen.js new file mode 100644 index 00000000..952bb5c2 --- /dev/null +++ b/application/mobile/App/Screens/CommunityScreen.js @@ -0,0 +1,280 @@ +import React, { useState, useRef } from "react"; +import { + View, + FlatList, + StyleSheet, + TouchableOpacity, + StatusBar, + Dimensions, +} from "react-native"; +import CommunityHeader from "../components/CommunityHeader"; +import Post from "../components/Post"; +import { VITE_API_URL } from "@env"; +import axios from "axios"; + +export default function Community({ navigation, route }) { + const [communityName, setCommunityName] = useState(""); + const [communityYear, setCommunityYear] = useState(""); + const [communityImage, setCommunityImage] = useState(""); + + const getPosts = () => { + return [ + { + id: 1, + profilePic: "pp1", + username: "Can Öztemiz", + community: "Fenerbahçe", + communityLink: "fenerbahcelink", + text: "Sizce Fenerbahçe'nin Trabzonspor karşısındaki hücum hattı nasıl olmalı?", + imageUrl: "image1", + likes: 278, + dislikes: 12, + commentsCount: 124, + }, + { + id: 2, + profilePic: "pp2", + username: "GalaGala123", + community: "Galatasaray", + communityLink: "galatasaraylink", + text: "Icardi'nin bugünkü performansı çok iyi değil miydi?", + imageUrl: "image2", + likes: 543, + dislikes: 23, + commentsCount: 87, + }, + { + id: 3, + profilePic: "image1", + username: "jane_doe", + community: "Fenerbahçe", + communityLink: "fenerbahcelink", + text: "This is the second sample post", + imageUrl: "https://example.com/sampleimage2.jpg", + likes: 15, + dislikes: 3, + commentsCount: 8, + }, + { + id: 4, + profilePic: "image2", + username: "jane_doe", + community: "Fenerbahçe", + communityLink: "fenerbahcelink", + text: "This is the second sample post", + imageUrl: "https://example.com/sampleimage2.jpg", + likes: 15, + dislikes: 3, + commentsCount: 8, + }, + { + id: 5, + profilePic: "pp1", + username: "jane_doe", + community: "Fenerbahçe", + communityLink: "fenerbahcelink", + text: "This is the second sample post", + imageUrl: "https://example.com/sampleimage2.jpg", + likes: 15, + dislikes: 3, + commentsCount: 8, + }, + ]; + }; + + const Communities = { + TRABZONSPOR: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/bs/c/cb/Trabzonspor_%28grb%29.png", + name: "TRABZONSPOR COMMUNITY", + year: "1907", + }, + ADANADEMIRSPOR: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/thumb/5/5f/Adanademirspor.png/400px-Adanademirspor.png", + name: "ADANA DEMİRSPOR COMMUNITY", + year: "1907", + }, + ALANYASPOR: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/thumb/2/29/Alanyaspor_logo.png/400px-Alanyaspor_logo.png", + name: "ALANYASPOR COMMUNITY", + year: "1907", + }, + ANTALYASPOR: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/thumb/b/b9/Antalyaspor_logo.png/400px-Antalyaspor_logo.png", + name: "ANTALYASPOR COMMUNITY", + year: "1907", + }, + BESIKTAS: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Logo_of_Be%C5%9Fikta%C5%9F_JK.svg/1200px-Logo_of_Be%C5%9Fikta%C5%9F_JK.svg.png", + name: "BEŞİKTAŞ COMMUNITY", + year: "1903", + }, + RIZESPOR: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/thumb/f/f6/%C3%87aykur_Rizespor_Logo.png/400px-%C3%87aykur_Rizespor_Logo.png", + name: "ÇAYKUR RİZESPOR COMMUNITY", + year: "1907", + }, + KARAGUMRUK: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/thumb/9/90/Fatihkaragumruk.png/400px-Fatihkaragumruk.png", + name: "FATİH KARAGÜMRÜK COMMUNITY", + year: "1907", + }, + FENERBAHCE: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/8/86/Fenerbah%C3%A7e_SK.png", + name: "FENERBAHÇE COMMUNITY", + year: "1907", + }, + GALATASARAY: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Galatasaray_Sports_Club_Logo.svg/1200px-Galatasaray_Sports_Club_Logo.svg.png", + name: "GALATASARAY COMMUNITY", + year: "1905", + }, + GAZIANTEP: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/GFK-Logo.png/400px-GFK-Logo.png", + name: "GAZIANTEP FK COMMUNITY", + year: "1905", + }, + HATAYSPOR: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/thumb/0/08/Hatayspor.png/400px-Hatayspor.png", + name: "HATAYSPOR COMMUNITY", + year: "1905", + }, + BASAKSEHIR: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/c/cd/%C4%B0stanbul_Ba%C5%9Fak%C5%9Fehir_FK.png", + name: "BAŞAKŞEHİR COMMUNITY", + year: "1905", + }, + ISTANBULSPOR: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/thumb/e/ed/IstanbulsporAS.png/400px-IstanbulsporAS.png", + name: "İSTANBULSPOR COMMUNITY", + year: "1905", + }, + KASIMPASA: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/6/68/Kasimpasa_2012.png", + name: "KASIMPAŞA COMMUNITY", + year: "1905", + }, + KAYSERISPOR: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/thumb/c/c2/Kayserispor_logosu.png/400px-Kayserispor_logosu.png", + name: "KAYSERİSPOR COMMUNITY", + year: "1905", + }, + KONYASPOR: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/4/41/Konyaspor_1922.png", + name: "KONYASPOR COMMUNITY", + year: "1905", + }, + ANKARAGUCU: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/thumb/9/97/MKE_Ankarag%C3%BCc%C3%BC_logo.png/400px-MKE_Ankarag%C3%BCc%C3%BC_logo.png", + name: "MKE ANKARAGÜCÜ COMMUNITY", + year: "1905", + }, + PENDIKSPOR: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/thumb/2/2e/Pendikspor.png/400px-Pendikspor.png", + name: "PENDİKSPOR COMMUNITY", + year: "1905", + }, + SAMSUNSPOR: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/thumb/d/dc/Samsunspor_logo_2.png/400px-Samsunspor_logo_2.png", + name: "SAMSUNSPOR COMMUNITY", + year: "1905", + }, + SIVASSPOR: { + imageUrl: + "https://upload.wikimedia.org/wikipedia/tr/thumb/8/80/Sivasspor.png/400px-Sivasspor.png", + name: "SİVASSPOR COMMUNITY", + year: "1905", + }, + }; + + axios + .get(`${VITE_API_URL}/api/v1/users?email=` + route.params.email, { + headers: { + Authorization: `Bearer ${route.params.authToken}`, + }, + }) + .then((response) => { + setCommunityName(Communities[response.data.community.name].name); + setCommunityYear(Communities[response.data.community.name].year); + setCommunityImage(Communities[response.data.community.name].imageUrl); + + console.log(communityName); + console.log(communityYear); + console.log(communityImage); + }) + .catch((error) => { + console.log(error); + }); + + const goToProfile = (attrs) => { + navigation.navigate("ProfileScreen", { profile: attrs }); + }; + + return ( + + + + + ( + { + navigation.navigate("PostScreen", { item: item }); + }} + > + + + )} + style={styles.flatList} + /> + + ); +} + +const styles = StyleSheet.create({ + backgroundContainer: { + flex: 1, + backgroundColor: "white", + paddingTop: StatusBar.currentHeight, + justifyContent: "flex-start", + alignItems: "center", + minHeight: Math.round(Dimensions.get("window").height), + }, + communityHeaderContainer: { + marginTop: 10, + }, + flatList: { + width: "90%", + marginTop: "5%", + }, +}); diff --git a/application/mobile/App/Screens/DeleteAccount.js b/application/mobile/App/Screens/DeleteAccount.js new file mode 100644 index 00000000..b8b9d53e --- /dev/null +++ b/application/mobile/App/Screens/DeleteAccount.js @@ -0,0 +1,97 @@ +import React, { useState, useRef } from "react"; +import { + Alert, + Text, + View, + StyleSheet, + TextInput, + StatusBar, + Image, + FlatList, + Dimensions, + TouchableOpacity, + Modal, +} from "react-native"; + + +export default function DeleteAccount({navigation}){ + const [oldPass, setOld] = useState(""); + const backButton = () => { + navigation.goBack(); + } + + const deleteAccount = () => { + navigation.goBack(); + } + + return( + + + + + + + appFanatic. + + + + Enter Your Password: + {setOld(val)}}/> + + + Delete Account + + + ) +} + +const styles = StyleSheet.create({ + backgroundContainer: { + flex: 1, + backgroundColor: "white", + paddingTop: StatusBar.currentHeight, + justifyContent: "flex-start", + minHeight: Math.round(Dimensions.get("window").height), + }, + headerContainer: { + marginTop: "5%", + flexDirection: "row", + justifyContent: "center", + alignItems: "center", + }, + backIcon: { + width: 40, + height: 50, + resizeMode:"stretch", + }, + header: { + color: "blue", + fontSize: 25, + fontWeight: "600", + }, + textInContainer: { + height: "50%", + width: "80%", + marginTop: "2%", + marginLeft: "5%", + marginBottom: "5%", + borderWidth: 2, + padding: 5, + borderRadius: 5, + borderColor: "#0001", + }, + button: { + backgroundColor: 'blue', + padding: 10, + borderRadius: 5, + alignItems: 'center', + marginBottom: "5%", + }, + inputView: { + flexDirection: "row", + marginBottom: "5%", + marginLeft: "5%", + width: "60%", + } +}) \ No newline at end of file diff --git a/application/mobile/App/Screens/FeedScreen.js b/application/mobile/App/Screens/FeedScreen.js index 14939185..256bddd0 100644 --- a/application/mobile/App/Screens/FeedScreen.js +++ b/application/mobile/App/Screens/FeedScreen.js @@ -1,4 +1,4 @@ -import React, { useState, useRef } from "react"; +import React, { useState, useRef, useEffect } from "react"; import { Text, View, @@ -13,72 +13,46 @@ import { } from "react-native"; import Icon from "react-native-vector-icons/Entypo"; import Post from "../components/Post"; +import { VITE_API_URL } from "@env"; +import axios from "axios"; export default function FeedScreen({ navigation, route }) { + const [data, setData] = useState(null); + useEffect(() => { const getPosts = () => { - return [ - { - id: 1, - profilePic: "pp1", - username: "Can Öztemiz", - community: "Fenerbahçe", - communityLink: "fenerbahcelink", - text: "Sizce Fenerbahçe'nin Trabzonspor karşısındaki hücum hattı nasıl olmalı?", - imageUrl: "image1", - likes: 278, - dislikes: 12, - commentsCount: 124, - }, - { - id: 2, - profilePic: "pp2", - username: "GalaGala123", - community: "Galatasaray", - communityLink: "galatasaraylink", - text: "Icardi'nin bugünkü performansı çok iyi değil miydi?", - imageUrl: "image2", - likes: 543, - dislikes: 23, - commentsCount: 87, - }, - { - id: 3, - profilePic: "image1", - username: "jane_doe", - community: "Fenerbahçe", - communityLink: "fenerbahcelink", - text: "This is the second sample post", - imageUrl: "https://example.com/sampleimage2.jpg", - likes: 15, - dislikes: 3, - commentsCount: 8, - }, - { - id: 4, - profilePic: "image2", - username: "jane_doe", - community: "Fenerbahçe", - communityLink: "fenerbahcelink", - text: "This is the second sample post", - imageUrl: "https://example.com/sampleimage2.jpg", - likes: 15, - dislikes: 3, - commentsCount: 8, - }, - { - id: 5, - profilePic: "pp1", - username: "jane_doe", - community: "Fenerbahçe", - communityLink: "fenerbahcelink", - text: "This is the second sample post", - imageUrl: "https://example.com/sampleimage2.jpg", - likes: 15, - dislikes: 3, - commentsCount: 8, - }, - ]; - }; + const apiUrl = `${VITE_API_URL}/api/v1/posts/feed`; + console.log(route.params.authToken); + axios + .get(apiUrl, { + headers: { + Authorization: `Bearer ${route.params.authToken}`, + }, + }) + .then((response) => { + setData(response.data); + }) + .catch((error) => { + console.error("Error fetching feed: ", error); + setData([]); + }); + }; + + getPosts(); + }, [route.params.authToken]); + + const transformData = (data) => + (data ? data : []).map((post) => ({ + id: post.postID, + profilePic: post.user.profilePicture, + username: post.username, + community: post.user.community?.name, + communityLink: post.communityLink, + text: post.text, + imageUrl: post.image, + likes: post.likes, + dislikes: post.dislikes, + commentsCount: post.commentsCount, + })); const [isMenuVisible, setIsMenuVisible] = useState(false); const [text, setText] = useState(""); @@ -89,17 +63,29 @@ export default function FeedScreen({ navigation, route }) { setIsMenuVisible(!isMenuVisible); }; + const viewCommunity = () => { + navigation.navigate("Community", { + email: route.params.email, + authToken: route.params.authToken, + }); + }; const createPost = () => { - navigation.navigate("Post"); + setIsMenuVisible(false); + navigation.navigate("Post", { authToken: route.params.authToken }); console.log("create post"); }; const viewProfile = () => { - console.log("view profile"); setIsMenuVisible(false); - navigation.navigate("Profile"); + navigation.navigate("ProfileScreen", { + profile: { username: "Jeffrey J.", profilePhoto: "pp2" }, + selfP: true, + }); + console.log("view profile"); }; const settings = () => { console.log("settings"); + setIsMenuVisible(false); + navigation.navigate("Settings"); }; const logout = () => { console.log("logout"); @@ -112,6 +98,9 @@ export default function FeedScreen({ navigation, route }) { authToken: route.params.accessToken, }); }; + const goToProfile = (attrs) => { + navigation.navigate("ProfileScreen", { profile: attrs }); + }; return ( @@ -129,6 +118,10 @@ export default function FeedScreen({ navigation, route }) { + + + View Community + Create Post @@ -160,13 +153,22 @@ export default function FeedScreen({ navigation, route }) { /> ( - + { + navigation.navigate("PostScreen", { item: item }); + }} + > + + )} style={styles.flatList} /> diff --git a/application/mobile/App/Screens/LoginScreen.js b/application/mobile/App/Screens/LoginScreen.js index 37d3e8c2..38f3289b 100644 --- a/application/mobile/App/Screens/LoginScreen.js +++ b/application/mobile/App/Screens/LoginScreen.js @@ -8,7 +8,7 @@ import { TouchableOpacity, Dimensions, } from "react-native"; -import {VITE_API_URL} from "@env"; +import { VITE_API_URL } from "@env"; import axios from "axios"; export default function LoginScreen({ navigation }) { @@ -23,7 +23,6 @@ export default function LoginScreen({ navigation }) { email: email, password: password, }; - axios .post(`${VITE_API_URL}/api/v1/auth/authenticate`, userParams) .then((response) => { @@ -35,8 +34,7 @@ export default function LoginScreen({ navigation }) { }) .catch((error) => { setError("Incorrect e-mail or password!"); - console.log(error.response.data); - console.log(error.response.status); + console.log(error); }); }; @@ -58,6 +56,7 @@ export default function LoginScreen({ navigation }) { style={styles.inputText} onChangeText={setEmail} placeholder="E-mail" + autoCapitalize="none" value={email} onSubmitEditing={() => ref_password.current.focus()} blurOnSubmit={false} @@ -66,6 +65,7 @@ export default function LoginScreen({ navigation }) { style={styles.inputText} onChangeText={setPassword} placeholder="Password" + autoCapitalize="none" secureTextEntry value={password} ref={ref_password} diff --git a/application/mobile/App/Screens/PostCreationScreen.js b/application/mobile/App/Screens/PostCreationScreen.js index 97a9e258..85790578 100644 --- a/application/mobile/App/Screens/PostCreationScreen.js +++ b/application/mobile/App/Screens/PostCreationScreen.js @@ -9,191 +9,321 @@ import { StatusBar, Dimensions, Image, - Button, + Button, } from "react-native"; import Icon from "react-native-vector-icons/Entypo"; import axios from "axios"; import AutoExpandingTextInput from "../components/AutoExpandingTextInput"; -import * as ImagePicker from 'expo-image-picker/src/ImagePicker'; -export default function PostCreationScreen({navigation}){ - const profile = { - profilePhoto: require("../assets/dummy_pics/pp2.png"), - username: "james", - email: "james@gmail.com", - supportedTeam: "Fenerbahçe", - }; - const[selectedImage, selectImage] = useState(null); - const[selectedCommunity, selectCommunity] = useState(""); - +import * as ImagePicker from "expo-image-picker/src/ImagePicker"; +import { VITE_API_URL } from "@env"; +import TagModal from "../components/TagModal"; +import Checkbox from "expo-checkbox"; +import { useRoute } from "@react-navigation/native"; - const [isMenuVisible, setIsMenuVisible] = useState(false); +export default function PostCreationScreen({ navigation }) { + const profile = { + profilePhoto: require("../assets/dummy_pics/pp2.png"), + username: "james", + email: "james@gmail.com", + supportedTeam: "Fenerbahçe", + }; + const [selectedImage, selectImage] = useState(null); + const [communityPost, setCommunity] = useState(false); + const [postMessage, changePost] = useState(""); + const [modalVisible, setModalVisible] = useState(false); + const [tags, setTags] = useState([]); + const [formData, setFormData] = useState(new FormData()); + const [authToken, setAuthtoken] = useState(""); + const [title, changeTitle] = useState(""); + const route = useRoute(); - const toggleMenu = () => { - console.log("Toggle menu"); - setIsMenuVisible(!isMenuVisible); - }; - - const createPost = () => { - navigation.navigate("Post"); - console.log("create post"); - }; - const viewProfile = () => { - console.log("view profile"); - setIsMenuVisible(false); - navigation.navigate("Profile"); - }; - const settings = () => { - console.log("settings"); - }; - const logout = () => { - console.log("logout"); - navigation.navigate("Login"); - }; - const pickImage = async () => { - const permissionResult = await ImagePicker.requestMediaLibraryPermissionsAsync(); - if (permissionResult.granted === false) { - alert("Permission to access camera roll is required!"); - return; - } - const pickerResult = await ImagePicker.launchImageLibraryAsync(); - if (pickerResult.cancelled === true) { - return; + const [isMenuVisible, setIsMenuVisible] = useState(false); + + const backButton = () => { + console.log("nav"); + navigation.goBack(); + }; + const toggleMenu = () => { + console.log("Toggle menu"); + setIsMenuVisible(!isMenuVisible); + }; + + const createPost = () => { + setIsMenuVisible(false); + navigation.navigate("Post"); + console.log("create post"); + }; + const viewProfile = () => { + console.log("view profile"); + }; + const settings = () => { + console.log("settings"); + setIsMenuVisible(false); + navigation.navigate("Settings"); + }; + const logout = () => { + console.log("logout"); + navigation.navigate("Login"); + }; + const pickImage = async () => { + const permissionResult = + await ImagePicker.requestMediaLibraryPermissionsAsync(); + if (permissionResult.granted === false) { + alert("Permission to access camera roll is required!"); + return; + } + const pickerResult = await ImagePicker.launchImageLibraryAsync(); + if (pickerResult.cancelled === true) { + return; + } + + selectImage({ localUri: pickerResult.assets[0].uri }); + }; + const removeImage = () => { + selectImage(null); + }; + const textChanged = (text) => { + changePost(text); + }; + const makeCommunity = () => { + setCommunity(!communityPost); + }; + const closeModal = () => { + setModalVisible(false); + }; + const toggleModal = () => { + setModalVisible(!modalVisible); + }; + const handleTags = (selectedTags) => { + setTags(selectedTags); + }; + const sendPost = () => { + let comm = communityPost ? "COMMUNITY" : "GLOBAL"; + + formData.append("title", title); + formData.append("text", postMessage); + formData.append("image", { + type: "file", + src: selectedImage, + disabled: selectedImage == null, + }); + formData.append("postedAt", comm); + + axios + .post( + `${VITE_API_URL}/api/v1/posts?title=${title}&text=${postMessage}&postedAt=${comm}`, + { + image: { + type: "file", + src: selectedImage["localUri"], + disabled: selectedImage == null, + }, + }, + { + headers: { + Authorization: `Bearer ${route.params.authToken}`, + }, } - + ) + .then((response) => { + setFormData(new FormData()); + navigation.navigate("Feed", { authToken: route.params.authToken }); + }) + .catch((error) => { + setFormData(new FormData()); + console.log(error); + alert("Something went wrong"); + navigation.navigate("Feed", { authToken: route.params.authToken }); + }); + }; - selectImage({ localUri: pickerResult.assets[0].uri }); - } - const removeImage = () => { - selectImage(null); - } - const pickCommunity = (comm) =>{ - selectCommunity(comm); - } - return( + return ( - - Fanatic - - + + + + + + appFanatic. + + + + + + - - - + { + changeTitle(val); + }} + placeholder="Your Post Title" + /> + + + - + {selectedImage !== null && ( - + )} - - - + + + + + + + + Publish Post + + + Publish This As A Community Post + + -