File tree Expand file tree Collapse file tree 5 files changed +36
-29
lines changed Expand file tree Collapse file tree 5 files changed +36
-29
lines changed Original file line number Diff line number Diff line change 108
108
109
109
async function showAndPrefillName() {
110
110
createRefModal ?.show ();
111
- createRefName = await stackService .newBranchName (projectId );
111
+ createRefName = await stackService .fetchNewBranchName (projectId );
112
112
// Reset selected stack to default
113
113
selectedStackId = undefined ;
114
114
}
Original file line number Diff line number Diff line change 81
81
return failed ;
82
82
}
83
83
84
- const stackState = $derived (stackId ? uiState .stack (stackId ) : undefined );
85
- const selection = $derived (stackState ?.selection .current );
86
-
87
84
const exclusiveAction = $derived (projectState .exclusiveAction .current );
88
85
const commitAction = $derived (exclusiveAction ?.type === ' commit' ? exclusiveAction : undefined );
89
86
92
89
const topBranchName = $derived (topBranchResult ?.current .data ?.at (0 )?.name );
93
90
94
91
const draftBranchName = $derived (uiState .global .draftBranchName .current );
95
-
96
- const selectedBranchName = $derived (selection ?.branchName || topBranchName );
97
- const canCommit = $derived (
98
- (selectedBranchName || draftBranchName || topBranchName ) && selectedLines .current .length > 0
99
- );
92
+ const canCommit = $derived (selectedLines .current .length > 0 );
100
93
101
94
let input = $state <ReturnType <typeof CommitMessageEditor >>();
102
95
110
103
await tick ();
111
104
try {
112
105
let finalStackId = stackId ;
113
- let finalBranchName = commitAction ?.branchName || topBranchName ;
106
+ let finalBranchName = commitAction ?.branchName || draftBranchName || topBranchName ;
107
+ // TODO: Refactor this awkward fallback somehow.
108
+ if (! finalBranchName ) {
109
+ finalBranchName = await stackService .fetchNewBranchName (projectId );
110
+ }
114
111
const parentId = commitAction ?.parentCommitId ;
115
112
116
113
if (! finalStackId ) {
117
114
const stack = await createNewStack ({
118
115
projectId ,
119
- branch: { name: draftBranchName , order: 0 }
116
+ branch: { name: finalBranchName , order: 0 }
120
117
});
121
118
finalStackId = stack .id ;
122
119
projectState .stackId .set (finalStackId );
Original file line number Diff line number Diff line change 3
3
import CommitGoesHere from ' $components/CommitGoesHere.svelte' ;
4
4
import ConfigurableScrollableContainer from ' $components/ConfigurableScrollableContainer.svelte' ;
5
5
import NewCommitView from ' $components/NewCommitView.svelte' ;
6
+ import ReduxResult from ' $components/ReduxResult.svelte' ;
6
7
import Resizer from ' $components/Resizer.svelte' ;
7
8
import { StackService } from ' $lib/stacks/stackService.svelte' ;
8
9
import { UiState } from ' $lib/state/uiState.svelte' ;
43
44
<div class ="new-commit-view" data-testid ={TestId .NewCommitView }>
44
45
<NewCommitView {projectId } />
45
46
</div >
46
- {#await newNameResult then newName }
47
- {@const branchName = draftBranchName .current || newName }
48
- <BranchCard
49
- type =" draft-branch"
50
- {projectId }
51
- {branchName }
52
- readonly ={false }
53
- lineColor =" var(--clr-commit-local)"
54
- >
55
- {#snippet branchContent ()}
56
- <CommitGoesHere commitId ={undefined } selected last />
57
- {/ snippet }
58
- </BranchCard >
59
- {/await }
47
+ <ReduxResult {projectId } result ={newNameResult .current }>
48
+ {#snippet children (newName )}
49
+ {@const branchName = draftBranchName .current || newName }
50
+ <BranchCard
51
+ type =" draft-branch"
52
+ {projectId }
53
+ {branchName }
54
+ readonly ={false }
55
+ lineColor =" var(--clr-commit-local)"
56
+ >
57
+ {#snippet branchContent ()}
58
+ <CommitGoesHere commitId ={undefined } selected last />
59
+ {/ snippet }
60
+ </BranchCard >
61
+ {/ snippet }
62
+ </ReduxResult >
60
63
<Resizer
61
64
persistId =" resizer-darft-panel"
62
65
viewport ={draftPanelEl }
Original file line number Diff line number Diff line change 239
239
const branchName = selectionId .branchName ;
240
240
241
241
const fileNames = changes .map ((change ) => change .path );
242
- const newBranchName = await stackService .newBranchName (projectId );
242
+ const newBranchName = await stackService .fetchNewBranchName (projectId );
243
243
244
244
if (! newBranchName ) {
245
245
toasts .error (' Failed to generate a new branch name.' );
269
269
const branchName = selectionId .branchName ;
270
270
271
271
const fileNames = changes .map ((change ) => change .path );
272
- const newBranchName = await stackService .newBranchName (projectId );
272
+ const newBranchName = await stackService .fetchNewBranchName (projectId );
273
273
274
274
if (! newBranchName ) {
275
275
toasts .error (' Failed to generate a new branch name.' );
306
306
<ContextMenuItem
307
307
label =" Stash into branch"
308
308
onclick ={() => {
309
- stackService .newBranchName (projectId ).then ((name ) => {
309
+ stackService .fetchNewBranchName (projectId ).then ((name ) => {
310
310
stashBranchName = name || ' ' ;
311
311
});
312
312
stashConfirmationModal ?.show (item );
Original file line number Diff line number Diff line change @@ -736,7 +736,14 @@ export class StackService {
736
736
} ) ;
737
737
}
738
738
739
- async newBranchName ( projectId : string ) {
739
+ newBranchName ( projectId : string ) {
740
+ const result = $derived (
741
+ this . api . endpoints . newBranchName . useQuery ( { projectId } , { forceRefetch : true } )
742
+ ) ;
743
+ return result ;
744
+ }
745
+
746
+ async fetchNewBranchName ( projectId : string ) {
740
747
return await this . api . endpoints . newBranchName . fetch ( { projectId } , { forceRefetch : true } ) ;
741
748
}
742
749
You can’t perform that action at this time.
0 commit comments