diff --git a/src/App.tsx b/src/App.tsx index 659be7e..c083e13 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -21,44 +21,63 @@ 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 SignUp from './auth/SignUp'; import SignIn from './auth/SignIn'; +import SignUp from './auth/SignUp'; +import { Provider } from 'react-redux'; +import store from './redux/store'; const Stack = createNativeStackNavigator(); const Tab = createMaterialBottomTabNavigator(); -function Clip() { - return ( - - - {(props) => } - - - {(props) => } - - - ); -} +class App extends React.Component { -function Auth() { - return - - - ; -} + constructor(props: any) { + super(props); + this.state = { + token: "", + username: "" + } + store.subscribe(() => { + console.log("see a dispatch"); + this.setState({ token: store.getState().userReducer.token}) + }); + } -function App(): JSX.Element { - return ( - - - {/*-------------------------------------------*/} - - {/*-------------------------------------------*/} - - {/*-------------------------------------------*/} - + Auth() { + return + + } name="Login" options={{ title: 'Connexion' }} /> + } name="Register" options={{ title: 'Créer un compte' }} /> + + ; + } + + Clip() { + return ( + + + {(props) => } + + + {(props) => } + + + ); + } + + render(): React.ReactNode { + console.log("render app", store.getState()); + console.log("app state", this.state); + return + { + this.state.token === "" + ? + + : + + } - ); + }; } const styles = StyleSheet.create({ diff --git a/src/auth/SignIn.tsx b/src/auth/SignIn.tsx index af1310e..eea6d42 100644 --- a/src/auth/SignIn.tsx +++ b/src/auth/SignIn.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { View, Text, Button, TextInput } from 'react-native'; - +import { setUser } from '../redux/actions'; export default class SignIn extends React.Component { @@ -16,6 +16,15 @@ export default class SignIn extends React.Component { } async signInFunction() { + const signInResponse = await fetch( + 'https://notifysync.simailadjalim.fr/user?username=' + this.state.username + '&password=' + this.state.password, + { method: 'POST' } + ); + const signInJson = await signInResponse.json(); + if (signInJson.status === "ok") { + console.log(this.props.store); + this.props.store.dispatch(setUser(signInJson.token, this.state.username)); + } else console.log(signInJson); } updateUsername(event: any) { @@ -29,10 +38,10 @@ export default class SignIn extends React.Component { render(): React.ReactNode { return ( - Sign In - + Connexion + -