Skip to content

Commit 5eab3bc

Browse files
updatedTodo
1 parent 12685b1 commit 5eab3bc

File tree

2 files changed

+68
-10
lines changed

2 files changed

+68
-10
lines changed

src/components/signUp.jsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { db } from './firebase'
33

44
function SignUp() {
55

6-
// const[arr] = useState(['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday',])
6+
const[arr] = useState(['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday',])
77

88
// useEffect(() => {
99
// const obj = {
@@ -12,7 +12,8 @@ function SignUp() {
1212
// Day: "",
1313
// Id: "",
1414
// status: false,
15-
// RemindMe: ""
15+
// RemindMe: "",
16+
// CreatedAt: "",
1617
// }
1718

1819
// arr.forEach(day => {
@@ -26,7 +27,7 @@ function SignUp() {
2627
// })
2728
// }
2829
// })
29-
// })
30+
// }, [])
3031

3132
return (
3233
<div>hello</div>

src/components/todo.jsx

+64-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useState } from "react"
1+
import { useEffect, useState } from "react"
22
import { db } from './firebase'
3-
// import SignUp from './signUp'
3+
import SignUp from './signUp'
44

55
function Todo() {
66

@@ -10,6 +10,44 @@ function Todo() {
1010
const[dis, setDis] = useState('')
1111
const[day, setDay] = useState('')
1212
const[time, setTime] = useState('')
13+
const[tod, setTod] = useState([]) //tod = today's list
14+
const[yesRem, setYRem] = useState([]) //yesRem = yesterday's remaining
15+
const[tom, setTom] = useState([]) //tomorrow's list
16+
const[cur, setCur] = useState({})
17+
18+
useEffect(() => {
19+
let yesIdx = ((idx-1)%arr.length + arr.length)%arr.length
20+
db.collection('user').doc(`${arr[yesIdx]}`).collection('tasks').get()
21+
.then(doc => {
22+
let yArr = []
23+
doc.forEach(document => {
24+
if(!document.data().status) yArr.push(document.data())
25+
})
26+
setYRem(yArr)
27+
})
28+
.catch(err => alert(err))
29+
30+
let todIdx = idx
31+
db.collection('user').doc(`${arr[todIdx]}`).collection('tasks').get()
32+
.then(doc => {
33+
let todArr = []
34+
doc.forEach(document => {
35+
todArr.push(document.data())
36+
})
37+
setTod(todArr)
38+
})
39+
.catch(err => alert(err))
40+
41+
let tomIdx = (idx+1)%arr.length
42+
db.collection('user').doc(`${arr[tomIdx]}`).collection('tasks').get()
43+
.then(doc => {
44+
let tomArr = []
45+
doc.forEach(document => {
46+
tomArr.push(document.data())
47+
})
48+
setTom(tomArr)
49+
})
50+
}, [cur])
1351

1452
const handleChange = (e)=> {
1553
e.preventDefault()
@@ -19,15 +57,17 @@ function Todo() {
1957
EventDisc: "",
2058
Day: "",
2159
status: false,
22-
RemindMe: ""
60+
RemindMe: "",
61+
CreatedAt: ""
2362
}
2463

2564
const obj2 = {
2665
EventName: name,
2766
EventDisc: dis,
2867
Day: day,
2968
status: false,
30-
RemindMe: time
69+
RemindMe: time,
70+
CreatedAt: new Date().getTime()
3171
}
3272

3373
let yesIdx = ((idx-2)%arr.length + arr.length)%arr.length
@@ -54,11 +94,14 @@ function Todo() {
5494
docRef.doc(`${el.id}`).update(obj2)
5595
}
5696
})
97+
setCur(obj2)
5798
if(flag === 0) alert("Only 4 todos are to be done in a day")
99+
else docRef.orderBy("CreatedAt", "asc")
58100
})
59101
})
60102
})
61103

104+
62105
const form = document.getElementById('form')
63106
form.reset()
64107
}
@@ -81,14 +124,14 @@ function Todo() {
81124
name="day"
82125
value={arr[idx%arr.length]}
83126
onClick={e => setDay(arr[idx%arr.length])}
84-
/>{arr[idx%arr.length]}
127+
/>Today ({arr[idx]})
85128

86129
<input
87130
type="radio"
88131
name="day"
89132
value={arr[(idx+1)%arr.length]}
90133
onClick={e => setDay(arr[(idx+1)%arr.length])}
91-
/>{arr[(idx+1)%arr.length]}
134+
/>Tomorrow ({arr[(idx+1)%arr.length]})
92135
</div>
93136
<div>
94137
<label>Remind me at</label>
@@ -102,8 +145,22 @@ function Todo() {
102145
<input type="submit" value="Submit"/>
103146
</div>
104147
</form>
148+
149+
<div>
150+
{yesRem.map(val => (<div>{JSON.stringify(val)}</div>))}
151+
</div>
152+
<br />
153+
<br />
154+
<div>
155+
{tod.map(val => (<div>{JSON.stringify(val)}</div>))}
156+
</div>
157+
<br />
158+
<br />
159+
<div>
160+
{tom.map(val => (<div>{JSON.stringify(val)}</div>))}
161+
</div>
162+
{/* <SignUp /> */}
105163
</div>
106-
// <SignUp />
107164
)
108165
}
109166

0 commit comments

Comments
 (0)