-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(frontend): undo when cancel drawing a line (#47)
* fix(frontend): undo when cancel drawing a line * style(frontend): fix Prettier issue * test(frontend): provide mock store & actions
- Loading branch information
1 parent
d58f637
commit 238fb8e
Showing
7 changed files
with
71 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import { createAction, props } from '@ngrx/store'; | ||
import { Tool } from '@talus/model'; | ||
|
||
export const selectTool = createAction('[toolsPanel] Select tool', props<{ id: Tool }>()); | ||
const actionTypePrefix = `[toolsPanel]`; | ||
|
||
export const selectTool = createAction(`${actionTypePrefix} Select tool`, props<{ id: Tool }>()); | ||
|
||
export const removeSelectionLinePreview = createAction( | ||
`${actionTypePrefix} Remove selection line preview`, | ||
); |
28 changes: 15 additions & 13 deletions
28
apps/frontend/src/app/tools-panel/tools-panel.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { select, Store } from '@ngrx/store'; | ||
import { filter, map, switchMap, withLatestFrom } from 'rxjs/operators'; | ||
import * as fromApp from '../app.reducer'; | ||
import { GridService } from '../scene-viewer-container/grid.service'; | ||
import { cancelLine, voxelsSet } from '../scene-viewer-container/scene-viewer-container.actions'; | ||
import { removeSelectionLinePreview, selectTool } from './tools-panel.actions'; | ||
|
||
@Injectable() | ||
export class ToolsPanelEffects { | ||
constructor( | ||
private actions$: Actions, | ||
private gridService: GridService, | ||
private store: Store<fromApp.State>, | ||
) {} | ||
|
||
selectTool$ = createEffect(() => | ||
this.actions$.pipe( | ||
ofType(selectTool), | ||
withLatestFrom(this.store.pipe(select(fromApp.selectSceneViewerContainerState))), | ||
filter(([_action, state]) => Boolean(state.selectedLineStartCoord)), | ||
map(() => removeSelectionLinePreview()), | ||
), | ||
); | ||
|
||
removeSelectionLinePreview$ = createEffect(() => | ||
this.actions$.pipe( | ||
ofType(removeSelectionLinePreview), | ||
withLatestFrom(this.store.pipe(select(fromApp.selectSceneViewerContainerState))), | ||
map(([_action, state]) => | ||
state.selectedLineChanges.map(change => | ||
this.gridService.setVoxel(change.xyz, change.oldValue), | ||
), | ||
), | ||
switchMap(voxelChanges => [voxelsSet({ voxelChanges }), cancelLine()]), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { EffectsModule } from '@ngrx/effects'; | ||
import { UiToolbarModule } from '@talus/ui'; | ||
import { GridService } from '../scene-viewer-container/grid.service'; | ||
import { ToolsPanelComponent } from './tools-panel.component'; | ||
import { ToolsPanelEffects } from './tools-panel.effects'; | ||
|
||
@NgModule({ | ||
declarations: [ToolsPanelComponent], | ||
imports: [CommonModule, UiToolbarModule], | ||
imports: [CommonModule, EffectsModule.forFeature([ToolsPanelEffects]), UiToolbarModule], | ||
providers: [GridService], | ||
exports: [ToolsPanelComponent], | ||
}) | ||
export class ToolsPanelModule {} |