-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
99 lines (83 loc) · 2.25 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
import { StyleSheet, Platform, Text, View, Button, SafeAreaView, TouchableOpacity } from 'react-native';
import { useEffect, useState } from 'react';
import Header from './src/components/Header/Header';
import Time from './src/components/Time/Time';
import { Audio } from "expo-av";
const colors = ["cyan", "yellow", "green"]
export default function App() {
const [isWorking, setIsWorking] = useState(false);
const [time, setTime] = useState(25 * 60);
const [currentTime, setCurrentTime] = useState("POMO" | "SHORT" | "BREAK")
const [isActive, setIsActive] = useState(false);
useEffect(() => {
let interval = null;
if (isActive) {
//run timer
interval = setInterval( ()=> {
setTime(time-1);
}, 10)
}else{
//clear interval
clearInterval(interval);
}
if (time ===0){
setIsActive(false);
setIsWorking((prev) => !prev);
setTime(isWorking ? 300 : 1500);
}
return () => clearInterval(interval);
}, [isActive, time])
function handleStartStop() {
playSound();
setIsActive(!isActive);
}
async function playSound() {
const { sound } = await Audio.Sound.createAsync(
require("./assets/click.mp3")
);
await sound.playAsync();
}
return (
<SafeAreaView
style={[styles.container, { backgroundColor: colors[currentTime] }]}
>
<View style={styles.view}>
<Text style={styles.text}>TaskTime</Text>
<Header
currentTime={currentTime}
setCurrentTime={setCurrentTime}
setTime={setTime}
/>
<Time time={time} />
<TouchableOpacity style={styles.button} onPress={handleStartStop}>
<Text style={styles.textButton}> {isActive ? "STOP" : "STAR"} </Text>
</TouchableOpacity>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
text: {
fontSize: 40,
fontWeight: "bold"
},
view: {
flex: 1,
paddingHorizontal: 15,
paddingTop: Platform.OS === "android" && 30,
},
button: {
backgroundColor: "#333333",
padding: 15,
marginTop: 15,
borderRadius: 15,
alignItems: "center",
},
textButton: {
color: "white",
fontWeight: "bold",
}
});