diff --git a/.gitignore b/.gitignore index 12c149c..c131846 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,7 @@ local.properties # vscode .vscode - +.history # node.js # node_modules/ diff --git a/package.json b/package.json index 70df8df..de4fc69 100644 --- a/package.json +++ b/package.json @@ -10,15 +10,23 @@ "test": "jest" }, "dependencies": { + "@react-native-async-storage/async-storage": "^1.18.1", + "@react-navigation/material-bottom-tabs": "^6.2.15", + "@react-navigation/native": "^6.1.6", + "@react-navigation/native-stack": "^6.9.12", + "@reduxjs/toolkit": "^1.9.3", "axios": "^1.3.4", "expo": "^48.0.9", "expo-cli": "^6.3.2", - "@react-navigation/native": "^6.1.6", - "@react-navigation/native-stack": "^6.9.12", "react": "18.2.0", "react-native": "0.71.4", + "react-native-async-storage": "^0.0.1", + "react-native-paper": "^5.6.0", "react-native-simple-toast": "^2.0.0", - "react-native-vector-icons": "^9.2.0" + "react-native-vector-icons": "^9.2.0", + "react-redux": "^8.0.5", + "redux": "^4.2.1", + "redux-persist": "^6.0.0" }, "devDependencies": { "@babel/core": "^7.20.0", @@ -28,6 +36,7 @@ "@tsconfig/react-native": "^2.0.2", "@types/jest": "^29.2.1", "@types/react": "^18.0.24", + "@types/react-native": "^0.71.5", "@types/react-native-vector-icons": "^6.4.13", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.2.1", diff --git a/src/App.tsx b/src/App.tsx index 18094c6..e58a14a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,76 +5,96 @@ * @format */ import * as React from 'react'; -import { NavigationContainer, StackActions } from '@react-navigation/native'; -import type { PropsWithChildren } from 'react'; +import {NavigationContainer, StackActions} from '@react-navigation/native'; +import type {PropsWithChildren} from 'react'; import { - SafeAreaView, - ScrollView, - StatusBar, - StyleSheet, - Text, - useColorScheme, - View, + SafeAreaView, + ScrollView, + StatusBar, + StyleSheet, + Text, + useColorScheme, + View, } from 'react-native'; import ClipViewLocal from './clip/ClipViewLocal'; import ClipViewRemote from './clip/ClipViewRemote'; -import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs'; -import { createNativeStackNavigator } from '@react-navigation/native-stack'; +import {createMaterialBottomTabNavigator} from '@react-navigation/material-bottom-tabs'; +import {createNativeStackNavigator} from '@react-navigation/native-stack'; import SignIn from './auth/SignIn'; import SignUp from './auth/SignUp'; -import { Provider } from 'react-redux'; -import { store, persistor } from './redux/store'; -import { PersistGate } from 'redux-persist/integration/react'; - - +import {Provider} from 'react-redux'; +import {store, persistor} from './redux/store'; +import {PersistGate} from 'redux-persist/integration/react'; const Stack = createNativeStackNavigator(); const Tab = createMaterialBottomTabNavigator(); class App extends React.Component { - - constructor(props: any) { - super(props); - this.state = { - token: "", - username: "" - } - store.subscribe(() => { - this.setState({ token: store.getState().persistedUserReducer.token }); - }); - } - - render(): React.ReactNode { - console.log("render app", store.getState()); - console.log("app state", this.state); - return - - - - { - this.state.token === "" - ? - //////////////////////////////////////////////////////////// - <> - } name="Login" options={{ title: 'Connexion' }} /> - } name="Register" options={{ title: 'Créer un compte' }} /> - - : - //////////////////////////////////////////////////////////// - <> - - {(props) => } - - - {(props) => } - - - //////////////////////////////////////////////////////////// - } - - + constructor(props: any) { + super(props); + this.state = { + token: '', + username: '', }; + store.subscribe(() => { + this.setState({token: store.getState().persistedUserReducer.token}); + }); + } + + render(): React.ReactNode { + console.log('render app', store.getState()); + console.log('app state', this.state); + return ( + + + + + { + this.state.token === '' ? ( + //////////////////////////////////////////////////////////// + <> + } + name="Login" + options={{title: 'Connexion'}} + /> + } + name="Register" + options={{title: 'Créer un compte'}} + /> + + ) : ( + //////////////////////////////////////////////////////////// + <> + + {props => ( + + )} + + + {props => ( + + )} + + + ) + //////////////////////////////////////////////////////////// + } + + + + ); + } } export default App; diff --git a/src/auth/SignUp.tsx b/src/auth/SignUp.tsx index 33ee082..da986a8 100644 --- a/src/auth/SignUp.tsx +++ b/src/auth/SignUp.tsx @@ -1,65 +1,77 @@ import React from 'react'; -import { View, Text, Button, TextInput } from 'react-native'; -import { accessibilityProps } from 'react-native-paper/lib/typescript/src/components/MaterialCommunityIcon'; -import { setUser } from '../redux/actions'; - +import {View, Text, Button, TextInput} from 'react-native'; +import {accessibilityProps} from 'react-native-paper/lib/typescript/src/components/MaterialCommunityIcon'; +import {setUser} from '../redux/actions'; export default class SignUp extends React.Component { + constructor(props: any) { + super(props); + this.state = { + username: '', + password: '', + }; + this.signUpFunction = this.signUpFunction.bind(this); + this.updateUsername = this.updateUsername.bind(this); + this.updatePassword = this.updatePassword.bind(this); + } - constructor(props: any) { - super(props); - this.state = { - username: '', - password: '' - } - this.signUpFunction = this.signUpFunction.bind(this); - this.updateUsername = this.updateUsername.bind(this); - this.updatePassword = this.updatePassword.bind(this); + async signUpFunction() { + const data = new FormData(); + data.append('username', this.state.username); + data.append('password', this.state.password); + const signUpResponse = await fetch( + 'https://notifysync.simailadjalim.fr/user', + { + method: 'PUT', + body: data, + }, + ); + const signUpJson = await signUpResponse.json(); + if (signUpJson.status === 'ok') { + const signInResponse = await fetch( + 'https://notifysync.simailadjalim.fr/user', + { + method: 'POST', + body: data, + }, + ); + const signInJson = await signInResponse.json(); + if (signInJson.status === 'ok') { + this.props.store.dispatch(setUser(signInJson.token)); + } else { + console.log(signInJson); + } + } else { + console.log(signUpJson); } + } - async signUpFunction() { - const data = new FormData(); - data.append("username", this.state.username); - data.append("password", this.state.password); - const signUpResponse = await fetch( - 'https://notifysync.simailadjalim.fr/user', - { - method: 'PUT', - body: data - } - ); - const signUpJson = await signUpResponse.json(); - if (signUpJson.status === "ok") { - const signInResponse = await fetch( - 'https://notifysync.simailadjalim.fr/user', - { - method: 'POST', - body: data - } - ); - const signInJson = await signInResponse.json(); - if (signInJson.status === "ok") { - this.props.store.dispatch(setUser(signInJson.token)); - } else console.log(signInJson); - } else console.log(signUpJson); - } + updateUsername(username: string) { + this.setState({username: username}); + } - updateUsername(username: string) { - this.setState({ username: username }); - } + updatePassword(password: any) { + this.setState({password: password}); + } - updatePassword(password: any) { - this.setState({ password: password }); - } - - render(): React.ReactNode { - return ( - - Créer un compte - - -