File size: 4,604 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'

export default function Questions({no,name,qlist,Checked,setChecked,qstate,setqstate,mode}) {

  useEffect(() => {

   let strs=localStorage.getItem('Checked'+`${no}`);
   if (strs==null) return;
    // let strs=localStorage.getItem('qstate');
    // localStorage.setItem('Checked', "");
    // localStorage.setItem('qstate', "");
    let item1=[],item2=[];

    // for(let i=0;i<strs.length;i++)
    // {
    //    if (strs[i]!=','&&strs[i]!='/'&&strs[i]!='"'&&strs[i]!='['&&strs[i]!=']'&&(strs[i]<'a'||strs[i]>'z')) item2.push(strs[i]);
    // }
    for(let i=0;i<strs.length;i++)
    {
      // let iop = parseInt(strs[i] + strs[i+1]);

       if (strs[i]==='+') { item2.push((strs[i] + strs[i+1] + strs[i+2])); i+=3;}
else if (strs[i]!=',' && strs[i]!='/' &&  strs[i]!='"' && strs[i]!='['&&strs[i]!=']' && (strs[i]<'a'||strs[i]>'z')&& strs[i]!="\\"&& strs[i]!='+' && strs[i]!='0' ) {item2.push(strs[i]);}
    }

    setChecked(item2);
    console.log(item2);
    localStorage.setItem('Checked'+`${no}`, JSON.stringify(item2));
    // localStorage.setItem('qstate', JSON.stringify(item2));
  }, []);

    let qq = qlist;
    function refreshPage() {
      window.location.reload();
    }

const handlechange = (id) => {

     if (checkID(id)===true) 
     {
        const newList = Checked.filter((idt) => idt !== id);
        setChecked(newList);

   localStorage.setItem('Checked'+`${no}`, JSON.stringify(newList));
   localStorage.setItem('qstate', JSON.stringify(newList));
 
        // const newList1 = qstate.filter((idt) => idt !== id);
        // setqstate(newList1);

    }
     else {
        // setqstate([...qstate,id]);
        setChecked([...Checked,id]);
        localStorage.setItem('Checked'+`${no}`, JSON.stringify(Checked+id));
     }   
     
// setChecked(Checked);
// window.location.reload();
}
// console.log(Checked,'2');

let checkID  = (ele) =>
 {
    if (Checked==null) return false;
   
    for(let i=0;i<Checked.length;i++)
       {
          if (ele==Checked[i]) return true;
       }
       return false;
}


const handleID = (str) => {
  
 let ans =  str.split('');
 ans.reverse();
  ans.pop(); 
  ans.reverse();
  ans.join('');
  
  return ans;
}
// let classNamer ;
// mode=="dark" ? classNamer = "bg-blue-100"  : classNamer = "mb-10";

return (
   <div className = {"mb-20"}>
    
    {/* {console.log ( mode == "dark" ? " bg-cyan-500 " : null )} */}

    <div className='flex justify-center mt-24 ' >
        <img className='w-10 h-10' src="Sparkle.png"></img>
      <h1 className='text-4xl mb-3' >{name}  Problems</h1>
    </div>
    <div className='flex justify-center mt-4'>
    <Link className='pr-2 text-teal-600' to="/"> Topics </Link>
    <p>  /  { name}</p>
     </div>

<div  className='flex text-center justify-center '>
<table className='   w-screen mt-20 ml-56  mr-56  '>
  <tr className='  text-amber-50 bg-fuchsia-700  text-center'>
    <th className=' border-1 font-normal  text-center p-3 w-10'>ID</th>
    <th className=' border-1 font-normal text-center p-3 '>Question(s)</th>
    <th className='border-1 font-normal text-center p-3 w-36'>Status</th>
    <th className='border-1 font-normal text-center p-3 w-20'>Done</th>
  </tr>
{
 
   
    
qq.map((ele)=>{
        {
                return (          
    <tr className = { checkID(ele.ID)==true?"bg-green-400":ele.ID%2===0?"bg-cyan-100":"none"  }>
                    <td  className=' text-md  text-sky-700 font-medium   border-2 p-3 w-10'>
                    
                      { ele.ID[0]=='+'? handleID(ele.ID) : ele.ID }
                    
                    </td>
                    <td  className='text-md text-left text-sky-700 font-medium   border-2 p-3'><Link target="_blank" to={ele.link}>{ele.Q}</Link></td>
                    <td  className='text-md  text-sky-700 font-medium text-center  border-2 w-36'>
                        {
        checkID(ele.ID)===false ? <img className='w-5 h-5' src="https://th.bing.com/th/id/OIP.2Ef1V0Yr3Lv_CZLcXBBt3gHaHa?pid=ImgDet&rs=1"></img> :
        <img className='w-5 h-5' src="https://cdn.pixabay.com/photo/2012/04/24/16/22/check-40319_960_720.png"></img> 
                        }
                        </td>
                    <td  className='text-md  text-sky-700 font-medium   border-2 p-3 w-20'>
<input   type="checkbox"  onChange={()=>{handlechange(ele.ID)}} checked={checkID(ele.ID)}/>
                      </td>
                  </tr>
                )               
                }
}
)
}
</table>
</div>
    </div>
  )
}