diff options
| author | Nidboj132 <lol2s@vp.plm> | 2023-07-12 17:58:04 +0200 |
|---|---|---|
| committer | Nidboj132 <lol2s@vp.plm> | 2023-07-12 17:58:04 +0200 |
| commit | 26cdd0d363b1e279b14f7c5c3c12bb7d5e6d87d8 (patch) | |
| tree | 548bd55dca7c3b1ae3ef86036b2eef3ec361b455 /frontend/src/components/pages/summary.js | |
| parent | login (diff) | |
| download | lphub-26cdd0d363b1e279b14f7c5c3c12bb7d5e6d87d8.tar.gz lphub-26cdd0d363b1e279b14f7c5c3c12bb7d5e6d87d8.tar.bz2 lphub-26cdd0d363b1e279b14f7c5c3c12bb7d5e6d87d8.zip | |
summary
Diffstat (limited to '')
| -rw-r--r-- | frontend/src/components/pages/summary.js | 225 |
1 files changed, 225 insertions, 0 deletions
diff --git a/frontend/src/components/pages/summary.js b/frontend/src/components/pages/summary.js new file mode 100644 index 0000000..c628dd4 --- /dev/null +++ b/frontend/src/components/pages/summary.js | |||
| @@ -0,0 +1,225 @@ | |||
| 1 | import React from 'react'; | ||
| 2 | import { useLocation } from "react-router-dom"; | ||
| 3 | import ReactMarkdown from 'react-markdown' | ||
| 4 | |||
| 5 | import "./summary.css"; | ||
| 6 | |||
| 7 | import img4 from "../../imgs/4.png" | ||
| 8 | import img5 from "../../imgs/5.png" | ||
| 9 | import img6 from "../../imgs/6.png" | ||
| 10 | import Modview from "./summary_modview.js" | ||
| 11 | |||
| 12 | export default function Summary(prop) { | ||
| 13 | const {token,mod} = prop | ||
| 14 | const fakedata={} //for debug | ||
| 15 | |||
| 16 | const location = useLocation() | ||
| 17 | |||
| 18 | //fetching data | ||
| 19 | const [data, setData] = React.useState(null); | ||
| 20 | React.useEffect(() => { | ||
| 21 | fetch(`/api/v1/maps/${location.pathname.split('/')[2]}/summary`) | ||
| 22 | .then(r => r.json()) | ||
| 23 | .then(d => { | ||
| 24 | if(Object.keys(fakedata).length!==0){setData(fakedata)} | ||
| 25 | else{setData(d.data)} | ||
| 26 | if(d.data.summary.routes.length===0){d.data.summary.routes[0]={"category": "","history": {"score_count": 0,},"rating": 0,"description": "","showcase": ""}} | ||
| 27 | }) | ||
| 28 | // eslint-disable-next-line | ||
| 29 | }, []); | ||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | |||
| 35 | const [navState, setNavState] = React.useState(0); // eslint-disable-next-line | ||
| 36 | React.useEffect(() => {NavClick();}, [[],navState]); | ||
| 37 | |||
| 38 | function NavClick() { | ||
| 39 | if(data!==null){ | ||
| 40 | const btn = document.querySelectorAll("#section2 button.nav-button"); | ||
| 41 | btn.forEach((e) => {e.style.backgroundColor = "#2b2e46"}); | ||
| 42 | btn[navState].style.backgroundColor = "#202232"; | ||
| 43 | }} | ||
| 44 | |||
| 45 | |||
| 46 | const [catState, setCatState] = React.useState(1); // eslint-disable-next-line | ||
| 47 | React.useEffect(() => {CatClick();}, [[],catState]); | ||
| 48 | |||
| 49 | function CatClick() { | ||
| 50 | if(data!==null){ | ||
| 51 | const btn = document.querySelectorAll("#section3 #category span button"); | ||
| 52 | btn.forEach((e) => {e.style.backgroundColor = "#2b2e46"}); | ||
| 53 | btn[catState-1].style.backgroundColor = "#202232"; | ||
| 54 | }} | ||
| 55 | React.useEffect(()=>{ | ||
| 56 | if(data!==null && data.summary.routes.filter(e=>e.category.id===catState).length!==0){ | ||
| 57 | selectRun(0,catState)} // eslint-disable-next-line | ||
| 58 | },[catState,data]) | ||
| 59 | |||
| 60 | |||
| 61 | const [hisState, setHisState] = React.useState(0); // eslint-disable-next-line | ||
| 62 | React.useEffect(() => {HisClick();}, [[],hisState]); | ||
| 63 | |||
| 64 | function HisClick() { | ||
| 65 | if(data!==null){ | ||
| 66 | const btn = document.querySelectorAll("#section3 #history span button"); | ||
| 67 | btn.forEach((e) => {e.style.backgroundColor = "#2b2e46"}); | ||
| 68 | btn[hisState].style.backgroundColor = "#202232"; | ||
| 69 | }} | ||
| 70 | |||
| 71 | const [selectedRun,setSelectedRun] = React.useState(0) | ||
| 72 | |||
| 73 | function selectRun(x,y){ | ||
| 74 | let r = document.querySelectorAll("button.record") | ||
| 75 | r.forEach(e=>e.style.backgroundColor="#2b2e46") | ||
| 76 | r[x].style.backgroundColor="#161723" | ||
| 77 | |||
| 78 | |||
| 79 | if(data!==null && data.summary.routes.length!==0 && data.summary.routes.length!==0){ | ||
| 80 | if(y===2){x+=data.summary.routes.filter(e=>e.category.id<2).length} | ||
| 81 | if(y===3){x+=data.summary.routes.filter(e=>e.category.id<3).length} | ||
| 82 | if(y===4){x+=data.summary.routes.filter(e=>e.category.id<4).length} | ||
| 83 | setSelectedRun(x) | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | const [vid,setVid] = React.useState("") | ||
| 88 | React.useEffect(()=>{ | ||
| 89 | if(data!==null){ | ||
| 90 | let showcase = data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].showcase | ||
| 91 | showcase.length>6 ? setVid("https://www.youtube.com/embed/"+YouTubeGetID(showcase)) | ||
| 92 | : setVid("") | ||
| 93 | } // eslint-disable-next-line | ||
| 94 | },[[],selectedRun]) | ||
| 95 | |||
| 96 | function YouTubeGetID(url){ | ||
| 97 | url = url.split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/); | ||
| 98 | return (url[2] !== undefined) ? url[2].split(/[^0-9a-z_]/i)[0] : url[0]; | ||
| 99 | } | ||
| 100 | |||
| 101 | if(data!==null){ | ||
| 102 | return ( | ||
| 103 | <> | ||
| 104 | {token!==null?mod===true?<Modview selectedRun={selectedRun} data={data} token={token}/>:"":""} | ||
| 105 | |||
| 106 | <div id='background-image'> | ||
| 107 | <img src={data.map.image} alt="" /> | ||
| 108 | </div> | ||
| 109 | <main> | ||
| 110 | <section id='section1'> | ||
| 111 | <div> | ||
| 112 | <button className='nav-button'><i className='triangle'></i><span>{data.map.game_name}</span></button> | ||
| 113 | <button className='nav-button'><i className='triangle'></i><span>{data.map.chapter_name}</span></button> | ||
| 114 | <br/><span><b>{data.map.map_name}</b></span> | ||
| 115 | </div> | ||
| 116 | |||
| 117 | |||
| 118 | </section> | ||
| 119 | |||
| 120 | <section id='section2'> | ||
| 121 | <button className='nav-button' onClick={()=>setNavState(0)}><img src={img4} alt="" /><span>Summary</span></button> | ||
| 122 | <button className='nav-button' onClick={()=>setNavState(1)}><img src={img5} alt="" /><span>Leaderboards</span></button> | ||
| 123 | <button className='nav-button' onClick={()=>setNavState(2)}><img src={img6} alt="" /><span>Discussions</span></button> | ||
| 124 | </section> | ||
| 125 | |||
| 126 | <section id='section3'> | ||
| 127 | <div id='category' | ||
| 128 | style={data.map.image===""?{backgroundColor:"#202232"}:{}}> | ||
| 129 | <img src={data.map.image} alt="" id='category-image'></img> | ||
| 130 | <p><span className='portal-count'>{data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].history.score_count}</span> | ||
| 131 | {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].history.score_count === 1 ? ` portal` : ` portals` }</p> | ||
| 132 | <span> | ||
| 133 | <button onClick={()=>setCatState(1)}>CM</button> | ||
| 134 | <button onClick={()=>setCatState(2)}>NoSLA</button> | ||
| 135 | {data.map.is_coop?<button onClick={()=>setCatState(3)}>SLA</button> | ||
| 136 | :<button onClick={()=>setCatState(3)}>Inbounds SLA</button>} | ||
| 137 | <button onClick={()=>setCatState(4)}>Any%</button> | ||
| 138 | </span> | ||
| 139 | |||
| 140 | </div> | ||
| 141 | |||
| 142 | <div id='history'> | ||
| 143 | <div> | ||
| 144 | <div className='record-top'> | ||
| 145 | <span>Date</span> | ||
| 146 | <span>Record</span> | ||
| 147 | <span>First completion</span> | ||
| 148 | </div> | ||
| 149 | <hr/> | ||
| 150 | <div id='records'> | ||
| 151 | |||
| 152 | {data.summary.routes | ||
| 153 | .sort((a, b) => a.history.score_count - b.history.score_count) | ||
| 154 | .filter(e=>e.category.id===catState) | ||
| 155 | .map((r, index) => ( | ||
| 156 | <button className='record' key={index} onClick={()=>{ | ||
| 157 | selectRun(index,r.category.id); | ||
| 158 | }}> | ||
| 159 | <span>{ new Date(r.history.date).toLocaleDateString( | ||
| 160 | "en-US", { month: 'long', day: 'numeric', year: 'numeric' } | ||
| 161 | )}</span> | ||
| 162 | <span>{r.history.score_count}</span> | ||
| 163 | <span>{r.history.runner_name}</span> | ||
| 164 | </button> | ||
| 165 | ))} | ||
| 166 | |||
| 167 | </div> | ||
| 168 | </div> | ||
| 169 | <span> | ||
| 170 | <button onClick={()=>setHisState(0)}>List</button> | ||
| 171 | <button onClick={()=>setHisState(1)}>Graph</button> | ||
| 172 | </span> | ||
| 173 | </div> | ||
| 174 | |||
| 175 | </section> | ||
| 176 | |||
| 177 | <section id='section4'> | ||
| 178 | <div id='difficulty'> | ||
| 179 | <span>Difficulty</span> | ||
| 180 | {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].rating === 0 ? (<span style={{color:"lime"}}>Very easy</span>):null} | ||
| 181 | {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].rating === 1 ? (<span style={{color:"green"}}>Easy</span>):null} | ||
| 182 | {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].rating === 2 ? (<span style={{color:"yellow"}}>Medium</span>):null} | ||
| 183 | {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].rating === 3 ? (<span style={{color:"orange"}}>Hard</span>):null} | ||
| 184 | {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].rating === 4 ? (<span style={{color:"red"}}>Very hard</span>):null} | ||
| 185 | <div> | ||
| 186 | {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].rating === 0 ? (<div className='difficulty-rating' style={{backgroundColor:"lime"}}></div>) : (<div className='difficulty-rating'></div>)} | ||
| 187 | {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].rating === 1 ? (<div className='difficulty-rating' style={{backgroundColor:"green"}}></div>) : (<div className='difficulty-rating'></div>)} | ||
| 188 | {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].rating === 2 ? (<div className='difficulty-rating' style={{backgroundColor:"yellow"}}></div>) : (<div className='difficulty-rating'></div>)} | ||
| 189 | {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].rating === 3 ? (<div className='difficulty-rating' style={{backgroundColor:"orange"}}></div>) : (<div className='difficulty-rating'></div>)} | ||
| 190 | {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].rating === 4 ? (<div className='difficulty-rating' style={{backgroundColor:"red"}}></div>) : (<div className='difficulty-rating'></div>)} | ||
| 191 | </div> | ||
| 192 | </div> | ||
| 193 | <div id='count'> | ||
| 194 | <span>Completion count</span> | ||
| 195 | <div>6275</div> | ||
| 196 | </div> | ||
| 197 | </section> | ||
| 198 | |||
| 199 | <section id='section5'> | ||
| 200 | <div id='description'> | ||
| 201 | {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].showcase!=="" ? | ||
| 202 | <iframe title='Showcase video' src={vid}> </iframe> | ||
| 203 | : ""} | ||
| 204 | <h3>Route description</h3> | ||
| 205 | <span id='description-text'> | ||
| 206 | <ReactMarkdown> | ||
| 207 | {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].description} | ||
| 208 | </ReactMarkdown> | ||
| 209 | </span> | ||
| 210 | </div> | ||
| 211 | |||
| 212 | </section> | ||
| 213 | </main> | ||
| 214 | </> | ||
| 215 | ) | ||
| 216 | }else{ | ||
| 217 | return ( | ||
| 218 | <main></main> | ||
| 219 | ) | ||
| 220 | } | ||
| 221 | |||
| 222 | |||
| 223 | } | ||
| 224 | |||
| 225 | |||