Commit 9a9b013a by OuiAtichat

update

parent aed87281
{
"projects": {
"default": "safetcut-20cdf"
}
}
...@@ -235,7 +235,7 @@ const AppStack = createSwitchNavigator( ...@@ -235,7 +235,7 @@ const AppStack = createSwitchNavigator(
Main: MainStack, Main: MainStack,
}, },
{ {
initialRouteName: 'Intro', initialRouteName: 'AuthLoading',
} }
); );
......
import firebase from 'firebase/app';
// These imports load individual services into the firebase namespace.
import 'firebase/auth';
import 'firebase/firestore';
const app = firebase.initializeApp({
apiKey: 'AIzaSyBoWBj5AyWlTV_7VSxbYqCRT2KgT5aK0po',
authDomain: 'safetcut-20cdf.firebaseapp.com',
databaseURL: 'https://safetcut-20cdf.firebaseio.com',
projectId: 'safetcut-20cdf',
storageBucket: '',
messagingSenderId: '716807932076',
});
export default app;
const fireStore = app.firestore();
export { fireStore };
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
}
}
{
"indexes": [],
"fieldOverrides": []
}
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
\ No newline at end of file
...@@ -50,217 +50,10 @@ const MultipleMockData = [ ...@@ -50,217 +50,10 @@ const MultipleMockData = [
{ day: 'S', dayActive: false }, { day: 'S', dayActive: false },
], ],
}, },
{
time: '8:00',
period: 'AM',
name: 'Slot 3',
active: false,
power: true,
day: [
{ day: 'S', dayActive: false },
{ day: 'M', dayActive: false },
{ day: 'T', dayActive: true },
{ day: 'W', dayActive: false },
{ day: 'T', dayActive: false },
{ day: 'F', dayActive: false },
{ day: 'S', dayActive: false },
],
},
{
time: '9:00',
period: 'AM',
name: 'Slot 4',
active: true,
power: false,
day: [
{ day: 'S', dayActive: true },
{ day: 'M', dayActive: true },
{ day: 'T', dayActive: true },
{ day: 'W', dayActive: true },
{ day: 'T', dayActive: false },
{ day: 'F', dayActive: true },
{ day: 'S', dayActive: false },
],
},
{
time: '8:00',
period: 'PM',
name: 'Slot 5',
active: false,
power: true,
day: [
{ day: 'S', dayActive: false },
{ day: 'M', dayActive: false },
{ day: 'T', dayActive: true },
{ day: 'W', dayActive: false },
{ day: 'T', dayActive: false },
{ day: 'F', dayActive: false },
{ day: 'S', dayActive: false },
],
},
], ],
}, },
{ {
tabName: 'MCB Link 1', tabName: 'Main MCB Link',
timer: [
{
time: '6:00',
period: 'AM',
name: 'Slot 1',
active: true,
power: true,
day: [
{ day: 'S', dayActive: true },
{ day: 'M', dayActive: true },
{ day: 'T', dayActive: true },
{ day: 'W', dayActive: true },
{ day: 'T', dayActive: false },
{ day: 'F', dayActive: true },
{ day: 'S', dayActive: true },
],
},
{
time: '7:00',
period: 'AM',
name: 'Slot 2',
active: true,
power: false,
day: [
{ day: 'S', dayActive: true },
{ day: 'M', dayActive: true },
{ day: 'T', dayActive: true },
{ day: 'W', dayActive: true },
{ day: 'T', dayActive: false },
{ day: 'F', dayActive: true },
{ day: 'S', dayActive: false },
],
},
{
time: '8:00',
period: 'PM',
name: 'Slot 3',
active: false,
power: true,
day: [
{ day: 'S', dayActive: false },
{ day: 'M', dayActive: false },
{ day: 'T', dayActive: true },
{ day: 'W', dayActive: false },
{ day: 'T', dayActive: false },
{ day: 'F', dayActive: false },
{ day: 'S', dayActive: false },
],
},
],
},
{
tabName: 'MCB Link 2',
timer: [
{
time: '6:00',
period: 'AM',
name: 'Slot 1',
active: false,
power: true,
day: [
{ day: 'S', dayActive: true },
{ day: 'M', dayActive: true },
{ day: 'T', dayActive: true },
{ day: 'W', dayActive: true },
{ day: 'T', dayActive: false },
{ day: 'F', dayActive: true },
{ day: 'S', dayActive: true },
],
},
{
time: '7:00',
period: 'AM',
name: 'Slot 2',
active: false,
power: false,
day: [
{ day: 'S', dayActive: true },
{ day: 'M', dayActive: true },
{ day: 'T', dayActive: true },
{ day: 'W', dayActive: true },
{ day: 'T', dayActive: false },
{ day: 'F', dayActive: true },
{ day: 'S', dayActive: false },
],
},
{
time: '8:00',
period: 'PM',
name: 'Slot 3',
active: false,
power: true,
day: [
{ day: 'S', dayActive: false },
{ day: 'M', dayActive: false },
{ day: 'T', dayActive: true },
{ day: 'W', dayActive: false },
{ day: 'T', dayActive: false },
{ day: 'F', dayActive: false },
{ day: 'S', dayActive: false },
],
},
],
},
{
tabName: 'MCB Link 3',
timer: [
{
time: '6:00',
period: 'AM',
name: 'Slot 1',
active: true,
power: true,
day: [
{ day: 'S', dayActive: true },
{ day: 'M', dayActive: true },
{ day: 'T', dayActive: true },
{ day: 'W', dayActive: true },
{ day: 'T', dayActive: false },
{ day: 'F', dayActive: true },
{ day: 'S', dayActive: true },
],
},
{
time: '7:00',
period: 'AM',
name: 'Slot 2',
active: true,
power: false,
day: [
{ day: 'S', dayActive: true },
{ day: 'M', dayActive: true },
{ day: 'T', dayActive: true },
{ day: 'W', dayActive: true },
{ day: 'T', dayActive: false },
{ day: 'F', dayActive: true },
{ day: 'S', dayActive: false },
],
},
{
time: '8:00',
period: 'PM',
name: 'Slot 3',
active: false,
power: true,
day: [
{ day: 'S', dayActive: false },
{ day: 'M', dayActive: false },
{ day: 'T', dayActive: true },
{ day: 'W', dayActive: false },
{ day: 'T', dayActive: false },
{ day: 'F', dayActive: false },
{ day: 'S', dayActive: false },
],
},
],
},
{
tabName: 'MCB Link 4',
timer: [ timer: [
{ {
time: '6:00', time: '6:00',
...@@ -294,22 +87,6 @@ const MultipleMockData = [ ...@@ -294,22 +87,6 @@ const MultipleMockData = [
{ day: 'S', dayActive: false }, { day: 'S', dayActive: false },
], ],
}, },
{
time: '8:00',
period: 'PM',
name: 'Slot 3',
active: false,
power: true,
day: [
{ day: 'S', dayActive: false },
{ day: 'M', dayActive: false },
{ day: 'T', dayActive: true },
{ day: 'W', dayActive: false },
{ day: 'T', dayActive: false },
{ day: 'F', dayActive: false },
{ day: 'S', dayActive: false },
],
},
], ],
}, },
]; ];
...@@ -347,22 +124,22 @@ export default class TimerScreen extends Component { ...@@ -347,22 +124,22 @@ export default class TimerScreen extends Component {
isVisible: false, isVisible: false,
}; };
renderTimerFab = () => { // renderTimerFab = () => {
return ( // return (
<Fab // <Fab
containerStyle={{ // containerStyle={{
bottom: '15%', // bottom: '15%',
// right: '50%', // centerFAB // // right: '50%', // centerFAB
// marginRight: -28, // // marginRight: -28,
}} // }}
style={{ backgroundColor: color.primary }} // style={{ backgroundColor: color.primary }}
position="bottomRight" // position="bottomRight"
onPress={() => this.setState({ isVisible: true })} // onPress={() => this.setState({ isVisible: true })}
> // >
<Icon name="add" /> // <Icon name="add" />
</Fab> // </Fab>
); // );
}; // };
_onSwipeOpen = swipeInstance => { _onSwipeOpen = swipeInstance => {
if (this.currentlyOpenSwipe && this.currentlyOpenSwipe !== swipeInstance) { if (this.currentlyOpenSwipe && this.currentlyOpenSwipe !== swipeInstance) {
this.currentlyOpenSwipe.close(); this.currentlyOpenSwipe.close();
...@@ -371,45 +148,24 @@ export default class TimerScreen extends Component { ...@@ -371,45 +148,24 @@ export default class TimerScreen extends Component {
this.currentlyOpenSwipe = swipeInstance; this.currentlyOpenSwipe = swipeInstance;
}; };
render() { render() {
console.log(MultipleMockData[0]);
return ( return (
<> <>
<Tabs <FlatList
locked contentContainerStyle={{ paddingBottom: isIphoneX() ? 90 : 55 }}
tabBarUnderlineStyle={{ backgroundColor: 'transparent' }} data={MultipleMockData[0].timer}
renderTabBar={() => <ScrollableTab style={{ backgroundColor: color.white, borderWidth: 0 }} />} ListEmptyComponent={() => (
locked <View>
> <Text style={[theme.normalText, theme.mt2]}>No Data</Text>
{MultipleMockData.map((item, index) => ( </View>
<Tab )}
key={index + item.tabName} ItemSeparatorComponent={() => <View style={styles.separator} />}
textStyle={[theme.description]} // ListFooterComponent={() => item.timer.length > 0 && <View style={styles.separator} />}
activeTextStyle={[theme.description, theme.textWhite]} renderItem={({ item, index }) => (
tabStyle={{ backgroundColor: color.white }} <SwipeableRow item={item} index={index} onSwipeOpen={this._onSwipeOpen} />
activeTabStyle={{ )}
backgroundColor: color.primary, keyExtractor={(item, index) => `timer ${index}`}
borderRadius: 100, />
margin: 10,
}}
heading={item.tabName}
>
<FlatList
contentContainerStyle={{ paddingBottom: isIphoneX() ? 90 : 55 }}
data={item.timer}
ListEmptyComponent={() => (
<View>
<Text style={[theme.normalText, theme.mt2]}>No Data</Text>
</View>
)}
ItemSeparatorComponent={() => <View style={styles.separator} />}
ListFooterComponent={() => item.timer.length > 0 && <View style={styles.separator} />}
renderItem={({ item, index }) => (
<SwipeableRow item={item} index={index} onSwipeOpen={this._onSwipeOpen} />
)}
keyExtractor={(item, index) => `timer ${index}`}
/>
</Tab>
))}
</Tabs>
<Modal <Modal
transparent transparent
...@@ -511,7 +267,7 @@ export default class TimerScreen extends Component { ...@@ -511,7 +267,7 @@ export default class TimerScreen extends Component {
</ScrollView> </ScrollView>
</View> </View>
</Modal> </Modal>
{this.renderTimerFab()} {/* {this.renderTimerFab()} */}
</> </>
); );
} }
......
...@@ -3,6 +3,7 @@ import { ActivityIndicator, View, StatusBar, Image } from 'react-native'; ...@@ -3,6 +3,7 @@ import { ActivityIndicator, View, StatusBar, Image } from 'react-native';
import AsyncStorage from '@react-native-community/async-storage'; //expo not yet support import AsyncStorage from '@react-native-community/async-storage'; //expo not yet support
import logo from '../../assets/images/logo2.png'; import logo from '../../assets/images/logo2.png';
import { width } from '../../constants/Layout'; import { width } from '../../constants/Layout';
import app from '../../firebase';
export default class AuthLoadingScreen extends Component { export default class AuthLoadingScreen extends Component {
static navigationOptions = { static navigationOptions = {
...@@ -10,15 +11,16 @@ export default class AuthLoadingScreen extends Component { ...@@ -10,15 +11,16 @@ export default class AuthLoadingScreen extends Component {
}; };
state = { state = {
isShowImg: true, isShowImg: true,
authentication: null,
}; };
performTimeConsumingTask = async () => { // performTimeConsumingTask = async () => {
return new Promise(resolve => // return new Promise(resolve =>
setTimeout(() => { // setTimeout(() => {
resolve('loadingCompleted'); // resolve('loadingCompleted');
}, 1700) // }, 200)
); // );
}; // };
showLogoThenIndicator = () => { showLogoThenIndicator = () => {
setTimeout(() => { setTimeout(() => {
...@@ -32,15 +34,28 @@ export default class AuthLoadingScreen extends Component { ...@@ -32,15 +34,28 @@ export default class AuthLoadingScreen extends Component {
// Preload data using AsyncStorage // Preload data using AsyncStorage
const alreadyLaunched = await AsyncStorage.getItem('alreadyLaunched'); const alreadyLaunched = await AsyncStorage.getItem('alreadyLaunched');
const RememberedLogin = await AsyncStorage.getItem('RememberedLogin'); const RememberedLogin = await AsyncStorage.getItem('RememberedLogin');
// console.log(alreadyLaunched, RememberedLogin);
const loading = await this.performTimeConsumingTask(); // const loading = await this.performTimeConsumingTask();
if (loading) { // if (loading) {
RememberedLogin app.auth().onAuthStateChanged(user => {
? this.props.navigation.navigate('Main') if (user) {
: this.props.navigation.navigate(alreadyLaunched ? 'Login' : 'Onboarding'); // this.setState({ authentication: true });
} this.props.navigation.navigate(RememberedLogin ? 'Main' : 'Login');
} else {
// this.setState({ authentication: false });
this.props.navigation.navigate(alreadyLaunched ? 'Login' : 'Onboarding');
}
});
} }
// componentDidUpdate = (prevProps, prevState) => {
// if (prevState.authentication !== this.state.authentication) {
// this.state.authentication
// ? this.props.navigation.navigate(RememberedLogin ? 'Main' : 'Login')
// : this.props.navigation.navigate(alreadyLaunched ? 'Login' : 'Onboarding');
// }
// };
render() { render() {
return ( return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
......
...@@ -4,6 +4,7 @@ import { theme, color } from '../../constants/Styles'; ...@@ -4,6 +4,7 @@ import { theme, color } from '../../constants/Styles';
import AsyncStorage from '@react-native-community/async-storage'; import AsyncStorage from '@react-native-community/async-storage';
import LoginForm from '../../components/Form/LoginForm'; import LoginForm from '../../components/Form/LoginForm';
import { KeyboardAvoidingView, View } from 'react-native'; import { KeyboardAvoidingView, View } from 'react-native';
import app from '../../firebase';
export default class LoginScreen extends Component { export default class LoginScreen extends Component {
static navigationOptions = { static navigationOptions = {
...@@ -16,30 +17,41 @@ export default class LoginScreen extends Component { ...@@ -16,30 +17,41 @@ export default class LoginScreen extends Component {
passVisible: false, passVisible: false,
}; };
async success() { handleSignIn = async values => {
console.log('call success function'); const { username, password } = values;
await AsyncStorage.setItem('alreadyLaunched', 'true'); try {
console.log('Remembered me?', this.state.isCheck); await app.auth().signInWithEmailAndPassword(username, password);
this.state.isCheck === true && (await AsyncStorage.setItem('RememberedLogin', 'true'));
this.props.navigation.navigate('SmartMeter');
}
submit = values => {
if (values.username == 'test' && values.password == 'password') {
console.log('Login Success!', values);
this.success(); this.success();
} else if (values.username == 'test') { } catch (error) {
alert('Wrong password! \n ==> password'); alert(error);
} else {
alert('Wrong username & password! \n ==> (test, password)');
} }
}; };
success = async () => {
// console.log('call success function');
const alreadyLaunched = await AsyncStorage.getItem('alreadyLaunched');
if (alreadyLaunched !== null) await AsyncStorage.setItem('alreadyLaunched', 'true');
// console.log('Remembered me?', this.state.isCheck);
this.state.isCheck === true && (await AsyncStorage.setItem('RememberedLogin', 'true'));
this.props.navigation.navigate('Main');
};
// submit = values => {
// if (values.username == 'test' && values.password == 'password') {
// console.log('Login Success!', values);
// this.success();
// } else if (values.username == 'test') {
// alert('Wrong password! \n ==> password');
// } else {
// alert('Wrong username & password! \n ==> (test, password)');
// }
// };
render() { render() {
return ( return (
<KeyboardAvoidingView style={theme.introContainer}> <KeyboardAvoidingView style={theme.introContainer}>
<Text style={[theme.title, theme.textDark]}>Login</Text> <Text style={[theme.title, theme.textDark]}>Login</Text>
<LoginForm onSubmit={this.submit}> <LoginForm onSubmit={this.handleSignIn}>
<View style={[theme.rowContainer, theme.mt1, { justifyContent: 'space-between' }]}> <View style={[theme.rowContainer, theme.mt1, { justifyContent: 'space-between' }]}>
<View style={[theme.rowContainer]}> <View style={[theme.rowContainer]}>
<CheckBox <CheckBox
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment