diff --git a/assets/images/default_profile_picture.jpeg b/assets/images/default_profile_picture.jpeg new file mode 100644 index 0000000..2a51528 Binary files /dev/null and b/assets/images/default_profile_picture.jpeg differ diff --git a/authentification/AuthContext.tsx b/authentification/AuthContext.tsx index 237bec6..9145063 100644 --- a/authentification/AuthContext.tsx +++ b/authentification/AuthContext.tsx @@ -14,6 +14,7 @@ import { navigate, reset } from "../navigation/NavigationService"; import { jwtDecode } from "jwt-decode"; import "core-js/stable/atob"; import { registerForPushNotificationsAsync } from "../screens/NotificationScreen"; +import * as FileSystem from 'expo-file-system'; interface AuthContextType { token: string | null; @@ -33,6 +34,7 @@ interface AuthContextType { password: string, nickname: string, email: string, + profilePicture: string, setServerError: Dispatch>, setUsernameErrorText: Dispatch>, setEmailErrorText: Dispatch>, @@ -273,24 +275,37 @@ export const AuthProvider: React.FC = ({ children }) => { password, nickname, email, + profilePicture, setServerError, setUsernameErrorText, setEmailErrorText, ) => { let response; let data; + let base64; + + if(profilePicture !== ''){ + base64 = await FileSystem.readAsStringAsync(profilePicture, { + encoding: FileSystem.EncodingType.Base64, + }); + } + + const body = JSON.stringify({ + username: username, + password: password, + nickname: nickname, + email: email, + profilePicture: base64 + }) + + try { response = await fetch(`${baseUrl}users`, { method: "POST", headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ - username: username, - password: password, - nickname: nickname, - email: email, - }), + body: body, }); data = await response.json(); switch (response.status) { diff --git a/components/Register.tsx b/components/Register.tsx index c32c4fc..a810a96 100644 --- a/components/Register.tsx +++ b/components/Register.tsx @@ -1,8 +1,11 @@ import React, { useState, Dispatch, SetStateAction } from "react"; -import { ScrollView, Text, TouchableOpacity, View } from "react-native"; +import { ScrollView, Text, TouchableOpacity, View, Image } from "react-native"; import FloatingLabelInput from "./FloatingLabelInput"; import { COLORS } from "../theme"; import { useAuth } from "../authentification/AuthContext"; +import * as ImagePicker from 'expo-image-picker'; +import Ionicons from "@expo/vector-icons/Ionicons"; + interface Props { setServerError: Dispatch>; @@ -135,6 +138,25 @@ const Register: React.FC = ({ setServerError }) => { } }; + const [image, setImage] = useState(''); + const pickImage = async () => { + let result = await ImagePicker.launchImageLibraryAsync({ + mediaTypes: ImagePicker.MediaTypeOptions.Images, + allowsEditing: true, + aspect: [4, 3], + quality: 1, + }); + + + if (!result.canceled) { + setImage(result.assets[0].uri); + } + }; + + const removeImage = () => { + setImage(''); + } + return ( = ({ setServerError }) => { alwaysBounceVertical={false} showsVerticalScrollIndicator={false} > + + + + + + + + + + + = ({ setServerError }) => { password, nickname, email, + image, setServerError, setUsernameErrorText, setEmailErrorText, diff --git a/screens/PostScreen.tsx b/screens/PostScreen.tsx index b704b15..7a3c604 100644 --- a/screens/PostScreen.tsx +++ b/screens/PostScreen.tsx @@ -6,9 +6,7 @@ import { Text, Keyboard, TouchableWithoutFeedback, - Button, Image, - StyleSheet } from "react-native"; import { SHADOWS, COLORS } from "../theme"; import { baseUrl } from "../env"; @@ -106,7 +104,7 @@ const PostScreen: React.FC = () => { const [image, setImage] = useState(''); const pickImage = async () => { let result = await ImagePicker.launchImageLibraryAsync({ - mediaTypes: ImagePicker.MediaTypeOptions.All, + mediaTypes: ImagePicker.MediaTypeOptions.Images, allowsEditing: true, aspect: [4, 3], quality: 1, @@ -143,11 +141,7 @@ const PostScreen: React.FC = () => { - {image !== '' ? ( - - ) : ( - - )} +