aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/pages/home.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/components/pages/home.js')
-rw-r--r--frontend/src/components/pages/home.js125
1 files changed, 97 insertions, 28 deletions
diff --git a/frontend/src/components/pages/home.js b/frontend/src/components/pages/home.js
index c1477ab..55e58a8 100644
--- a/frontend/src/components/pages/home.js
+++ b/frontend/src/components/pages/home.js
@@ -4,14 +4,45 @@ import { useLocation, Link } from "react-router-dom";
4import "./home.css" 4import "./home.css"
5import News from '../news'; 5import News from '../news';
6import Record from '../record'; 6import Record from '../record';
7import Login from '../login';
7 8
8export default function Homepage(prop) { 9export default function Homepage(prop) {
9 const {token, setToken} = prop 10 const { token, setToken } = prop
10 const [home, setHome] = React.useState(null); 11 const [home, setHome] = React.useState(null);
12 const [profile, setProfile] = React.useState(null);
13 const [loading, setLoading] = React.useState(true)
11 const location = useLocation(); 14 const location = useLocation();
12 15
16 const [isLoggedIn, setIsLoggedIn] = React.useState(false);
17 React.useEffect(() => {
18 try {
19 fetch(`https://lp.ardapektezol.com/api/v1/profile`, {
20 headers: {
21 'Content-Type': 'application/json',
22 Authorization: token
23 }
24 })
25 .then(r => r.json())
26 .then(d => setProfile(d.data))
27 .then(d => {
28 if (profile != null) {
29 setIsLoggedIn(true)
30 }
31 })
32 .then(d => {
33 setLoading(false)
34 })
35 } catch (error) {
36 console.log(error)
37 }
38
39 }, [token, profile]);
40
13 useEffect(() => { 41 useEffect(() => {
14 async function fetchMapImg() { 42 async function fetchMapImg() {
43 if (!isLoggedIn) {
44 return;
45 }
15 try { 46 try {
16 const response = await fetch("https://lp.ardapektezol.com/api/v1/games", { 47 const response = await fetch("https://lp.ardapektezol.com/api/v1/games", {
17 headers: { 48 headers: {
@@ -23,11 +54,11 @@ export default function Homepage(prop) {
23 54
24 const recommendedMapImg = document.querySelector("#recommendedMapImg"); 55 const recommendedMapImg = document.querySelector("#recommendedMapImg");
25 56
26 recommendedMapImg.src = `${data.data[0].image}` 57 recommendedMapImg.style.backgroundImage = `url(${data.data[0].image})`
27 58
28 const column1 = document.querySelector("#column1"); 59 const column1 = document.querySelector("#column1");
29 const column2 = document.querySelector("#column2"); 60 const column2 = document.querySelector("#column2");
30 61
31 column2.style.height = column1.clientHeight + "px"; 62 column2.style.height = column1.clientHeight + "px";
32 } catch (error) { 63 } catch (error) {
33 console.log(error) 64 console.log(error)
@@ -115,41 +146,57 @@ export default function Homepage(prop) {
115 }, 146 },
116 ] 147 ]
117 148
149 if (loading) {
150 return (
151 <main>
152 </main>
153 )
154 }
155
118 return ( 156 return (
119 <main> 157 <main>
120 <section style={{marginTop: "40px", userSelect: "none"}}> 158 <section style={{ userSelect: "none", display: "flex" }}>
121 <span style={{fontSize: "40px"}}>Welcome back,</span><br/> 159 <h1 style={{ marginTop: "53.6px", fontSize: "80px", marginBottom: "15px" }}>Home</h1>
122 <span><b style={{ fontSize: "96px", transform: "translateY(-20px)", display: "block"}}>Krzyhau</b></span> 160 {isLoggedIn ?
161 <div style={{ textAlign: "right", width: "100%", marginTop: "20px" }}>
162 <span style={{ fontSize: "25px" }}>Welcome back,</span><br />
163
164 <span><b style={{ fontSize: "80px", transform: "translateY(-20px)", display: "block" }}>Wolfboy248</b></span>
165 </div>
166 : null}
123 </section> 167 </section>
124 168
125 <div style={{display: "grid", gridTemplateColumns: "calc(50%) calc(50%)"}}> 169 <div style={{ display: "grid", gridTemplateColumns: "calc(50%) calc(50%)" }}>
126 <div id='column1' style={{ display: "flex", alignItems: "self-start", flexWrap: "wrap", alignContent: "start" }}> 170 <div id='column1' style={{ display: "flex", alignItems: "self-start", flexWrap: "wrap", alignContent: "start" }}>
127 {/* Column 1 */} 171 {/* Column 1 */}
172 {isLoggedIn ?
128 <section title="Your Profile" className='homepage-panel'> 173 <section title="Your Profile" className='homepage-panel'>
129 <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: "12px"}}> 174 <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: "12px" }}>
130 <div className='stats-div'> 175 <div className='stats-div'>
131 <span>Overall rank</span><br/> 176 <span>Overall rank</span><br />
132 <span><b>#69</b></span> 177 <span><b>{profile.rankings.overall.rank > 0 ? "#" + profile.rankings.overall.rank : "No rank"}</b></span>
133 </div> 178 </div>
134 <div className='stats-div'> 179 <div className='stats-div'>
135 <span>Singleplayer</span><br/> 180 <span>Singleplayer</span><br />
136 <span style={{fontSize: "22px"}}><b>#10</b>&nbsp;(60/62)</span> 181 <span style={{ fontSize: "22px" }}><b>{profile.rankings.singleplayer.rank > 0 ? "#" + profile.rankings.singleplayer.rank : "No rank"}</b>&nbsp;{profile.rankings.singleplayer.rank > 0 ? "(" + profile.rankings.singleplayer.completion_count + "/" + profile.rankings.singleplayer.completion_total + ")" : ""}</span>
137 </div> 182 </div>
138 <div className='stats-div'> 183 <div className='stats-div'>
139 <span>Overall rank</span><br/> 184 <span>Cooperative rank</span><br />
140 <span style={{fontSize: "22px"}}><b>#69</b>&nbsp;(13/37)</span> 185 <span style={{ fontSize: "22px" }}><b>{profile.rankings.cooperative.rank > 0 ? "#" + profile.rankings.cooperative.rank : "No rank"}</b>&nbsp;{profile.rankings.cooperative.rank > 0 ? "(" + profile.rankings.cooperative.completion_count + "/" + profile.rankings.cooperative.completion_total + ")" : ""}</span>
141 </div> 186 </div>
142 </div> 187 </div>
143 </section> 188 </section>
189 : null}
190 {isLoggedIn ?
144 <section title="What's Next?" className='homepage-panel'> 191 <section title="What's Next?" className='homepage-panel'>
145 <div style={{display: "flex"}}> 192 <div style={{ display: "flex" }}>
146 <img className='recommended-map-img' id="recommendedMapImg"></img> 193 <div className='recommended-map-img' id="recommendedMapImg"></div>
147 <div style={{marginLeft: "12px", display: "block", width: "100%"}}> 194 <div style={{ marginLeft: "12px", display: "block", width: "100%" }}>
148 <span style={{fontFamily: "BarlowSemiCondensed-SemiBold", fontSize: "32px", width: "100%", display: "block"}}>Container Ride</span> 195 <span style={{ fontFamily: "BarlowSemiCondensed-SemiBold", fontSize: "32px", width: "100%", display: "block" }}>Container Ride</span>
149 <span style={{fontSize: "20px"}}>Your Record: 4 portals</span> 196 <span style={{ fontSize: "20px", display: "block" }}>Your Record: 4 portals</span>
150 <span style={{fontFamily: "BarlowSemiCondensed-SemiBold", fontSize: "36px", width: "100%", display: "block"}}>World Record: 2 portals</span> 197 <span style={{ fontFamily: "BarlowSemiCondensed-SemiBold", fontSize: "36px", width: "100%", display: "block" }}>World Record: 2 portals</span>
151 <div className='difficulty-bar-home'> 198 <div className='difficulty-bar-home'>
152 <div className='difficulty-point' style={{backgroundColor: "#51C355"}}></div> 199 <div className='difficulty-point' style={{ backgroundColor: "#51C355" }}></div>
153 <div className='difficulty-point'></div> 200 <div className='difficulty-point'></div>
154 <div className='difficulty-point'></div> 201 <div className='difficulty-point'></div>
155 <div className='difficulty-point'></div> 202 <div className='difficulty-point'></div>
@@ -158,17 +205,39 @@ export default function Homepage(prop) {
158 </div> 205 </div>
159 </div> 206 </div>
160 </section> 207 </section>
161 <section title="Newest Records" className='homepage-panel' style={{height: "250px"}}> 208 : null}
209 <section title="Newest Records" className='homepage-panel' style={{ height: isLoggedIn ? "250px" : "960px" }}>
162 <div className='record-title'> 210 <div className='record-title'>
163 <div> 211 <div>
164 <span>Place</span> 212 <span>Place</span>
165 <span style={{textAlign: "left"}}>Runner</span> 213 <span style={{ textAlign: "left" }}>Runner</span>
166 <span>Portals</span> 214 <span>Portals</span>
167 <span>Time</span> 215 <span>Time</span>
168 <span>Date</span> 216 <span>Date</span>
169 </div> 217 </div>
170 </div> 218 </div>
171 <div style={{overflowY: "scroll", height: "calc(100% - 90px)", paddingRight: "10px"}}> 219 <div style={{ overflowY: "scroll", height: "calc(100% - 90px)", paddingRight: "10px" }}>
220 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
221 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
222 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
223 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
224 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
225 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
226 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
227 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
228 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
229 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
230 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
231 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
232 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
233 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
234 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
235 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
236 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
237 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
238 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
239 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
240 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
172 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record> 241 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
173 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record> 242 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
174 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record> 243 <Record name={"Krzyhau"} portals={"2"} date={new Date("2024-05-21T08:45:00")} place={"2"} time={"20.20"}></Record>
@@ -180,9 +249,9 @@ export default function Homepage(prop) {
180 </section> 249 </section>
181 </div> 250 </div>
182 {/* Column 2 */} 251 {/* Column 2 */}
183 <div id='column2' style={{display: "flex", alignItems: "stretch", height: "87px"}}> 252 <div id='column2' style={{ display: "flex", alignItems: "stretch", height: "1000px" }}>
184 <section title="News" className='homepage-panel'> 253 <section title="News" className='homepage-panel'>
185 <div id='newsContent' style={{ display: "block", width: "100%", overflowY: "scroll", height: "calc(100% - 50px)"}}> 254 <div id='newsContent' style={{ display: "block", width: "100%", overflowY: "scroll", height: "calc(100% - 50px)" }}>
186 {newsList.map((newsList, index) => ( 255 {newsList.map((newsList, index) => (
187 <News newsInfo={newsList} key={index}></News> 256 <News newsInfo={newsList} key={index}></News>
188 ))} 257 ))}
@@ -190,9 +259,9 @@ export default function Homepage(prop) {
190 </section> 259 </section>
191 </div> 260 </div>
192 </div> 261 </div>
193
194 262
195 263
264
196 </main> 265 </main>
197 ) 266 )
198} \ No newline at end of file 267} \ No newline at end of file