-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
94 lines (84 loc) · 3.4 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import HomeView from "./views/HomeView";
import DeckView from "./views/DeckView";
import NewQuestionView from "./views/NewQuestionView";
import QuizView from "./views/QuizView";
import Ionics from 'react-native-vector-icons/Ionicons';
import {Alert, AsyncStorage, StyleSheet, View} from "react-native";
import RNDateTimePicker from "@react-native-community/datetimepicker";
import clearNotification from "./utils/notificationsHandler";
import registerForPushNotificationsAsync from "./utils/notificationsHandler";
const Stack = createStackNavigator();
interface AppState {
date: any,
showDate: boolean
mode: any
}
class App extends React.Component<any, AppState> {
state: AppState = {
date: new Date(),
showDate: false,
mode: 'time'
};
setDate(event: any, date: any) {
if (date !== undefined) {
if (this.state.mode === 'date') {
this.setState({date: date, showDate: true, mode: 'time'});
} else {
const dateToSave = new Date(this.state.date);
const dateWithHours = new Date(date);
dateToSave.setHours(dateWithHours.getHours());
dateToSave.setMinutes(dateWithHours.getMinutes());
AsyncStorage.setItem('date', JSON.stringify(dateToSave)).then(() => {
clearNotification();
registerForPushNotificationsAsync();
this.setState({date: date, showDate: false, mode: 'date'});
});
}
}
}
createAlert() {
Alert.alert(
'Set Notification',
'Set date and time for notification',
[
{text: 'Enter Date', onPress: () => this.setState({showDate: true, mode: 'date'})},
{text: 'Cancel'}
],
{cancelable: false},
);
}
render() {
return (
<NavigationContainer>
{
this.state.showDate && <RNDateTimePicker
style={{width: 200}}
mode={this.state.mode}
onChange={(event, date) => { this.setDate(event, date)}}
value={this.state.date}/>
}
<Stack.Navigator initialRouteName="FlashCard">
<Stack.Screen name="FlashCard" component={HomeView}
options={{headerRight: () => (
<View>
<Ionics onPress={() => this.createAlert()}
style={styles.settingsButton} name={'md-settings'} size={30} />
</View>
)}}/>
<Stack.Screen options={(option: any) => ({ title: option.route.params.deck.title })} name="Deck" component={DeckView} />
<Stack.Screen name="Add Card" component={NewQuestionView} />
<Stack.Screen name="Quiz" component={QuizView} />
</Stack.Navigator>
</NavigationContainer>
);
}
}
const styles = StyleSheet.create({
settingsButton: {
marginRight: 16
},
});
export default App;