-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSummary.js
123 lines (112 loc) · 3.94 KB
/
Summary.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
import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import {
Container, Header, List, ListItem, Text, Left, Body, Icon, Badge, Button,
Card, CardItem, Content, Right } from 'native-base';
import { getAllData } from './Storage';
import { getMonthInfo, beautifyDate } from './utils';
export default class Summary extends Component {
constructor() {
super();
const todaysDate = new Date();
this.state = {
allTasks: [],
info: getMonthInfo(todaysDate)
}
}
onPressReviewNavigate(date) {
const d = date.split('-');
const dateObj = new Date(Number(d[0]), Number(d[1]) - 1, Number(d[2]))
this.props.navigation.navigate("Review", { date: dateObj });
}
async componentDidMount() {
const tasks = await getAllData();
this.setState({ allTasks: tasks })
}
analyzeAndSortTasks = (tasks) => {
let allTasks = [ ...tasks ];
allTasks.forEach(task => {
const date = task.date.split('-');
task.d = new Date(Number(date[0]), Number(date[1]-1), Number(date[2]))
})
allTasks.sort((a, b) => b.d - a.d);
// console.log('all tasks in summary: ', tasks);
return allTasks;
}
render() {
const {info} = this.state;
const allTasks = this.analyzeAndSortTasks(this.state.allTasks);
return (
<Container>
<Content style={styles.content}>
<Header style={styles.header} androidStatusBarColor="#3F4674">
</Header>
<View style={{ padding: 20 }}>
<View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
<Text style={{ fontSize: 40, color: '#efefefaa' }}>SUMMARY</Text>
</View>
<View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', marginTop: 10 }}>
<Text style={{ fontSize: 36, color: '#efefef', fontWeight: 'bold' }}>{info.month} </Text>
<Text style={{ fontSize: 36, color: '#efefef' }}>| {info.year}</Text>
</View>
</View>
{allTasks.map(task =>
{
const { date, totalTasks, completedTasks, stars } = task;
let starColor = '#E74B3A';
if (stars >= 4) {
starColor = '#5DCB9A';
} else if (stars > 2.5) {
starColor = '#FCB323';
}
return (
<View style={styles.item} key={date}>
<View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between' }}>
<Badge style={{ marginRight: 10, display: 'flex', flexDirection: 'row', backgroundColor: starColor, alignItems: 'center' }}><Icon name='star' style={{ fontSize: 18, color: 'white' }}/><Text>{stars}</Text></Badge>
<View>
<Text style={{ color: '#efefef', fontWeight: 'bold', fontSize: 18 }}>{beautifyDate(date)}</Text>
<Text style={{ color: '#efefef', fontSize: 12 }}>{`${completedTasks} of ${totalTasks} tasks completed`}</Text>
</View>
<Right>
<Button transparent onPress={() => this.onPressReviewNavigate(date)}>
<Icon name='arrow-forward' />
</Button>
</Right>
</View>
</View>
)
}
)}
</Content>
</Container>
)
}
}
const styles = StyleSheet.create({
item: {
backgroundColor: '#3F4674',
height: 60,
color: '#efefef',
padding: 10,
display: 'flex',
flexDirection: 'row',
alignItems: 'center', // #5C89C3
justifyContent: 'space-between',
borderRadius: 10,
marginTop: 10,
},
header: {
backgroundColor: '#ffffff',
display: 'none'
},
content: {
padding: '5%',
backgroundColor: '#393D5E',
color: '#efefef'
},
cardItem: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'flex-start',
}
})