Skip to content

Instantly share code, notes, and snippets.

@adelowo

adelowo/App.js Secret

Created February 13, 2020 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adelowo/b63267a25a016987e10f97faf2e04328 to your computer and use it in GitHub Desktop.
Save adelowo/b63267a25a016987e10f97faf2e04328 to your computer and use it in GitHub Desktop.
import React, {Component} from 'react';
import {Alert, StyleSheet, View, SafeAreaView} from 'react-native';
import {StreamChat} from 'stream-chat';
import Signup from './Signup';
import VideoPlayer from './VideoPlayer';
import Chat from './Chat';
import axios from 'axios';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
isAuthenticated: false,
id: '',
};
this.chatClient = new StreamChat('STREAM_KEY_FROM_DASHBOARD');
}
onLoginCallBack = user => {
if (user.email.length === 0) {
Alert.alert('Login', 'Please provide your email');
return;
}
if (user.password.length === 0) {
Alert.alert('Login', 'Please provide your password');
return;
}
user = {
...user,
name: {
first: 'Bot',
last: 'Last Name',
},
};
axios
.post('http://localhost:5200/v1/auth/init', user, {
headers: {Authorization: 'AUTHORIZATION_HEADER'},
})
.then(res => {
this.chatClient.setUser(
{
id: res.data.user._id,
username: res.data.user.email,
image:
'https://stepupandlive.files.wordpress.com/2014/09/3d-animated-frog-image.jpg',
},
res.data.token
);
this.setState({
isAuthenticated: true,
id: res.data.user._id,
});
})
.catch(err => {
console.log(err);
Alert.alert('Login', 'Could not log you in');
});
};
render() {
return (
<SafeAreaView style={{flex: 1}}>
<View style={{flex: 1}}>
{!this.state.isAuthenticated || this.state.currentUser === null ? (
<View style={styles.container}>
<Signup cb={this.onLoginCallBack} />
</View>
) : (
<View style={[{flex: 1}]}>
<View style={{flex: 0.4}}>
<VideoPlayer />
</View>
<View style={{flex: 0.6}}>
<Chat userID={this.state.id} chatClient={this.chatClient} />
</View>
</View>
)}
</View>
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment