aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components
diff options
context:
space:
mode:
authorNidboj132 <lol2s@vp.pl>2023-05-06 16:17:52 +0200
committerGitHub <noreply@github.com>2023-05-06 16:17:52 +0200
commit5e29c7e9d65f77c0597d81de611a89268cadef1c (patch)
tree4d04c0cdea26e0e497134b99c0e34a7d9d478f34 /frontend/src/components
parentfix: allow credentials cors (diff)
parentMerge branch 'pektezol:main' into main (diff)
downloadlphub-5e29c7e9d65f77c0597d81de611a89268cadef1c.tar.gz
lphub-5e29c7e9d65f77c0597d81de611a89268cadef1c.tar.bz2
lphub-5e29c7e9d65f77c0597d81de611a89268cadef1c.zip
Merge pull request #41 from Nidboj132/main
login test
Diffstat (limited to 'frontend/src/components')
-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
4 files changed, 100 insertions, 12 deletions
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>