11import { Component , OnInit } from '@angular/core' ;
22import { select , Store } from '@ngrx/store' ;
3- import { Observable } from 'rxjs' ;
3+ import { Observable , of } from 'rxjs' ;
44import { delay } from 'rxjs/operators' ;
55import { getIsLoading } from 'src/app/modules/activities-management/store/activity-management.selectors' ;
66import { Activity } from '../../../shared/models' ;
77import { allActivities } from '../../store' ;
88import { DeleteActivity , LoadActivities , SetActivityToEdit } from './../../store/activity-management.actions' ;
99import { ActivityState } from './../../store/activity-management.reducers' ;
1010
11-
1211@Component ( {
1312 selector : 'app-activity-list' ,
1413 templateUrl : './activity-list.component.html' ,
1514 styleUrls : [ './activity-list.component.scss' ] ,
1615} )
1716export class ActivityListComponent implements OnInit {
17+ constructor ( private store : Store < ActivityState > ) {
18+ this . isLoading$ = store . pipe ( delay ( 0 ) , select ( getIsLoading ) ) ;
19+ }
1820 activities : Activity [ ] = [ ] ;
1921 showModal = false ;
2022 activityToDelete : Activity ;
2123 message : string ;
2224 idToDelete : string ;
2325 isLoading$ : Observable < boolean > ;
24- constructor ( private store : Store < ActivityState > ) {
25- this . isLoading$ = store . pipe ( delay ( 0 ) , select ( getIsLoading ) ) ;
26- }
2726
2827 ngOnInit ( ) {
2928 this . store . dispatch ( new LoadActivities ( ) ) ;
@@ -35,8 +34,9 @@ export class ActivityListComponent implements OnInit {
3534 }
3635
3736 deleteActivity ( ) {
38- this . store . dispatch ( new DeleteActivity ( this . idToDelete ) ) ;
39- this . showModal = true ;
37+ // this.store.dispatch(new DeleteActivity(this.idToDelete));
38+ console . log ( 'despachado el evento' ) ;
39+ this . showModal = false ;
4040 }
4141
4242 updateActivity ( activityId : string ) {
@@ -45,15 +45,26 @@ export class ActivityListComponent implements OnInit {
4545
4646 openModal ( item : Activity ) {
4747 this . idToDelete = item . id ;
48- this . message = `Are you sure you want to delete ${ item . name } ?` ;
48+ this . message = `Are you sure you want to archive activity ${ item . name } ?` ;
4949 this . showModal = true ;
50+ console . log ( `Despliegue del modal para id: ${ item . id } ` ) ;
51+ }
52+
53+ switchStatus ( evt : boolean , item : Activity ) : void {
54+ if ( ! evt ) {
55+ // FIXME: Si el usuario selecciona cancelar, se produce la animación de cambio
56+ // del switch
57+ this . openModal ( item ) ;
58+ } else {
59+ this . showModal = false ;
60+ // TODO: dispatch para actualizar la operacion
61+ // this.store.dispatch(new SetToTrueActivity());
62+ }
5063 }
5164
52- switchStatus ( state : string ) : void {
53- // this.store.dispatch(
54- // user.groups.includes(groupName)
55- // ? new RemoveUserFromGroup(user.id, groupName)
56- // : new AddUserToGroup(user.id, groupName)
57- // );
65+ OnSwitch ( item : Activity ) : Observable < boolean > {
66+ // FIXME: OnBeforeChange debería ser un evento que traiga el estado del switch
67+ // para poder realizar una acción antes de que el estado cambie.
68+ return of ( true ) ;
5869 }
5970}
0 commit comments