-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
139 lines (137 loc) · 2.98 KB
/
App.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import * as React from 'react';
import {
Text,
View,
StyleSheet,
TextInput,
TouchableOpacity,
ScrollView
} from 'react-native';
import Constants from 'expo-constants';
import Note from './components/Note';
import db from './config'
export default class App extends React.Component {
constructor() {
super();
this.state = {
noteArr: [{ note: 'React-Native', date: '13-Jul-2021' }],
noteText: '',
};
}
markDone = (index) => {
const node =db.ref('tasks').child(this.state.noteArr[index].id)
node.remove();
this.state.noteArr.splice(index);
};
componentDidMount(){
const tasks=db.ref('tasks');
tasks.on('value',(data)=>{
const todos=data.val();
const taskList=[];
for(var id in todos){
taskList.push({id,...todos[id]})
}
this.setState({noteArr:taskList})
})
}
addtask = () => {
const tasks= db.ref('tasks');
var d = new Date();
const monthName = [
'Jan',
'Feb',
'Mar',
'Apr',
'Jun',
'July',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
];
if (this.state.noteText) {
const newTask={
note: this.state.noteText,
date:
d.getDate() + ' ' + monthName[d.getMonth()-1] + ' ' + d.getFullYear(),
}
tasks.push(newTask)
this.setState({ noteText: '' });
}
};
render() {
var notes = this.state.noteArr.map((item, index) => {
return (
<Note
task={item}
markDone={() => {
this.markDone(index);
}}
/>
);
});
return (
<View style={styles.container}>
<View style={styles.header}>
<Text style={{ fontSize: 20 }}>Keep It</Text>
</View>
<ScrollView style={styles.scroll}>{notes}</ScrollView>
<View style={styles.bottom}>
<TextInput
placeholder="Enter Task"
style={styles.inputText}
onChangeText={(text) => {
this.setState({ noteText: text });
}}
value={this.state.noteText}
/>
<TouchableOpacity style={styles.inputButton} onPress={this.addtask}>
<Text style={{ fontSize: 20 }}>+</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: Constants.statusBarHeight,
},
header: {
backgroundColor: 'gold',
height: 70,
justifyContent: 'center',
alignItems: 'center',
borderBottomWidth: 3,
borderBottomColor: 'grey',
},
bottom: {
position: 'absolute',
left: 0,
bottom: 0,
right: 0,
borderTopColor: 'gold',
borderTopWidth: 2,
},
inputText: {
padding: 20,
outline: 'none',
},
inputButton: {
position: 'absolute',
bottom: 10,
right: 20,
height: 40,
width: 40,
backgroundColor: 'gold',
justifyContent: 'center',
alignItems: 'center',
borderRadius: 50,
},
scroll:{
flex:1,
marginBottom:70
}
});