mirror of
https://github.com/SrIzan10/spongebin.git
synced 2026-05-01 11:05:09 +00:00
feat: add save button keybind
This commit is contained in:
@@ -4,6 +4,7 @@ import { useRouter } from "next/navigation";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "~/components/ui/button";
|
||||
import { addPaste } from "~/actions/paste-action";
|
||||
import { useEffect } from "react";
|
||||
|
||||
interface SaveButtonProps {
|
||||
content: string;
|
||||
@@ -38,6 +39,17 @@ export function SaveButton({
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key !== "s" || !(e.ctrlKey || e.metaKey)) return;
|
||||
e.preventDefault();
|
||||
handleSave();
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", handleKeyDown);
|
||||
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||
}, [content, language, theme]);
|
||||
|
||||
return (
|
||||
<Button variant="outline" onClick={handleSave} className={className}>
|
||||
save
|
||||
|
||||
Reference in New Issue
Block a user