-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnote_handlesoinSelected
72 lines (66 loc) · 2.68 KB
/
note_handlesoinSelected
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
const handleCoinSelected = (e:any) =>{
const coin = e.target.value;
const selected = e.target.checked;
if(selected===true){
if(coinCount===8){
setSearchPlaceholder('✅ Eight coins already selected!');
return
} else {
setSearchPlaceholder('🙋♂️ Select eight coins you want to follow')
let repeated:boolean=false;
selectedCoins.forEach((previousCoin)=>{
if(previousCoin===coin){
setSearchPlaceholder(`🤷♂️${coin} already added!`);
repeated = true;
return
}else{repeated=false}
})
if(repeated){
return
} else {
setCoinCount(prevNumber=>prevNumber+1)
setSelectedCoins((prevState: any)=>[...prevState,coin])
}
}
} else {
const filteredCoins = selectedCoins.filter((selectedCoin)=>{
return !(coin===selectedCoin);
})
setSelectedCoins(filteredCoins);
setCoinCount(prevNumber=>prevNumber-1)
setSearchPlaceholder('🙋♂️ Select eight coins you want to follow')
}
}
//////////////////////////////////////////////
const coin = e.target.value;
const selected = e.target.checked;
if(selected===true){
if(coinCount===8){
setSearchPlaceholder('✅ Eight coins already selected!');
return
} else {
setSearchPlaceholder(`🙋♂️ you have selected ${coinCount} coins`)
let repeated:boolean=false;
selectedCoins.forEach((previousCoin)=>{
if(previousCoin===coin){
setSearchPlaceholder(`🤷♂️${coin} already added!`);
repeated = true;
return
}else{repeated=false}
})
if(repeated){
return
} else {
setCoinCount(prevNumber=>prevNumber+1)
setSelectedCoins((prevState: any)=>[...prevState,coin])
}
}
} else {
const filteredCoins = selectedCoins.filter((selectedCoin)=>{
return !(coin===selectedCoin);
})
setSelectedCoins(filteredCoins);
setCoinCount(prevNumber=>prevNumber-1)
setSearchPlaceholder(`🙋♂️ you have selected ${coinCount} coins`)
}
}