-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.jsx
More file actions
161 lines (121 loc) · 3.76 KB
/
Copy pathtimer.jsx
File metadata and controls
161 lines (121 loc) · 3.76 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// @flow
/* REACT */
import React, { Component } from 'react';
import { AppState, Text, View } from 'react-native';
/* MODULES */
import { observer } from 'mobx-react';
import moment from 'moment';
import * as Animatable from 'react-native-animatable';
/* CONFIGS */
import DATE_CONFIG from '/config/date.config.js';
/* STYLES */
import styles from './styles.js';
/* TYPES */
import type { _t_appStore } from '/store/types';
import type { _t_timerTabStore } from '/types';
@observer
export default class Timer extends Component {
// ================
// ===== FLOW =====
// ================
props: {
appStore: _t_appStore,
timerTabStore: _t_timerTabStore,
};
_appState: string;
// ===========================
// ===== CLASS FUNCTIONS =====
// ===========================
constructor(props: Object): void {
super(props);
this._appState = 'active';
this._handleAppStateChange = this._handleAppStateChange.bind(this);
}
componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}
// ============================
// ===== CUSTOM FUNCTIONS =====
// ============================
/**
* Handle when app become active
*
* @param {string} nextAppState - next app state (inactive | background | active)
*/
_handleAppStateChange(nextAppState: string): void {
if (this._appState.match(/inactive|background/) && (nextAppState === 'active')) {
this.props.timerTabStore.onAppStart();
}
if (this._appState.match(/active/) && (nextAppState === 'inactive' || nextAppState === 'background')) {
this.props.timerTabStore.onChangeStateToBackground();
}
this._appState = nextAppState;
}
// ==================
// ===== RENDER =====
// ==================
render() {
const {
timerHours,
timerMinutes,
timerSeconds,
clockInTime,
isTimerActivated
} = this.props.timerTabStore;
return (
<View>
<View style={styles.timerTitle} >
<View style={styles.clockInRowCenterBlock} >
<Text style={styles.timerDate} >
{moment().format(DATE_CONFIG.timerDate)}
</Text>
</View>
<View style={styles.timerBlockStatusWrapper} >
{
<Text style={styles.timerBlockStatus} >
{
this.props.timerTabStore.isTimerRunning
? `Break time ${this.props.timerTabStore.getBreakTime}`
: 'On Break'
}
</Text>
}
</View>
</View>
<View style={styles.timerWrapper} >
<Text style={styles.timerValue} >
{timerHours < 10 ? '0' + timerHours : timerHours}
{':'}
{timerMinutes < 10 ? '0' + timerMinutes : timerMinutes}
</Text>
<Text style={styles.secondsText} >
{timerSeconds < 10 ? '0' + timerSeconds : timerSeconds}
</Text>
</View>
<View style={styles.timerLabelsWrapper} >
<View style={styles.timerLabelsBlockHours} >
<Text style={styles.timerLabel} >
hrs
</Text>
</View>
<View style={styles.timerLabelsBlock} >
<Text style={styles.timerLabel} >
mins
</Text>
</View>
</View>
<View style={styles.timerClockedWrapper} >
{
isTimerActivated &&
<Animatable.Text animation="flipInX" style={styles.timerClockedTitle} >
Clocked in at {moment(clockInTime).format(DATE_CONFIG.timeOfDay)}
</Animatable.Text>
}
</View>
</View>
);
}
}