Commit 9a9b013a by OuiAtichat

update

parent aed87281
{
"projects": {
"default": "safetcut-20cdf"
}
}
......@@ -235,7 +235,7 @@ const AppStack = createSwitchNavigator(
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 = [
{ 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',
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',
tabName: 'Main MCB Link',
timer: [
{
time: '6:00',
......@@ -294,22 +87,6 @@ const MultipleMockData = [
{ 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 {
isVisible: false,
};
renderTimerFab = () => {
return (
<Fab
containerStyle={{
bottom: '15%',
// right: '50%', // centerFAB
// marginRight: -28,
}}
style={{ backgroundColor: color.primary }}
position="bottomRight"
onPress={() => this.setState({ isVisible: true })}
>
<Icon name="add" />
</Fab>
);
};
// renderTimerFab = () => {
// return (
// <Fab
// containerStyle={{
// bottom: '15%',
// // right: '50%', // centerFAB
// // marginRight: -28,
// }}
// style={{ backgroundColor: color.primary }}
// position="bottomRight"
// onPress={() => this.setState({ isVisible: true })}
// >
// <Icon name="add" />
// </Fab>
// );
// };
_onSwipeOpen = swipeInstance => {
if (this.currentlyOpenSwipe && this.currentlyOpenSwipe !== swipeInstance) {
this.currentlyOpenSwipe.close();
......@@ -371,45 +148,24 @@ export default class TimerScreen extends Component {
this.currentlyOpenSwipe = swipeInstance;
};
render() {
console.log(MultipleMockData[0]);
return (
<>
<Tabs
locked
tabBarUnderlineStyle={{ backgroundColor: 'transparent' }}
renderTabBar={() => <ScrollableTab style={{ backgroundColor: color.white, borderWidth: 0 }} />}
locked
>
{MultipleMockData.map((item, index) => (
<Tab
key={index + item.tabName}
textStyle={[theme.description]}
activeTextStyle={[theme.description, theme.textWhite]}
tabStyle={{ backgroundColor: color.white }}
activeTabStyle={{
backgroundColor: color.primary,
borderRadius: 100,
margin: 10,
}}
heading={item.tabName}
>
<FlatList
contentContainerStyle={{ paddingBottom: isIphoneX() ? 90 : 55 }}
data={item.timer}
data={MultipleMockData[0].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} />}
// 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
transparent
......@@ -511,7 +267,7 @@ export default class TimerScreen extends Component {
</ScrollView>
</View>
</Modal>
{this.renderTimerFab()}
{/* {this.renderTimerFab()} */}
</>
);
}
......
......@@ -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 logo from '../../assets/images/logo2.png';
import { width } from '../../constants/Layout';
import app from '../../firebase';
export default class AuthLoadingScreen extends Component {
static navigationOptions = {
......@@ -10,15 +11,16 @@ export default class AuthLoadingScreen extends Component {
};
state = {
isShowImg: true,
authentication: null,
};
performTimeConsumingTask = async () => {
return new Promise(resolve =>
setTimeout(() => {
resolve('loadingCompleted');
}, 1700)
);
};
// performTimeConsumingTask = async () => {
// return new Promise(resolve =>
// setTimeout(() => {
// resolve('loadingCompleted');
// }, 200)
// );
// };
showLogoThenIndicator = () => {
setTimeout(() => {
......@@ -32,15 +34,28 @@ export default class AuthLoadingScreen extends Component {
// Preload data using AsyncStorage
const alreadyLaunched = await AsyncStorage.getItem('alreadyLaunched');
const RememberedLogin = await AsyncStorage.getItem('RememberedLogin');
const loading = await this.performTimeConsumingTask();
if (loading) {
RememberedLogin
? this.props.navigation.navigate('Main')
: this.props.navigation.navigate(alreadyLaunched ? 'Login' : 'Onboarding');
// console.log(alreadyLaunched, RememberedLogin);
// const loading = await this.performTimeConsumingTask();
// if (loading) {
app.auth().onAuthStateChanged(user => {
if (user) {
// 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() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
......
......@@ -4,6 +4,7 @@ import { theme, color } from '../../constants/Styles';
import AsyncStorage from '@react-native-community/async-storage';
import LoginForm from '../../components/Form/LoginForm';
import { KeyboardAvoidingView, View } from 'react-native';
import app from '../../firebase';
export default class LoginScreen extends Component {
static navigationOptions = {
......@@ -16,30 +17,41 @@ export default class LoginScreen extends Component {
passVisible: false,
};
async success() {
console.log('call success function');
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('SmartMeter');
}
submit = values => {
if (values.username == 'test' && values.password == 'password') {
console.log('Login Success!', values);
handleSignIn = async values => {
const { username, password } = values;
try {
await app.auth().signInWithEmailAndPassword(username, password);
this.success();
} else if (values.username == 'test') {
alert('Wrong password! \n ==> password');
} else {
alert('Wrong username & password! \n ==> (test, password)');
} catch (error) {
alert(error);
}
};
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() {
return (
<KeyboardAvoidingView style={theme.introContainer}>
<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]}>
<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