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
+
-
+
);
}
diff --git a/src/auth/SignUp.tsx b/src/auth/SignUp.tsx
index 089be28..83ec4a3 100644
--- a/src/auth/SignUp.tsx
+++ b/src/auth/SignUp.tsx
@@ -1,6 +1,7 @@
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';
export default class SignUp extends React.Component {
@@ -11,56 +12,45 @@ export default class SignUp extends React.Component {
username: '',
password: ''
}
+ this.signUpFunction = this.signUpFunction.bind(this);
this.updateUsername = this.updateUsername.bind(this);
this.updatePassword = this.updatePassword.bind(this);
- this.signUpFunction = this.signUpFunction.bind(this);
}
async signUpFunction() {
- const signInResponse = await fetch('https://notifysync.simailadjalim.fr/user', {
- method: 'PUT',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- username: this.state.username,
- password: this.state.password
- }),
- });
- const signInJson = await signInResponse.json();
- if (signInJson.status == "ok"){
- const loginResponse = await fetch('https://notifysync.simailadjalim.fr/user', {
- method: 'POST',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- username: this.state.username,
- password: this.state.password
- }),
- });
- const loginJson = await loginResponse.json();
-
- }
+ const signUpResponse = await fetch(
+ 'https://notifysync.simailadjalim.fr/user?username=' + this.state.username + '&password=' + this.state.password,
+ { method: 'PUT' }
+ );
+ const signUpJson = await signUpResponse.json();
+ if (signUpJson.status === "ok") {
+ 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);
+ } else console.log(signUpJson);
}
- updateUsername(event: any) {
- this.setState({ username: event.target.value });
+ updateUsername(username: string) {
+ this.setState({ username: username });
}
- updatePassword(event: any) {
- this.setState({ password: event.target.value });
+ updatePassword(password: any) {
+ this.setState({ password: password });
}
render(): React.ReactNode {
return (
- Sign Up
-
-
-
+ Créer un compte
+
+
+
);
}
diff --git a/src/clip/AClipView.tsx b/src/clip/AClipView.tsx
index 38e0f59..603aabb 100644
--- a/src/clip/AClipView.tsx
+++ b/src/clip/AClipView.tsx
@@ -1,7 +1,6 @@
import React from 'react';
-import { ScrollView, Text, Button } from 'react-native';
-import ClipList from './ClipList';
-
+import { Button } from 'react-native';
+import { clearUser } from '../redux/actions';
export default abstract class AClipView extends React.Component {
@@ -12,6 +11,13 @@ export default abstract class AClipView extends React.Component {
}
}
+ getSignOutBtn() {
+ return