Skip to content

Commit

Permalink
Ability to submit the generate form with cmd+enter (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
nichochar authored Jul 12, 2024
1 parent b2ff088 commit ec4c0e8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/web/src/components/generate-srcbook-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from 'react';
import { useHotkeys } from 'react-hotkeys-hook';
import { useNavigate } from 'react-router-dom';
import { cn } from '@/lib/utils';
import { Button } from '@/components/ui/button';
Expand Down Expand Up @@ -29,7 +30,17 @@ export default function GenerateSrcbookModal({

const navigate = useNavigate();

useHotkeys(
'mod+enter',
() => {
if (!open) return;
generate();
},
{ enableOnFormTags: ['textarea'] },
);

const generate = async () => {
if (!query) return;
setStatus('loading');
const result = await onGenerate(query);
if (result) {
Expand Down

0 comments on commit ec4c0e8

Please sign in to comment.