aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNidboj132 <lol2s@vp.plm>2023-05-06 16:10:49 +0200
committerNidboj132 <lol2s@vp.plm>2023-05-06 16:10:49 +0200
commit369f16e78ea958c9a536ea4ee7791ad9d469a770 (patch)
treed9e568fe22b8abb6280da2c4d91c762d90eaf275
parentfeat: set cookie and redirect after login (diff)
downloadlphub-369f16e78ea958c9a536ea4ee7791ad9d469a770.tar.gz
lphub-369f16e78ea958c9a536ea4ee7791ad9d469a770.tar.bz2
lphub-369f16e78ea958c9a536ea4ee7791ad9d469a770.zip
login test
-rw-r--r--frontend/package-lock.json14
-rw-r--r--frontend/package.json1
-rw-r--r--frontend/src/components/login.css26
-rw-r--r--frontend/src/components/login.js54
-rw-r--r--frontend/src/components/sidebar.css6
-rw-r--r--frontend/src/components/sidebar.js26
-rw-r--r--frontend/src/imgs/10.pngbin0 -> 1601 bytes
-rw-r--r--frontend/src/imgs/11.pngbin0 -> 1294 bytes
-rw-r--r--frontend/src/imgs/login.pngbin0 -> 4871 bytes
9 files changed, 115 insertions, 12 deletions
diff --git a/frontend/package-lock.json b/frontend/package-lock.json
index 0c4569a..9bfe340 100644
--- a/frontend/package-lock.json
+++ b/frontend/package-lock.json
@@ -11,6 +11,7 @@
11 "@testing-library/jest-dom": "^5.16.5", 11 "@testing-library/jest-dom": "^5.16.5",
12 "@testing-library/react": "^13.4.0", 12 "@testing-library/react": "^13.4.0",
13 "@testing-library/user-event": "^13.5.0", 13 "@testing-library/user-event": "^13.5.0",
14 "js-cookie": "^3.0.5",
14 "react": "^18.2.0", 15 "react": "^18.2.0",
15 "react-dom": "^18.2.0", 16 "react-dom": "^18.2.0",
16 "react-scripts": "5.0.1", 17 "react-scripts": "5.0.1",
@@ -11530,6 +11531,14 @@
11530 "url": "https://github.com/chalk/supports-color?sponsor=1" 11531 "url": "https://github.com/chalk/supports-color?sponsor=1"
11531 } 11532 }
11532 }, 11533 },
11534 "node_modules/js-cookie": {
11535 "version": "3.0.5",
11536 "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz",
11537 "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==",
11538 "engines": {
11539 "node": ">=14"
11540 }
11541 },
11533 "node_modules/js-sdsl": { 11542 "node_modules/js-sdsl": {
11534 "version": "4.3.0", 11543 "version": "4.3.0",
11535 "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz", 11544 "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz",
@@ -25457,6 +25466,11 @@
25457 } 25466 }
25458 } 25467 }
25459 }, 25468 },
25469 "js-cookie": {
25470 "version": "3.0.5",
25471 "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz",
25472 "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw=="
25473 },
25460 "js-sdsl": { 25474 "js-sdsl": {
25461 "version": "4.3.0", 25475 "version": "4.3.0",
25462 "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz", 25476 "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz",
diff --git a/frontend/package.json b/frontend/package.json
index 123a434..72e2117 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -6,6 +6,7 @@
6 "@testing-library/jest-dom": "^5.16.5", 6 "@testing-library/jest-dom": "^5.16.5",
7 "@testing-library/react": "^13.4.0", 7 "@testing-library/react": "^13.4.0",
8 "@testing-library/user-event": "^13.5.0", 8 "@testing-library/user-event": "^13.5.0",
9 "js-cookie": "^3.0.5",
9 "react": "^18.2.0", 10 "react": "^18.2.0",
10 "react-dom": "^18.2.0", 11 "react-dom": "^18.2.0",
11 "react-scripts": "5.0.1", 12 "react-scripts": "5.0.1",
diff --git a/frontend/src/components/login.css b/frontend/src/components/login.css
new file mode 100644
index 0000000..633145e
--- /dev/null
+++ b/frontend/src/components/login.css
@@ -0,0 +1,26 @@
1span>img {
2 scale: 1.1;
3 padding-top: 4px;
4}
5.login>button>span{
6 max-width: 22ch;
7 overflow: hidden;
8}
9.login>button:nth-child(2){
10 position: relative;
11 left: 210px;
12 width: 50px !important;
13
14 padding-left: 10px;
15 background-color: #00000000 !important;
16 transition: opacity .1s;
17}
18
19.login{
20 display: grid;
21 grid-template-columns: 50px auto 200px ;
22}
23
24button:disabled {
25 display: none;
26} \ No newline at end of file
diff --git a/frontend/src/components/login.js b/frontend/src/components/login.js
new file mode 100644
index 0000000..4ef1e2a
--- /dev/null
+++ b/frontend/src/components/login.js
@@ -0,0 +1,54 @@
1import React from 'react';
2import { Link } from "react-router-dom";
3import Cookies from "js-cookie";
4
5import "./login.css";
6import img1 from "../imgs/login.png"
7import img2 from "../imgs/10.png"
8import img3 from "../imgs/11.png"
9
10
11export default function Login() {
12
13const isLoggedIn = Cookies.get('token') !== undefined;
14
15function logout() {
16 Cookies.remove('token')
17 window.location.href="/"
18}
19
20const [data, setData] = React.useState();
21React.useEffect(() => {
22 fetch(`/api/v1/profile`,{
23 headers: {
24 'Content-Type': 'application/json',
25 Authorization: Cookies.get('token')
26 }})
27 .then(r => {console.log(r)})
28 .then(d => {setData(d);console.log(d)})
29 }, []);
30
31return (
32 <>
33 {isLoggedIn ? (
34 <Link to="/profile" tabIndex={-1} className='login'>
35 <button>
36 <img src={img2} alt="" />
37 <span>Username</span>
38 </button>
39 <button onClick={logout}><img src={img3} alt="" /><span></span></button>
40 </Link>
41 ) : (
42 <Link to="/api/v1/login" className='login'>
43 <button>
44 <img src={img2} alt="" />
45 <span><img src={img1} alt="Sign in through Steam" /></span>
46 </button>
47 <button disabled><span></span></button>
48 </Link>
49 )}
50 </>
51 )
52}
53
54
diff --git a/frontend/src/components/sidebar.css b/frontend/src/components/sidebar.css
index 23d46ad..84600fb 100644
--- a/frontend/src/components/sidebar.css
+++ b/frontend/src/components/sidebar.css
@@ -40,9 +40,10 @@ span>b{
40} 40}
41#sidebar-toplist>button:nth-child(1){margin-top: 5px;} 41#sidebar-toplist>button:nth-child(1){margin-top: 5px;}
42#sidebar-toplist{ 42#sidebar-toplist{
43 display: grid;
43 44
44 margin: 0 5px 0 5px; 45 margin: 0 5px 0 5px;
45 display: grid; 46 justify-items: left;
46 height: 400px; 47 height: 400px;
47 grid-template-rows: 45px 50px 50px 50px 50px 50px 50px 50px auto; 48 grid-template-rows: 45px 50px 50px 50px 50px 50px 50px 50px auto;
48} 49}
@@ -53,7 +54,6 @@ span>b{
53 margin: 0 5px 0 5px; 54 margin: 0 5px 0 5px;
54 justify-items: left; 55 justify-items: left;
55 grid-template-rows: calc(100vh - 670px) 50px 50px 50px; 56 grid-template-rows: calc(100vh - 670px) 50px 50px 50px;
56 grid-template-rows: calc(100vh - 670px) 50px 50px 50px;
57} 57}
58button>span{ 58button>span{
59 font-family: BarlowSemiCondensed-Regular; 59 font-family: BarlowSemiCondensed-Regular;
@@ -80,9 +80,7 @@ button{
80 transition: 80 transition:
81 width .3s, 81 width .3s,
82 background-color .3s; 82 background-color .3s;
83 /* outline: red dotted 1px; */
84} 83}
85/* button>*{outline: red 1px dotted;} */
86 84
87button>img { 85button>img {
88 scale: 1.1; 86 scale: 1.1;
diff --git a/frontend/src/components/sidebar.js b/frontend/src/components/sidebar.js
index d5a55fd..aaaf196 100644
--- a/frontend/src/components/sidebar.js
+++ b/frontend/src/components/sidebar.js
@@ -13,8 +13,9 @@ import img6 from "../imgs/6.png"
13import img7 from "../imgs/7.png" 13import img7 from "../imgs/7.png"
14import img8 from "../imgs/8.png" 14import img8 from "../imgs/8.png"
15import img9 from "../imgs/9.png" 15import img9 from "../imgs/9.png"
16import Login from "./login.js"
16 17
17export default function Sidebar(x) { 18export default function Sidebar() {
18 19
19// Locks search button for 300ms before it can be clicked again, prevents spam 20// Locks search button for 300ms before it can be clicked again, prevents spam
20const [isLocked, setIsLocked] = React.useState(false); 21const [isLocked, setIsLocked] = React.useState(false);
@@ -48,13 +49,18 @@ function SidebarHide(){
48const btn = document.querySelectorAll("button"); 49const btn = document.querySelectorAll("button");
49const span = document.querySelectorAll("button>span"); 50const span = document.querySelectorAll("button>span");
50const side = document.querySelector("#sidebar-list"); 51const side = document.querySelector("#sidebar-list");
52const login = document.querySelectorAll(".login>button")[1];
51 53
52if(sidebar===1){ 54if(sidebar===1){
53 setSidebar(0) 55 setSidebar(0)
54 side.style.width="320px" 56 side.style.width="320px"
55 btn.forEach((e, i) =>{ 57 btn.forEach((e, i) =>{
56 e.style.width="310px" 58 e.style.width="310px"
57 setTimeout(() => {span[i].style.opacity="1"}, 100) 59 setTimeout(() => {
60 span[i].style.opacity="1"
61 login.style.opacity="1"
62
63 }, 100)
58 }) 64 })
59 side.style.zIndex="2" 65 side.style.zIndex="2"
60} else { 66} else {
@@ -64,10 +70,14 @@ if(sidebar===1){
64 e.style.width="40px" 70 e.style.width="40px"
65 span[i].style.opacity="0" 71 span[i].style.opacity="0"
66 }) 72 })
67 setTimeout(() => {side.style.zIndex="0"}, 300); 73 login.style.opacity="0"
74 setTimeout(() => {
75 side.style.zIndex="0"
76 }, 300);
68 } 77 }
69} 78}
70 79
80// Links
71const location = useLocation() 81const location = useLocation()
72React.useEffect(()=>{ 82React.useEffect(()=>{
73 if(location.pathname==="/"){SidebarClick(1)} 83 if(location.pathname==="/"){SidebarClick(1)}
@@ -77,12 +87,14 @@ React.useEffect(()=>{
77 if(location.pathname.includes("discussions")){SidebarClick(5)} 87 if(location.pathname.includes("discussions")){SidebarClick(5)}
78 if(location.pathname.includes("scorelog")){SidebarClick(6)} 88 if(location.pathname.includes("scorelog")){SidebarClick(6)}
79 if(location.pathname.includes("profile")){SidebarClick(7)} 89 if(location.pathname.includes("profile")){SidebarClick(7)}
80 if(location.pathname.includes("rules")){SidebarClick(8)} 90 if(location.pathname.includes("rules")){SidebarClick(9)}
81 if(location.pathname.includes("about")){SidebarClick(9)} 91 if(location.pathname.includes("about")){SidebarClick(10)}
92
82 // console.log(location.pathname) 93 // console.log(location.pathname)
83 // eslint-disable-next-line react-hooks/exhaustive-deps 94 // eslint-disable-next-line react-hooks/exhaustive-deps
84}, [location]) 95}, [location])
85 96
97
86return ( 98return (
87 <div id='sidebar'> 99 <div id='sidebar'>
88 <div id='logo'> {/* logo */} 100 <div id='logo'> {/* logo */}
@@ -124,9 +136,7 @@ return (
124 <div id='sidebar-bottomlist'> 136 <div id='sidebar-bottomlist'>
125 <span></span> 137 <span></span>
126 138
127 <Link to="/profile" tabIndex={-1}> 139 <Login/>
128 <button><img src={img1} alt="" /><span>Login</span></button>
129 </Link>
130 140
131 <Link to="/rules" tabIndex={-1}> 141 <Link to="/rules" tabIndex={-1}>
132 <button><img src={img8} alt="" /><span>Leaderboard&nbsp;Rules</span></button> 142 <button><img src={img8} alt="" /><span>Leaderboard&nbsp;Rules</span></button>
diff --git a/frontend/src/imgs/10.png b/frontend/src/imgs/10.png
new file mode 100644
index 0000000..d4b0863
--- /dev/null
+++ b/frontend/src/imgs/10.png
Binary files differ
diff --git a/frontend/src/imgs/11.png b/frontend/src/imgs/11.png
new file mode 100644
index 0000000..b493059
--- /dev/null
+++ b/frontend/src/imgs/11.png
Binary files differ
diff --git a/frontend/src/imgs/login.png b/frontend/src/imgs/login.png
new file mode 100644
index 0000000..6456c21
--- /dev/null
+++ b/frontend/src/imgs/login.png
Binary files differ