@@ -22,6 +22,7 @@ import {
2222 DialogTitle ,
2323 DialogTrigger ,
2424} from "@gitru/ui/components/dialog" ;
25+ import { Group , GroupSeparator } from "@gitru/ui/components/group" ;
2526import { Input } from "@gitru/ui/components/input" ;
2627import {
2728 InputGroup ,
@@ -35,6 +36,10 @@ import {
3536 DropdownMenuContent ,
3637 DropdownMenuItem ,
3738 DropdownMenuTrigger ,
39+ Menu ,
40+ MenuItem ,
41+ MenuPopup ,
42+ MenuTrigger ,
3843} from "@gitru/ui/components/menu" ;
3944import {
4045 ResizableHandle ,
@@ -75,6 +80,7 @@ import {
7580} from "lucide-react" ;
7681import { memo , useCallback , useState } from "react" ;
7782import { toast } from "sonner" ;
83+ import z from "zod" ;
7884import { useDiffViewStore } from "@/components/diff/useDiffViewStore" ;
7985import { useFileSelectionStore } from "@/components/diff/useFileSelectionStore" ;
8086import { getStatusIcon } from "@/components/getStatusIcon" ;
@@ -85,6 +91,8 @@ import {
8591} from "@/lib/time" ;
8692import {
8793 getCommitHistory ,
94+ useCreateCommit ,
95+ useCurrentBranch ,
8896 useRepositoryActions ,
8997 useStatus ,
9098} from "@/state/hooks" ;
@@ -404,41 +412,7 @@ function GitPageLayout() {
404412 </ >
405413 ) }
406414 </ div >
407- < div className = "shrink-0 border-l flex flex-col gap-2 justify-between items-center border-t px-2 py-2 bg-accent dark:bg-accent/10" >
408- < Input
409- placeholder = "Summary (required)"
410- className = "h-8 _border-border dark:bg-background!"
411- />
412- < InputGroup className = "dark:bg-background!" >
413- < InputGroupTextarea
414- placeholder = "Description"
415- className = "dark:bg-background!"
416- />
417- < InputGroupAddon align = "block-end" >
418- < Button
419- variant = "ghost"
420- size = "icon-xs"
421- className = "rounded-full opacity-50 hover:opacity-100"
422- aria-label = "Add Co Authors"
423- >
424- < UserPlus size = { 16 } />
425- </ Button >
426- < Separator
427- orientation = "vertical"
428- className = { "h-[80%] mx-0" }
429- />
430- < Button
431- variant = "ghost"
432- size = "icon-xs"
433- className = "rounded-full opacity-50 hover:opacity-100"
434- aria-label = "Add files"
435- >
436- < Sparkles size = { 16 } />
437- </ Button >
438- </ InputGroupAddon >
439- </ InputGroup >
440- < Button className = "w-full" > Commit to main</ Button >
441- </ div >
415+ < WriteCommitBox />
442416 </ TabsPanel >
443417 < TabsPanel value = "tab-2" className = { "h-full" } tabIndex = { - 1 } >
444418 < ScrollArea
@@ -918,3 +892,98 @@ const DiscardChangesDialog = memo(function DiscardChangesDialog({
918892 </ Dialog >
919893 ) ;
920894} ) ;
895+
896+ const CoAuthers = z . array ( z . tuple ( [ z . string ( ) , z . string ( ) ] ) ) ;
897+ type CoAuthers = z . infer < typeof CoAuthers > ;
898+
899+ const WriteCommitBox = memo ( function WriteCommitBox ( ) {
900+ const [ title , setTitle ] = useState ( "" ) ;
901+ const [ description , setDescription ] = useState ( "" ) ;
902+ const [ co_authors , setCoAuthors ] = useState < CoAuthers > ( [ ] ) ;
903+
904+ const { data : currentBranch } = useCurrentBranch ( ) ;
905+ const { mutateAsync : createCommit , isPending : isCreatingCommit } =
906+ useCreateCommit ( ) ;
907+
908+ const handelCommit = useCallback ( async ( ) => {
909+ const data = await createCommit ( {
910+ title,
911+ description,
912+ co_authors,
913+ } ) ;
914+ if ( data ) {
915+ setTitle ( "" ) ;
916+ setDescription ( "" ) ;
917+ setCoAuthors ( [ ] ) ;
918+ toast . success ( "Commit created successfully" ) ;
919+ }
920+ } , [ createCommit , title , description , co_authors ] ) ;
921+
922+ return (
923+ < div >
924+ < div className = "shrink-0 border-l flex flex-col gap-2 justify-between items-center border-t px-2 py-2 bg-accent dark:bg-accent/10" >
925+ < Input
926+ placeholder = "Summary (required)"
927+ className = "h-8 _border-border dark:bg-background!"
928+ value = { title }
929+ onChange = { ( e ) => setTitle ( e . target . value ) }
930+ />
931+ < InputGroup className = "dark:bg-background!" >
932+ < InputGroupTextarea
933+ placeholder = "Description"
934+ className = "dark:bg-background!"
935+ value = { description }
936+ onChange = { ( e ) => setDescription ( e . target . value ) }
937+ />
938+ < InputGroupAddon align = "block-end" >
939+ < Button
940+ variant = "ghost"
941+ size = "icon-xs"
942+ className = "rounded-full opacity-50 hover:opacity-100"
943+ aria-label = "Add Co Authors"
944+ >
945+ < UserPlus size = { 16 } />
946+ </ Button >
947+ < Separator orientation = "vertical" className = { "h-4 mx-0" } />
948+ < Button
949+ variant = "ghost"
950+ size = "icon-xs"
951+ className = "rounded-full opacity-50 hover:opacity-100"
952+ aria-label = "Add files"
953+ >
954+ < Sparkles size = { 16 } />
955+ </ Button >
956+ </ InputGroupAddon >
957+ </ InputGroup >
958+ < Group aria-label = "Subscription actions" className = "w-full" >
959+ < Button
960+ onClick = { handelCommit }
961+ className = "flex-1 truncate"
962+ disabled = { isCreatingCommit || title . trim ( ) === "" }
963+ >
964+ Commit to
965+ < span className = "truncate -ml-1" > { currentBranch ?. name } </ span >
966+ </ Button >
967+ < GroupSeparator className = "bg-primary/72" />
968+ < Menu >
969+ < MenuTrigger
970+ render = {
971+ < Button
972+ aria-label = "Copy options"
973+ size = "icon"
974+ className = "rounded-r-lg!"
975+ />
976+ }
977+ >
978+ < ChevronDownIcon className = "size-4" />
979+ </ MenuTrigger >
980+ < MenuPopup align = "end" className = { "w-full" } >
981+ < MenuItem > Empty Commit</ MenuItem >
982+ < MenuItem > Amend Last Commit</ MenuItem >
983+ </ MenuPopup >
984+ </ Menu >
985+ </ Group >
986+ </ div >
987+ </ div >
988+ ) ;
989+ } ) ;
0 commit comments