-
Notifications
You must be signed in to change notification settings - Fork 1
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
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
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,61 @@ | ||
import { styled } from "goober"; | ||
import type { FunctionalComponent, h } from "preact"; | ||
import { useCallback, useState } from "preact/hooks"; | ||
|
||
const LoginContainer = styled('div')` | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
`; | ||
|
||
interface ILogin { | ||
onSuccess?: () => void; | ||
onFail?: () => void; | ||
} | ||
|
||
// TODO: wire up auth | ||
export const Login: FunctionalComponent<ILogin> = ({ onSuccess, onFail }) => { | ||
//const { setAuthHeader } = useContext(authContext); | ||
|
||
const [username, setUsername] = useState<string>(''); | ||
const [password, setPassword] = useState<string>(''); | ||
|
||
const handleUsernameChange: h.JSX.GenericEventHandler<HTMLInputElement> = useCallback( | ||
(event) => setUsername((event.target as HTMLInputElement).value), | ||
[] | ||
); | ||
const handlePasswordChange: h.JSX.GenericEventHandler<HTMLInputElement> = useCallback( | ||
(event) => setPassword((event.target as HTMLInputElement).value), | ||
[] | ||
); | ||
|
||
// const handleSubmit: h.JSX.MouseEventHandler<HTMLButtonElement> = useCallback(async () => { | ||
// // const encoded = Buffer.from(`${username}:${password}`).toString('base64'); | ||
// const encoded = btoa(`${username}:${password}`); | ||
// const result = await getConfig(encoded); | ||
// if (!result) { | ||
// return onFail?.(); | ||
// } | ||
// setAuthHeader(encoded); | ||
// }, [username, password, onFail, setAuthHeader]); | ||
|
||
const handleSubmit: h.JSX.MouseEventHandler<HTMLButtonElement> = useCallback(async () => { | ||
const encoded = btoa(`${username}:${password}`); | ||
|
||
console.log(encoded); | ||
}, [username, password, onFail]); | ||
|
||
return ( | ||
<LoginContainer> | ||
<h1>Login</h1> | ||
|
||
<label>Username</label> | ||
<input type="text" onChange={handleUsernameChange} /> | ||
|
||
<label>Password</label> | ||
<input type="password" onChange={handlePasswordChange} /> | ||
|
||
<button onClick={handleSubmit}>Submit</button> | ||
</LoginContainer> | ||
); | ||
} |
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