-
-
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.
* feat: game over dialog * refactor: to async await * a11y 👎
- Loading branch information
1 parent
bfca7c2
commit 97cca4e
Showing
4 changed files
with
113 additions
and
22 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,70 @@ | ||
"use client"; | ||
|
||
import { useRef, useState } from "react"; | ||
import { CheckIcon, CopyIcon, Skull } from "lucide-react"; | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogHeader, | ||
DialogTitle, | ||
} from "@/components/ui/dialog"; | ||
import { Input } from "@/components/ui/input"; | ||
|
||
export function GameOverDialog() { | ||
const [isOpen, setIsOpen] = useState(true); | ||
const [isCopied, setIsCopied] = useState(false); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
const shareLink = "https://mmmines.fly.dev/"; | ||
|
||
const copyToClipboard = async () => { | ||
if (inputRef.current) { | ||
inputRef.current.select(); | ||
await navigator.clipboard.writeText(shareLink); | ||
setIsCopied(true); | ||
setTimeout(() => setIsCopied(false), 2000); | ||
} | ||
}; | ||
|
||
return ( | ||
<Dialog open={isOpen} onOpenChange={setIsOpen}> | ||
<DialogContent className="sm:max-w-md"> | ||
<DialogHeader> | ||
<DialogTitle>Game Over</DialogTitle> | ||
</DialogHeader> | ||
<div className="flex flex-col items-center gap-6"> | ||
<Skull className="h-12 w-12 text-red-600 dark:text-red-300" /> | ||
<div> | ||
<h1 className="pb-2 text-center text-lg font-semibold"> | ||
You're out this round | ||
</h1> | ||
<h2 className="text-center text-sm text-slate-600 dark:text-slate-300"> | ||
Share this link with others so you can get back in sooner! | ||
</h2> | ||
</div> | ||
<div className="flex w-full space-x-2"> | ||
<Input | ||
ref={inputRef} | ||
readOnly | ||
value={shareLink} | ||
className="flex-grow" | ||
/> | ||
<Button onClick={copyToClipboard} className="w-24"> | ||
{isCopied ? ( | ||
<> | ||
<CheckIcon className="mr-2 h-4 w-4" /> | ||
Copied | ||
</> | ||
) : ( | ||
<> | ||
<CopyIcon className="mr-2 h-4 w-4" /> | ||
Copy | ||
</> | ||
)} | ||
</Button> | ||
</div> | ||
</div> | ||
</DialogContent> | ||
</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
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,24 @@ | ||
import * as React from "react"; | ||
import { cn } from "@/utils"; | ||
|
||
export interface InputProps | ||
extends React.InputHTMLAttributes<HTMLInputElement> {} | ||
|
||
const Input = React.forwardRef<HTMLInputElement, InputProps>( | ||
({ className, type, ...props }, ref) => { | ||
return ( | ||
<input | ||
type={type} | ||
className={cn( | ||
"flex h-9 w-full rounded-md border border-slate-200 bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-slate-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-slate-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-800 dark:placeholder:text-slate-400 dark:focus-visible:ring-slate-300", | ||
className, | ||
)} | ||
ref={ref} | ||
{...props} | ||
/> | ||
); | ||
}, | ||
); | ||
Input.displayName = "Input"; | ||
|
||
export { Input }; |