@@ -9,12 +9,13 @@ import {
99 HunkDropDataV3 ,
1010 type ChangeDropData ,
1111} from "$lib/dragging/draggables" ;
12- import { type HooksService } from "$lib/hooks/hooksService" ;
12+ import { HOOKS_SERVICE } from "$lib/hooks/hooksService" ;
1313import { showToast } from "$lib/notifications/toasts" ;
14+ import { STACK_SERVICE } from "$lib/stacks/stackService.svelte" ;
15+ import { UI_STATE , type UiState } from "$lib/state/uiState.svelte" ;
16+ import { inject } from "@gitbutler/core/context" ;
1417import { untrack } from "svelte" ;
1518import type { DropzoneHandler } from "$lib/dragging/handler" ;
16- import type { StackService } from "$lib/stacks/stackService.svelte" ;
17- import type { UiState } from "$lib/state/uiState.svelte" ;
1819
1920/** Details about a commit belonging to a drop zone. */
2021export type DzCommitData = {
@@ -37,9 +38,9 @@ export class CommitDropData {
3738/** Handler that can move commits between stacks. */
3839export class MoveCommitDzHandler implements DropzoneHandler {
3940 private readonly uiState = inject ( UI_STATE ) ;
41+ private readonly stackService = inject ( STACK_SERVICE ) ;
4042
4143 constructor (
42- private stackService : StackService ,
4344 private stackId : string ,
4445 private projectId : string ,
4546 ) { }
@@ -83,15 +84,16 @@ export class MoveCommitDzHandler implements DropzoneHandler {
8384 * Handler that will be able to amend a commit using `TreeChange`.
8485 */
8586export class AmendCommitWithChangeDzHandler implements DropzoneHandler {
87+ private readonly uiState = inject ( UI_STATE ) ;
88+ private readonly stackService = inject ( STACK_SERVICE ) ;
89+ private readonly hooksService = inject ( HOOKS_SERVICE ) ;
90+
8691 constructor (
8792 private projectId : string ,
88- private readonly stackService : StackService ,
89- private readonly hooksService : HooksService ,
9093 private stackId : string ,
9194 private runHooks : boolean ,
9295 private commit : DzCommitData ,
9396 private onresult : ( result : string ) => void ,
94- private readonly uiState : UiState ,
9597 ) { }
9698 accepts ( data : unknown ) : boolean {
9799 if ( ! ( data instanceof FileChangeDropData || data instanceof FolderChangeDropData ) ) return false ;
@@ -156,10 +158,10 @@ export class AmendCommitWithChangeDzHandler implements DropzoneHandler {
156158
157159export class UncommitDzHandler implements DropzoneHandler {
158160 private readonly uiState = inject ( UI_STATE ) ;
161+ private readonly stackService = inject ( STACK_SERVICE ) ;
159162
160163 constructor (
161164 private projectId : string ,
162- private readonly stackService : StackService ,
163165 private readonly assignTo ?: string ,
164166 ) { }
165167
@@ -250,11 +252,11 @@ export class UncommitDzHandler implements DropzoneHandler {
250252 */
251253export class AmendCommitWithHunkDzHandler implements DropzoneHandler {
252254 private readonly uiState = inject ( UI_STATE ) ;
255+ private readonly stackService = inject ( STACK_SERVICE ) ;
256+ private readonly hooksService = inject ( HOOKS_SERVICE ) ;
253257
254258 constructor (
255259 private args : {
256- stackService : StackService ;
257- hooksService : HooksService ;
258260 okWithForce : boolean ;
259261 projectId : string ;
260262 stackId : string ;
@@ -276,7 +278,7 @@ export class AmendCommitWithHunkDzHandler implements DropzoneHandler {
276278 }
277279
278280 async ondrop ( data : HunkDropDataV3 ) : Promise < void > {
279- const { stackService , projectId, stackId, commit, okWithForce, runHooks } = this . args ;
281+ const { projectId, stackId, commit, okWithForce, runHooks } = this . args ;
280282 if ( ! okWithForce && commit . isRemote ) return ;
281283
282284 if ( data instanceof HunkDropDataV3 ) {
@@ -288,7 +290,7 @@ export class AmendCommitWithHunkDzHandler implements DropzoneHandler {
288290 throw new Error ( "Can't receive a change without it's source or commit" ) ;
289291 }
290292
291- const { replacedCommits } = await stackService . moveChangesBetweenCommits ( {
293+ const { replacedCommits } = await this . stackService . moveChangesBetweenCommits ( {
292294 projectId,
293295 destinationStackId : stackId ,
294296 destinationCommitId : commit . id ,
@@ -334,20 +336,20 @@ export class AmendCommitWithHunkDzHandler implements DropzoneHandler {
334336
335337 if ( runHooks ) {
336338 try {
337- await this . args . hooksService . runPreCommitHooks ( projectId , worktreeChanges ) ;
339+ await this . hooksService . runPreCommitHooks ( projectId , worktreeChanges ) ;
338340 } catch {
339341 return ;
340342 }
341343 }
342- stackService . amendCommitMutation ( {
344+ this . stackService . amendCommitMutation ( {
343345 projectId,
344346 stackId,
345347 commitId : commit . id ,
346348 worktreeChanges,
347349 } ) ;
348350 if ( runHooks ) {
349351 try {
350- await this . args . hooksService . runPostCommitHooks ( projectId ) ;
352+ await this . hooksService . runPostCommitHooks ( projectId ) ;
351353 } catch {
352354 return ;
353355 }
@@ -360,9 +362,10 @@ export class AmendCommitWithHunkDzHandler implements DropzoneHandler {
360362 * Handler that is able to squash two commits using `DzCommitData`.
361363 */
362364export class SquashCommitDzHandler implements DropzoneHandler {
365+ private readonly stackService = inject ( STACK_SERVICE ) ;
366+
363367 constructor (
364368 private args : {
365- stackService : StackService ;
366369 projectId : string ;
367370 stackId : string ;
368371 commit : DzCommitData ;
@@ -381,9 +384,9 @@ export class SquashCommitDzHandler implements DropzoneHandler {
381384 }
382385
383386 async ondrop ( data : unknown ) {
384- const { stackService , projectId, stackId, commit } = this . args ;
387+ const { projectId, stackId, commit } = this . args ;
385388 if ( data instanceof CommitDropData ) {
386- await stackService . squashCommits ( {
389+ await this . stackService . squashCommits ( {
387390 projectId,
388391 stackId,
389392 sourceCommitIds : [ data . commit . id ] ,
@@ -413,8 +416,6 @@ function updateUiState(
413416export function createCommitDropHandlers ( args : {
414417 projectId : string ;
415418 stackId : string | undefined ;
416- stackService : StackService ;
417- hooksService : HooksService ;
418419 commit : DzCommitData ;
419420 runHooks : boolean ;
420421 onCommitIdChange ?: ( newCommitId : string ) => void ;
@@ -436,27 +437,21 @@ export function createCommitDropHandlers(args: {
436437
437438 const amendHandler = new AmendCommitWithChangeDzHandler (
438439 args . projectId ,
439- args . stackService ,
440- args . hooksService ,
441440 stackId ,
442441 args . runHooks ,
443442 commit ,
444443 ( newId ) => {
445444 onCommitIdChange ?.( newId ) ;
446445 } ,
447- args . uiState ,
448446 ) ;
449447
450448 const squashHandler = new SquashCommitDzHandler ( {
451- stackService : args . stackService ,
452449 projectId : args . projectId ,
453450 stackId,
454451 commit,
455452 } ) ;
456453
457454 const hunkHandler = new AmendCommitWithHunkDzHandler ( {
458- stackService : args . stackService ,
459- hooksService : args . hooksService ,
460455 projectId : args . projectId ,
461456 stackId,
462457 commit,
0 commit comments