chore: allow cmd+enter to post

This commit is contained in:
Danish Arora 2025-09-11 12:10:51 +05:30
parent 244119bb05
commit 9b1a6ea548
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
3 changed files with 33 additions and 3 deletions

View File

@ -96,6 +96,16 @@ export function CreateCellDialog({
}
};
// Handle keyboard shortcuts
const handleKeyDown = (e: React.KeyboardEvent) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
e.preventDefault();
if (!isCreatingCell && canCreateCell) {
form.handleSubmit(onSubmit)();
}
}
};
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
@ -108,7 +118,7 @@ export function CreateCellDialog({
<DialogTitle className="text-glow">Create New Cell</DialogTitle>
</DialogHeader>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
<form onSubmit={form.handleSubmit(onSubmit)} onKeyDown={handleKeyDown} className="space-y-4">
<FormField
control={form.control}
name="title"

View File

@ -101,6 +101,16 @@ const PostDetail = () => {
}
};
// Handle keyboard shortcuts
const handleKeyDown = (e: React.KeyboardEvent) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
e.preventDefault();
if (!isCreatingComment && newComment.trim()) {
handleCreateComment(e as React.FormEvent);
}
}
};
const handleVotePost = async (isUpvote: boolean) => {
// ✅ Permission checking handled in hook
await votePost(post.id, isUpvote);
@ -255,7 +265,7 @@ const PostDetail = () => {
{/* Comment Form */}
{canComment && (
<div className="mb-8">
<form onSubmit={handleCreateComment}>
<form onSubmit={handleCreateComment} onKeyDown={handleKeyDown}>
<h2 className="text-sm font-bold mb-2 flex items-center gap-1">
<MessageCircle className="w-4 h-4" />
Add a comment

View File

@ -124,6 +124,16 @@ const PostList = () => {
}
};
// Handle keyboard shortcuts
const handleKeyDown = (e: React.KeyboardEvent) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
e.preventDefault();
if (!isCreatingPost && newPostContent.trim() && newPostTitle.trim()) {
handleCreatePost(e as React.FormEvent);
}
}
};
const handleVotePost = async (postId: string, isUpvote: boolean) => {
// ✅ Permission checking handled in hook
await votePost(postId, isUpvote);
@ -198,7 +208,7 @@ const PostList = () => {
{canPost && (
<div className="section-spacing">
<form onSubmit={handleCreatePost}>
<form onSubmit={handleCreatePost} onKeyDown={handleKeyDown}>
<h2 className="text-sm font-bold mb-2 flex items-center gap-1">
<MessageSquare className="w-4 h-4" />
New Thread