-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
383 additions
and
50 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import { Icon } from '@iconify/react'; | ||
import loginHandler from '../services/loginHandler'; | ||
import '../styles/popup.css'; | ||
import '../styles/login.css'; | ||
|
||
interface LoginProps { | ||
setShowLogin: (value: boolean) => void; | ||
setIsLogedIn: (value: boolean) => void; | ||
token: string; | ||
setToken: (value: string) => void; | ||
message: string | null; | ||
setMessage: (value: string | null) => void; | ||
} | ||
|
||
function Login({ setShowLogin, setIsLogedIn, token, setToken, message, setMessage }: LoginProps) { | ||
const tryLogin = async () => { | ||
const username = (document.getElementById("username") as HTMLInputElement).value; | ||
const password = (document.getElementById("password") as HTMLInputElement).value; | ||
const loginResult = await loginHandler({ username, password, setToken }); | ||
|
||
console.log(loginResult); | ||
|
||
if (loginResult === true) { | ||
setShowLogin(false); | ||
localStorage.setItem('token', token); | ||
setIsLogedIn(true); | ||
setMessage('Successfully logged in'); | ||
} else { | ||
alert('Failed to login. Please try again.'); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="Popup"> | ||
<div className="Login-title">Login</div> | ||
<div className="Login-input"> | ||
<label htmlFor="username">Username</label> | ||
<input type="text" id="username" name="username" /> | ||
|
||
<label htmlFor="password">Password</label> | ||
<input type="password" id="password" name="password" /> | ||
</div> | ||
<button type="button" className="Login-button" onClick={tryLogin}>confirm</button> | ||
<button type="button" className="Login-close" title="Close" onClick={() => setShowLogin(false)}> | ||
<Icon icon="ci:close-md" /> | ||
</button> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default Login; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import '../styles/notification.css'; | ||
|
||
interface NotificationProps { | ||
message: string | null; | ||
setMessage: (value: string | null) => void; | ||
} | ||
|
||
function Notification({ message, setMessage }: NotificationProps) { | ||
const [visible, setVisible] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
if (message !== null) { | ||
setVisible(true); | ||
const visibilityTimer = setTimeout(() => { | ||
setVisible(false); | ||
}, 2000); | ||
const messageTimer = setTimeout(() => { | ||
setMessage(null); | ||
}, 4000); | ||
return () => { | ||
clearTimeout(visibilityTimer); | ||
clearTimeout(messageTimer); | ||
}; | ||
} | ||
return; | ||
}, [message, setMessage]); | ||
|
||
return ( | ||
<div className={`notification ${visible ? 'show' : ''}`}> | ||
{message} | ||
</div> | ||
); | ||
} | ||
|
||
export default Notification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.