diff options
| author | Nidboj132 <28981031+Nidboj132@users.noreply.github.com> | 2023-09-22 22:56:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-22 22:56:11 +0200 |
| commit | 93e2c912b50e5a8a5dc4048568cafdfed606e93e (patch) | |
| tree | 0b5f3e805120e9f98aa509d39c1c04ef78bc5e95 /frontend/src/components/sidebar.js | |
| parent | docs: update search response (#77) (diff) | |
| download | lphub-93e2c912b50e5a8a5dc4048568cafdfed606e93e.tar.gz lphub-93e2c912b50e5a8a5dc4048568cafdfed606e93e.tar.bz2 lphub-93e2c912b50e5a8a5dc4048568cafdfed606e93e.zip | |
feat: map search (#78)
Former-commit-id: 660e8bfcde4b850abb3820e209af3def2353fd51
Diffstat (limited to 'frontend/src/components/sidebar.js')
| -rw-r--r-- | frontend/src/components/sidebar.js | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/frontend/src/components/sidebar.js b/frontend/src/components/sidebar.js index 77800bd..d9b8012 100644 --- a/frontend/src/components/sidebar.js +++ b/frontend/src/components/sidebar.js | |||
| @@ -91,9 +91,17 @@ React.useEffect(()=>{ | |||
| 91 | if(location.pathname.includes("rules")){SidebarClick(9)} | 91 | if(location.pathname.includes("rules")){SidebarClick(9)} |
| 92 | if(location.pathname.includes("about")){SidebarClick(10)} | 92 | if(location.pathname.includes("about")){SidebarClick(10)} |
| 93 | 93 | ||
| 94 | // console.log(location.pathname) | ||
| 95 | // eslint-disable-next-line react-hooks/exhaustive-deps | 94 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 96 | }, [location]) | 95 | }, [location.pathname]) |
| 96 | |||
| 97 | const [search,setSearch] = React.useState(null) | ||
| 98 | const [searchData,setSearchData] = React.useState(null) | ||
| 99 | React.useEffect(()=>{ | ||
| 100 | fetch(`https://lp.ardapektezol.com/api/v1/search?q=${search}`) | ||
| 101 | .then(r=>r.json()) | ||
| 102 | .then(d=>setSearchData(d.data)) | ||
| 103 | |||
| 104 | }, [search]) | ||
| 97 | 105 | ||
| 98 | 106 | ||
| 99 | return ( | 107 | return ( |
| @@ -151,7 +159,27 @@ return ( | |||
| 151 | </div> | 159 | </div> |
| 152 | </div> | 160 | </div> |
| 153 | <div> | 161 | <div> |
| 154 | <input type="text" id='searchbar' placeholder='Search for map or a player...'/> | 162 | <input type="text" id='searchbar' placeholder='Search for map or a player...' onChange={()=>setSearch(document.querySelector("#searchbar").value)}/> |
| 163 | |||
| 164 | <div id='search-data'> | ||
| 165 | |||
| 166 | {searchData!==null?searchData.maps.map((q,index)=>( | ||
| 167 | <Link to={`/maps/${q.id}`} className='search-map' key={index}> | ||
| 168 | <span>{q.game}</span> | ||
| 169 | <span>{q.chapter}</span> | ||
| 170 | <span>{q.map}</span> | ||
| 171 | </Link> | ||
| 172 | )):""} | ||
| 173 | {searchData!==null?searchData.players.map((q,index)=> | ||
| 174 | ( | ||
| 175 | <Link className='search-player' key={index}> | ||
| 176 | <img src={q.avatar_link} alt='pfp'></img> | ||
| 177 | <span style={{fontSize:`${36 - q.user_name.length * 0.8}px`}}>{q.user_name}</span> | ||
| 178 | </Link> | ||
| 179 | |||
| 180 | )):""} | ||
| 181 | |||
| 182 | </div> | ||
| 155 | </div> | 183 | </div> |
| 156 | </div> | 184 | </div> |
| 157 | ) | 185 | ) |