11import { Toast } from "@base-ui/react" ;
22import { useMutation } from "@tanstack/react-query" ;
33import { Match } from "effect" ;
4- import { CommitMoveParams , MoveBranchParams , TearOffBranchParams } from "#electron/ipc.ts" ;
4+ import {
5+ CommitCreateParams ,
6+ CommitMoveParams ,
7+ MoveBranchParams ,
8+ TearOffBranchParams ,
9+ } from "#electron/ipc.ts" ;
510import { rejectedChangesToastOptions } from "#ui/components/RejectedChanges.tsx" ;
611import {
12+ commitCreateMutationOptions ,
713 commitMoveMutationOptions ,
814 moveBranchMutationOptions ,
915 rubMutationOptions ,
@@ -15,13 +21,15 @@ export type RubOperation = Omit<RubParams, "projectId">;
1521
1622export type Operation =
1723 | ( { _tag : "Rub" } & RubOperation )
24+ | ( { _tag : "CommitCreate" } & Omit < CommitCreateParams , "projectId" > )
1825 | ( { _tag : "CommitMove" } & Omit < CommitMoveParams , "projectId" > )
1926 | ( { _tag : "MoveBranch" } & Omit < MoveBranchParams , "projectId" > )
2027 | ( { _tag : "TearOffBranch" } & Omit < TearOffBranchParams , "projectId" > ) ;
2128
2229export const useRunOperation = ( projectId : string ) => {
2330 const toastManager = Toast . useToastManager ( ) ;
2431 const rubMutation = useMutation ( rubMutationOptions ) ;
32+ const commitCreate = useMutation ( commitCreateMutationOptions ) ;
2533 const commitMove = useMutation ( commitMoveMutationOptions ) ;
2634 const moveBranch = useMutation ( moveBranchMutationOptions ) ;
2735 const tearOffBranch = useMutation ( tearOffBranchMutationOptions ) ;
@@ -50,6 +58,28 @@ export const useRunOperation = (projectId: string) => {
5058 } ,
5159 ) ;
5260 } ) ,
61+ Match . tag ( "CommitCreate" , ( operation ) => {
62+ commitCreate . mutate (
63+ {
64+ projectId,
65+ relativeTo : operation . relativeTo ,
66+ side : operation . side ,
67+ changes : operation . changes ,
68+ message : operation . message ,
69+ } ,
70+ {
71+ onSuccess : ( response ) => {
72+ if ( response . rejectedChanges . length > 0 )
73+ toastManager . add (
74+ rejectedChangesToastOptions ( {
75+ newCommit : response . newCommit ,
76+ rejectedChanges : response . rejectedChanges ,
77+ } ) ,
78+ ) ;
79+ } ,
80+ } ,
81+ ) ;
82+ } ) ,
5383 Match . tag ( "CommitMove" , ( operation ) => {
5484 commitMove . mutate ( {
5585 projectId,
0 commit comments