-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from webdevcody/feat-manual-playground
Ability to play as user in Playground
- Loading branch information
Showing
14 changed files
with
407 additions
and
176 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
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
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 |
---|---|---|
@@ -1,16 +1,41 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import { Button } from "./ui/button"; | ||
import { ClipboardCopyIcon, SmileIcon } from "lucide-react"; | ||
|
||
export function CopyMapButton({ map }: { map: string[][] }) { | ||
const timeout = React.useRef<ReturnType<typeof setTimeout> | null>(null); | ||
const [copied, setCopied] = React.useState(false); | ||
|
||
async function handleClick() { | ||
await navigator.clipboard.writeText(JSON.stringify(map)); | ||
setCopied(true); | ||
|
||
timeout.current = setTimeout(() => { | ||
timeout.current = null; | ||
setCopied(false); | ||
}, 2000); | ||
} | ||
|
||
React.useEffect(() => { | ||
return () => { | ||
if (timeout.current !== null) { | ||
clearTimeout(timeout.current); | ||
} | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<Button onClick={handleClick} type="button"> | ||
Copy As Code | ||
</Button> | ||
<button | ||
className={ | ||
copied | ||
? "cursor-default" | ||
: "enabled:hover:scale-125 transition disabled:opacity-50" | ||
} | ||
onClick={copied ? undefined : handleClick} | ||
type="button" | ||
> | ||
{copied ? <SmileIcon size={16} /> : <ClipboardCopyIcon size={16} />} | ||
</button> | ||
); | ||
} |
Oops, something went wrong.