@@ -3,14 +3,18 @@ import "./ScoreBoard.css"
3
3
import { useUser } from "../../hooks/useUser"
4
4
import { supabase } from "../../client"
5
5
6
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
7
+ import { faTrash , faStar } from '@fortawesome/free-solid-svg-icons' ;
8
+
9
+
6
10
function ScoreBoard ( ) {
7
11
const [ habits , setHabits ] = useState ( [ ] )
8
12
9
13
const userId = useUser ( )
10
14
11
15
const handleOnClick = ( ) => {
12
16
// console.log("clicked")
13
- const newHabit = { content : "" , value : 'neu' }
17
+ const newHabit = { content : "" , value : 'neu' , strikes : [ false , false , false , false , false , false , false ] }
14
18
//create an empty card for user input
15
19
setHabits ( [ ...habits , newHabit ] )
16
20
}
@@ -44,7 +48,7 @@ function ScoreBoard(){
44
48
45
49
// If the user has a habit record, update it
46
50
if ( habitData . length === 1 ) {
47
- console . log ( "updating habit record" ) ;
51
+ // console.log("updating habit record");
48
52
const { data, error } = await supabase
49
53
. from ( "habits" )
50
54
. update ( { habits } )
@@ -55,7 +59,7 @@ function ScoreBoard(){
55
59
return ;
56
60
}
57
61
58
- console . log ( "updated habit record:" , data ) ;
62
+ // console.log("updated habit record:", data);
59
63
}
60
64
// If the user does not have a habit record, create a new one
61
65
else {
@@ -68,7 +72,7 @@ function ScoreBoard(){
68
72
console . error ( error ) ;
69
73
return ;
70
74
}
71
- console . log ( "Created new habit record:" , data ) ;
75
+ // console.log("Created new habit record:", data);
72
76
}
73
77
}
74
78
@@ -105,25 +109,54 @@ function ScoreBoard(){
105
109
return ( ) => {
106
110
submitHabits ( userId , habits ) ;
107
111
} ;
108
- } , [ userId , habits ] ) ;
112
+ } , [ habits ] ) ;
113
+
114
+ const handleDelete = ( e ) => {
115
+ const updatedHabits = [ ...habits ] ;
116
+ // console.log(e.currentTarget.id); // You can access the id attribute now
117
+ updatedHabits . splice ( e . currentTarget . id , 1 ) ;
118
+ setHabits ( updatedHabits ) ;
119
+ }
109
120
121
+ const handleLight = ( e , index ) => {
122
+ const updatedHabits = [ ...habits ] ;
123
+ // console.log(e.currentTarget.id); // You can access the id attribute now
124
+ // console.log("overall index", index)
125
+ updatedHabits [ index ] . strikes [ e . currentTarget . id ] = ! updatedHabits [ index ] . strikes [ e . currentTarget . id ] ;
126
+ // console.log('updatedHabits[index].strikes[e.currentTarget.id]: ', updatedHabits[index].strikes[e.currentTarget.id]);
127
+ setHabits ( updatedHabits ) ;
128
+
129
+ // console.log("setup done")
130
+ }
131
+
110
132
return (
111
133
< div className = "scoreboard" >
112
134
< div className = "scoreboard__header" >
113
135
< span >
114
- < h2 > Scoreboard</ h2 >
136
+ < h2 > Habits Scoreboard & Tracker </ h2 >
115
137
</ span >
116
138
</ div >
117
139
< div className = "scoreboard__body" >
118
140
{
119
141
habits . map ( ( habit , index ) => {
120
142
return (
121
- < div className = "scoreboard-input" key = { index } >
143
+ < div key = { index } >
144
+ < div className = "scoreboard-input" key = { index + 'scoreboard' } >
122
145
< input
123
146
type = "text"
124
147
id = { index }
125
148
value = { habit . content }
126
149
onChange = { handleObjectiveChange }
150
+ style = { {
151
+ borderBottom :
152
+ habit . value === 'neg'
153
+ ? '1px solid #fbbf77'
154
+ : habit . value === 'pos'
155
+ ? '1px solid lightgreen'
156
+ : '1px solid #fff' ,
157
+ } }
158
+
159
+ //ff9e3d
127
160
>
128
161
</ input >
129
162
< select name = "score"
@@ -136,16 +169,64 @@ function ScoreBoard(){
136
169
< option value = "neg" > -</ option >
137
170
< option value = "neu" > =</ option >
138
171
</ select >
172
+
173
+ < FontAwesomeIcon
174
+ className = "scoreboard-delete"
175
+ id = { index }
176
+ onClick = { ( e ) => handleDelete ( e ) }
177
+ icon = { faTrash }
178
+ />
179
+
180
+ </ div >
181
+ { /* probably more generic code here later? */ }
182
+ { habit ?. value === 'neg' ? (
183
+ < div className = "checkbox-row" >
184
+ { habit . strikes ?. map ( ( strike , starIndex ) => {
185
+ return (
186
+ < div key = { starIndex + 'checkbox' } >
187
+ < FontAwesomeIcon
188
+ style = { {
189
+ color : strike === true ? 'orange' : 'white' ,
190
+ } }
191
+ icon = { faStar }
192
+ id = { starIndex }
193
+ onClick = { ( e ) => handleLight ( e , index ) }
194
+ />
195
+ </ div >
196
+ ) ;
197
+ } ) }
198
+ </ div >
199
+ ) : null }
200
+
201
+ { habit ?. value === 'pos' ? (
202
+ < div className = "checkbox-row" >
203
+ { habit . strikes ?. map ( ( strike , starIndex ) => {
204
+ return (
205
+ < div key = { starIndex + 'checkbox' } >
206
+ < FontAwesomeIcon
207
+ style = { {
208
+ color : strike === true ? 'lightgreen' : 'white' ,
209
+ } }
210
+ icon = { faStar }
211
+ id = { starIndex }
212
+ onClick = { ( e ) => handleLight ( e , index ) }
213
+ />
214
+ </ div >
215
+ ) ;
216
+ } ) }
217
+ </ div >
218
+ ) : null }
139
219
</ div >
140
220
)
141
221
}
142
222
)
143
223
}
144
224
</ div >
145
-
146
- < button onClick = { handleOnClick } > + </ button >
147
- < button onClick = { handleSubmit } > Submit </ button >
148
-
225
+
226
+ < div className = "scoreboard-btn" >
227
+ < button onClick = { handleOnClick } > + </ button >
228
+ { /* <button onClick={handleSubmit}> Submit </button> */ }
229
+ </ div >
149
230
</ div >
150
231
)
151
232
}
0 commit comments