Skip to content

Commit 0d0f882

Browse files
author
Guido Quezada
committed
TT-71 fix: spinner for loading (advances)
1 parent 2f675b2 commit 0d0f882

File tree

7 files changed

+64
-6
lines changed

7 files changed

+64
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"ngx-mask": "^9.1.2",
4646
"ngx-material-timepicker": "^5.5.3",
4747
"ngx-pagination": "^5.0.0",
48+
"ngx-spinner": "^10.0.1",
4849
"ngx-toastr": "^12.0.1",
4950
"rxjs": "~6.6.3",
5051
"tslib": "^1.10.0",

src/app/app.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
33
import { ToastrModule } from 'ngx-toastr';
44
import { CommonModule, DatePipe } from '@angular/common';
55
import { BrowserModule } from '@angular/platform-browser';
6-
import { NgModule, Component } from '@angular/core';
6+
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
77
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
88
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
99
import { DataTablesModule } from 'angular-datatables';
@@ -13,6 +13,7 @@ import { StoreDevtoolsModule } from '@ngrx/store-devtools';
1313

1414
import { NgxPaginationModule } from 'ngx-pagination';
1515
import { AutocompleteLibModule } from 'angular-ng-autocomplete';
16+
import { NgxSpinnerModule } from "ngx-spinner";
1617

1718
import { AppRoutingModule } from './app-routing.module';
1819
import { AppComponent } from './app.component';
@@ -139,6 +140,7 @@ const maskConfig: Partial<IConfig> = {
139140
ReactiveFormsModule,
140141
HttpClientModule,
141142
NgxPaginationModule,
143+
NgxSpinnerModule,
142144
DataTablesModule,
143145
AutocompleteLibModule,
144146
NgxMaterialTimepickerModule,
@@ -171,5 +173,6 @@ const maskConfig: Partial<IConfig> = {
171173
CookieService,
172174
],
173175
bootstrap: [AppComponent],
176+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
174177
})
175178
export class AppModule { }

src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ export class EntryFieldsComponent implements OnInit {
7272
this.store.dispatch(new entryActions.LoadEntriesSummary());
7373
} else {
7474
this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, ...this.entryForm.value }));
75-
this.store.dispatch(new LoadActiveEntry());
7675
this.store.dispatch(new entryActions.LoadEntriesSummary());
7776
}
7877
});

src/app/modules/time-clock/pages/time-clock.component.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<app-time-entries-summary></app-time-entries-summary>
2+
<ngx-spinner
3+
bdColor = "rgba(0, 0, 0, 0.7)"
4+
size = "default"
5+
type = "pacman"
6+
[fullScreen] = "true"
7+
>
8+
<p style="color: #ffff" > Loading... </p>
9+
</ngx-spinner>
210

311
<div class="col-12 col-md-9 px-0">
412

@@ -15,7 +23,7 @@
1523
</div>
1624

1725
<app-project-list-hover></app-project-list-hover>
18-
<div *ngIf="areFieldsVisible">
26+
<div *ngIf="areFieldsVisible"> <!-- no recomendable-->
1927
<app-entry-fields></app-entry-fields>
2028
</div>
2129

src/app/modules/time-clock/pages/time-clock.component.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { AzureAdB2CService } from '../../login/services/azure.ad.b2c.service';
77
import { EntryFieldsComponent } from '../components/entry-fields/entry-fields.component';
88
import { Entry } from './../../shared/models/entry.model';
99
import { EntryActionTypes, LoadEntriesSummary, StopTimeEntryRunning } from './../store/entry.actions';
10-
import { getActiveTimeEntry } from './../store/entry.selectors';
10+
import { getActiveTimeEntry, getIsLoading } from './../store/entry.selectors';
11+
import { NgxSpinnerService } from "ngx-spinner";
1112
@Component({
1213
selector: 'app-time-clock',
1314
templateUrl: './time-clock.component.html',
@@ -26,7 +27,8 @@ export class TimeClockComponent implements OnInit, OnDestroy {
2627
private azureAdB2CService: AzureAdB2CService,
2728
private store: Store<Entry>,
2829
private toastrService: ToastrService,
29-
private actionsSubject$: ActionsSubject
30+
private actionsSubject$: ActionsSubject,
31+
private spinner: NgxSpinnerService,
3032
) {}
3133

3234
ngOnDestroy(): void {
@@ -44,6 +46,14 @@ export class TimeClockComponent implements OnInit, OnDestroy {
4446
}
4547
});
4648

49+
this.store.pipe(select(getIsLoading)).subscribe((isLoading) => {
50+
if (isLoading) {
51+
this.spinner.show();
52+
} else {
53+
this.spinner.hide();
54+
}
55+
});
56+
4757
this.reloadSummariesOnClockOut();
4858

4959
}

src/app/modules/time-clock/store/entry.reducer.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { EntryActions, EntryActionTypes } from './entry.actions';
66
export interface EntryState {
77
active: Entry;
88
isLoading: boolean;
9+
isLoading2: boolean;
910
message: string;
1011
createError: boolean;
1112
updateError: boolean;
@@ -20,6 +21,7 @@ const emptyTimeEntriesSummary: TimeEntriesSummary = { day: emptyTimeDetails, wee
2021
export const initialState = {
2122
active: null,
2223
isLoading: false,
24+
isLoading2: false,
2325
message: '',
2426
createError: null,
2527
updateError: null,
@@ -56,19 +58,24 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
5658
return {
5759
...state,
5860
isLoading: true,
61+
isLoading2: true,
5962
};
6063
}
6164
case EntryActionTypes.LOAD_ACTIVE_ENTRY_SUCCESS:
6265
return {
6366
...state,
6467
active: action.payload,
6568
isLoading: false,
69+
isLoading2: false,
6670
};
6771
case EntryActionTypes.LOAD_ACTIVE_ENTRY_FAIL: {
72+
console.log('jjsjd');
73+
6874
return {
6975
...state,
7076
active: null,
7177
isLoading: false,
78+
isLoading2: false,
7279
message: 'Something went wrong fetching active entry!',
7380
};
7481
}
@@ -93,6 +100,8 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
93100
};
94101

95102
case EntryActionTypes.LOAD_ENTRIES_FAIL: {
103+
console.log('here');
104+
96105
return {
97106
...state,
98107
message: 'Something went wrong fetching entries!',
@@ -210,6 +219,7 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
210219
return {
211220
...state,
212221
isLoading: true,
222+
isLoading2: true,
213223
};
214224
}
215225

@@ -221,10 +231,27 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
221231
};
222232
}
223233

234+
case EntryActionTypes.UPDATE_ENTRY_RUNNING: {
235+
console.log('UPDATE_ENTRY_RUNNING ');
236+
237+
return {
238+
...state,
239+
isLoading2: true,
240+
};
241+
}
242+
243+
case EntryActionTypes.SWITCH_TIME_ENTRY: {
244+
return {
245+
...state,
246+
isLoading2: true,
247+
};
248+
}
249+
224250
case EntryActionTypes.STOP_TIME_ENTRY_RUNNING: {
225251
return {
226252
...state,
227253
isLoading: true,
254+
isLoading2: true,
228255
};
229256
}
230257

@@ -233,7 +260,15 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
233260
...state,
234261
active: null,
235262
isLoading: false,
236-
message: 'You clocked-out successfully',
263+
isLoading2: false,
264+
message: 'You clocked-out successfullys',
265+
};
266+
}
267+
268+
case EntryActionTypes.CLOCK_IN: {
269+
return {
270+
...state,
271+
isLoading2: true,
237272
};
238273
}
239274

src/app/modules/time-clock/store/entry.selectors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export const getActiveTimeEntry = createSelector(getEntryState, (state: EntrySta
99

1010
export const getCreateError = createSelector(getEntryState, (state: EntryState) => state?.createError);
1111

12+
export const getIsLoading = createSelector(getEntryState, (state: EntryState) => state?.isLoading2);
13+
1214
export const getUpdateError = createSelector(getEntryState, (state: EntryState) => state?.updateError);
1315

1416
export const getStatusMessage = createSelector(getEntryState, (state: EntryState) => state?.message);

0 commit comments

Comments
 (0)