|
6 | 6 | import { changesToDiffSpec } from '$lib/commits/utils';
|
7 | 7 | import { projectAiExperimentalFeaturesEnabled, projectAiGenEnabled } from '$lib/config/config';
|
8 | 8 | import { isTreeChange, type TreeChange } from '$lib/hunks/change';
|
9 |
| - import { showToast } from '$lib/notifications/toasts'; |
10 | 9 | import { vscodePath } from '$lib/project/project';
|
11 | 10 | import { ProjectsService } from '$lib/project/projectsService';
|
12 | 11 | import { IdSelection } from '$lib/selection/idSelection.svelte';
|
|
168 | 167 | return;
|
169 | 168 | }
|
170 | 169 |
|
171 |
| - showToast({ |
172 |
| - style: 'neutral', |
173 |
| - title: 'Figuring out where to commit the changes', |
174 |
| - message: 'This may take a few seconds.' |
175 |
| - }); |
176 |
| -
|
177 |
| - await autoCommit({ projectId, changes }); |
178 |
| -
|
179 |
| - showToast({ |
180 |
| - style: 'success', |
181 |
| - title: 'And... done!', |
182 |
| - message: `Now, you're free to continue` |
183 |
| - }); |
| 170 | + await toasts.promise( |
| 171 | + (async () => { |
| 172 | + await autoCommit({ |
| 173 | + projectId, |
| 174 | + changes |
| 175 | + }); |
| 176 | + })(), |
| 177 | + { |
| 178 | + loading: 'Started auto commit', |
| 179 | + success: 'Auto commit succeded', |
| 180 | + error: (error: Error) => `Auto commit failed: ${error.message}` |
| 181 | + } |
| 182 | + ); |
184 | 183 | }
|
185 | 184 |
|
186 | 185 | async function triggerBranchChanges(changes: TreeChange[]) {
|
|
189 | 188 | return;
|
190 | 189 | }
|
191 | 190 |
|
192 |
| - showToast({ |
193 |
| - style: 'neutral', |
194 |
| - title: 'Creating a branch and committing the changes', |
195 |
| - message: 'This may take a few seconds.' |
196 |
| - }); |
197 |
| -
|
198 |
| - await branchChanges({ projectId, changes }); |
199 |
| -
|
200 |
| - showToast({ |
201 |
| - style: 'success', |
202 |
| - title: 'And... done!', |
203 |
| - message: `Now, you're free to continue` |
204 |
| - }); |
| 191 | + await toasts.promise( |
| 192 | + (async () => { |
| 193 | + await branchChanges({ projectId, changes }); |
| 194 | + })(), |
| 195 | + { |
| 196 | + loading: 'Creating a branch and committing changes', |
| 197 | + success: 'Branching changes succeded', |
| 198 | + error: (error: Error) => `Branching changes failed: ${error.message}` |
| 199 | + } |
| 200 | + ); |
205 | 201 | }
|
206 | 202 |
|
207 | 203 | async function triggerAbsorbChanges(changes: TreeChange[]) {
|
|
210 | 206 | return;
|
211 | 207 | }
|
212 | 208 |
|
213 |
| - showToast({ |
214 |
| - style: 'neutral', |
215 |
| - title: 'Looking for the best place to absorb the changes', |
216 |
| - message: 'This may take a few seconds.' |
217 |
| - }); |
218 |
| -
|
219 |
| - await absorbChanges({ projectId, changes }); |
220 |
| -
|
221 |
| - showToast({ |
222 |
| - style: 'success', |
223 |
| - title: 'And... done!', |
224 |
| - message: `Now, you're free to continue` |
225 |
| - }); |
| 209 | + await toasts.promise( |
| 210 | + (async () => { |
| 211 | + await absorbChanges({ projectId, changes }); |
| 212 | + })(), |
| 213 | + { |
| 214 | + loading: 'Looking for the best place to absorb the changes', |
| 215 | + success: 'Absorbing changes succeded', |
| 216 | + error: (error: Error) => `Absorbing changes failed: ${error.message}` |
| 217 | + } |
| 218 | + ); |
226 | 219 | }
|
227 | 220 |
|
228 | 221 | async function split(changes: TreeChange[]) {
|
|
239 | 232 | const branchName = selectionId.branchName;
|
240 | 233 |
|
241 | 234 | const fileNames = changes.map((change) => change.path);
|
242 |
| - const newBranchName = await stackService.fetchNewBranchName(projectId); |
243 | 235 |
|
244 |
| - if (!newBranchName) { |
245 |
| - toasts.error('Failed to generate a new branch name.'); |
246 |
| - return; |
247 |
| - } |
248 |
| -
|
249 |
| - await splitOffChanges({ |
250 |
| - projectId, |
251 |
| - sourceStackId: stackId, |
252 |
| - sourceBranchName: branchName, |
253 |
| - fileChangesToSplitOff: fileNames, |
254 |
| - newBranchName: newBranchName |
255 |
| - }); |
| 236 | + await toasts.promise( |
| 237 | + (async () => { |
| 238 | + const newBranchName = await stackService.fetchNewBranchName(projectId); |
| 239 | +
|
| 240 | + if (!newBranchName) { |
| 241 | + throw new Error('Failed to generate a new branch name.'); |
| 242 | + } |
| 243 | +
|
| 244 | + await splitOffChanges({ |
| 245 | + projectId, |
| 246 | + sourceStackId: stackId, |
| 247 | + sourceBranchName: branchName, |
| 248 | + fileChangesToSplitOff: fileNames, |
| 249 | + newBranchName: newBranchName |
| 250 | + }); |
| 251 | + })(), |
| 252 | + { |
| 253 | + loading: 'Splitting off changes', |
| 254 | + success: 'Changes split off into a new branch', |
| 255 | + error: (error: Error) => `Failed to split off changes: ${error.message}` |
| 256 | + } |
| 257 | + ); |
256 | 258 | }
|
257 | 259 |
|
258 | 260 | async function splitIntoDependentBranch(changes: TreeChange[]) {
|
|
269 | 271 | const branchName = selectionId.branchName;
|
270 | 272 |
|
271 | 273 | const fileNames = changes.map((change) => change.path);
|
272 |
| - const newBranchName = await stackService.fetchNewBranchName(projectId); |
273 | 274 |
|
274 |
| - if (!newBranchName) { |
275 |
| - toasts.error('Failed to generate a new branch name.'); |
276 |
| - return; |
277 |
| - } |
278 |
| -
|
279 |
| - await splitBranchIntoDependentBranch({ |
280 |
| - projectId, |
281 |
| - sourceStackId: stackId, |
282 |
| - sourceBranchName: branchName, |
283 |
| - fileChangesToSplitOff: fileNames, |
284 |
| - newBranchName: newBranchName |
285 |
| - }); |
| 275 | + await toasts.promise( |
| 276 | + (async () => { |
| 277 | + const newBranchName = await stackService.fetchNewBranchName(projectId); |
| 278 | +
|
| 279 | + if (!newBranchName) { |
| 280 | + throw new Error('Failed to generate a new branch name.'); |
| 281 | + } |
| 282 | +
|
| 283 | + await splitBranchIntoDependentBranch({ |
| 284 | + projectId, |
| 285 | + sourceStackId: stackId, |
| 286 | + sourceBranchName: branchName, |
| 287 | + fileChangesToSplitOff: fileNames, |
| 288 | + newBranchName: newBranchName |
| 289 | + }); |
| 290 | + })(), |
| 291 | + { |
| 292 | + loading: 'Splitting into dependent branch', |
| 293 | + success: 'Changes split into a dependent branch', |
| 294 | + error: (error: Error) => `Failed to split into dependent branch: ${error.message}` |
| 295 | + } |
| 296 | + ); |
286 | 297 | }
|
287 | 298 | </script>
|
288 | 299 |
|
|
372 | 383 | {#if isBranchFiles && isAdmin}
|
373 | 384 | <ContextMenuItem
|
374 | 385 | label="Split off changes"
|
375 |
| - onclick={async () => { |
376 |
| - await split(changes); |
| 386 | + onclick={() => { |
| 387 | + split(changes); |
377 | 388 | contextMenu.close();
|
378 | 389 | }}
|
379 | 390 | />
|
380 | 391 | <ContextMenuItem
|
381 | 392 | label="Split into dependent branch"
|
382 |
| - onclick={async () => { |
383 |
| - await splitIntoDependentBranch(changes); |
| 393 | + onclick={() => { |
| 394 | + splitIntoDependentBranch(changes); |
384 | 395 | contextMenu.close();
|
385 | 396 | }}
|
386 | 397 | />
|
|
394 | 405 | tooltip="Try to figure out where to commit the changes. Can create new branches too."
|
395 | 406 | onclick={async () => {
|
396 | 407 | contextMenu.close();
|
397 |
| - await triggerAutoCommit(item.changes); |
| 408 | + triggerAutoCommit(item.changes); |
398 | 409 | }}
|
399 | 410 | disabled={autoCommitting.current.isLoading}
|
400 | 411 | />
|
401 | 412 | <ContextMenuItem
|
402 | 413 | label="Branch changes 🧪"
|
403 | 414 | tooltip="Create a new branch and commit the changes into it."
|
404 |
| - onclick={async () => { |
| 415 | + onclick={() => { |
405 | 416 | contextMenu.close();
|
406 |
| - await triggerBranchChanges(item.changes); |
| 417 | + triggerBranchChanges(item.changes); |
407 | 418 | }}
|
408 | 419 | disabled={branchingChanges.current.isLoading}
|
409 | 420 | />
|
410 | 421 | <ContextMenuItem
|
411 | 422 | label="Absorb changes 🧪"
|
412 | 423 | tooltip="Try to find the best place to absorb the changes into."
|
413 |
| - onclick={async () => { |
| 424 | + onclick={() => { |
414 | 425 | contextMenu.close();
|
415 |
| - await triggerAbsorbChanges(item.changes); |
| 426 | + triggerAbsorbChanges(item.changes); |
416 | 427 | }}
|
417 | 428 | disabled={absorbingChanges.current.isLoading}
|
418 | 429 | />
|
|
0 commit comments