-
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
1 parent
0cb8e3d
commit 9cbf9c9
Showing
3 changed files
with
60 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { h, JSX } from "https://esm.sh/[email protected]?pin=v135"; | ||
import { | ||
useEffect, | ||
useRef, | ||
} from "https://esm.sh/[email protected]/hooks?pin=v135"; | ||
|
||
export const Dialog = (props: { | ||
readonly isOpen: boolean; | ||
readonly children: JSX.Element; | ||
readonly onClose: () => void; | ||
}): JSX.Element | null => { | ||
const ref = useRef<HTMLDialogElement>(null); | ||
|
||
useEffect(() => { | ||
ref.current?.addEventListener("close", props.onClose); | ||
const clickHandler = (event: MouseEvent) => { | ||
if (event.target instanceof HTMLElement) { | ||
if (event.target.closest("form") === null) { | ||
props.onClose(); | ||
} | ||
} | ||
}; | ||
ref.current?.addEventListener("click", clickHandler); | ||
return () => { | ||
ref.current?.removeEventListener("close", props.onClose); | ||
ref.current?.removeEventListener("click", clickHandler); | ||
}; | ||
}, [props.onClose, ref.current]); | ||
|
||
useEffect(() => { | ||
if (props.isOpen) { | ||
ref.current?.showModal(); | ||
} else { | ||
ref.current?.close(); | ||
} | ||
}, [props.isOpen]); | ||
|
||
if (!props.isOpen) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<dialog | ||
ref={ref} | ||
style={{ | ||
width: "80%", | ||
boxShadow: "0px 20px 36px 0px rgba(0, 0, 0, 0.6)", | ||
}} | ||
> | ||
{props.children} | ||
</dialog> | ||
); | ||
}; |
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 |
---|---|---|
|
@@ -4,49 +4,21 @@ import { | |
useRef, | ||
} from "https://esm.sh/[email protected]/hooks?pin=v135"; | ||
import { encodeBase64Url } from "jsr:@std/encoding/base64url"; | ||
import { Dialog } from "./Dialog.tsx"; | ||
|
||
export const SignUpDialog = (props: { | ||
readonly privateKey: Uint8Array | null; | ||
readonly copyPassword: () => void; | ||
readonly onClose: () => void; | ||
}): JSX.Element | null => { | ||
const ref = useRef<HTMLDialogElement>(null); | ||
|
||
useEffect(() => { | ||
ref.current?.addEventListener("close", props.onClose); | ||
const clickHandler = (event: MouseEvent) => { | ||
if (event.target instanceof HTMLElement) { | ||
if (event.target.closest("form") === null) { | ||
props.onClose(); | ||
} | ||
} | ||
}; | ||
ref.current?.addEventListener("click", clickHandler); | ||
return () => { | ||
ref.current?.removeEventListener("close", props.onClose); | ||
ref.current?.removeEventListener("click", clickHandler); | ||
}; | ||
}, [props.onClose, ref.current]); | ||
|
||
useEffect(() => { | ||
if (props.privateKey === null) { | ||
ref.current?.close(); | ||
} else { | ||
ref.current?.showModal(); | ||
} | ||
}, [props.privateKey]); | ||
|
||
if (props.privateKey === null) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<dialog | ||
ref={ref} | ||
style={{ | ||
width: "80%", | ||
boxShadow: "0px 20px 36px 0px rgba(0, 0, 0, 0.6)", | ||
}} | ||
<Dialog | ||
isOpen={props.privateKey !== null} | ||
onClose={props.onClose} | ||
> | ||
<form | ||
method="dialog" | ||
|
@@ -74,7 +46,7 @@ export const SignUpDialog = (props: { | |
</div> | ||
<label> | ||
<div>Username</div> | ||
<input type="text" /> | ||
<input type="text" required={true} /> | ||
</label> | ||
<label> | ||
<div> | ||
|
@@ -93,6 +65,6 @@ export const SignUpDialog = (props: { | |
</label> | ||
<button type="submit">Sign Up</button> | ||
</form> | ||
</dialog> | ||
</Dialog> | ||
); | ||
}; |
Oops, something went wrong.