add ngrx store and effect
This commit is contained in:
@@ -19,6 +19,7 @@ export const appConfig: ApplicationConfig = {
|
|||||||
provideStore({
|
provideStore({
|
||||||
myStaffs: staffsReducer,
|
myStaffs: staffsReducer,
|
||||||
}),
|
}),
|
||||||
|
provideEffects([staffEffects]),
|
||||||
provideStoreDevtools({
|
provideStoreDevtools({
|
||||||
maxAge: 25,
|
maxAge: 25,
|
||||||
logOnly: !isDevMode()
|
logOnly: !isDevMode()
|
||||||
@@ -39,7 +40,7 @@ export const appConfig: ApplicationConfig = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
provideEffects([staffEffects])
|
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<!--[value]="userList"-->
|
<!--[value]="userList"-->
|
||||||
<p-table [value]="users" sortMode="multiple"
|
<p-table [value]="users()" sortMode="multiple"
|
||||||
class="p-datatable-sm" [loading]="loading">
|
class="p-datatable-sm" [loading]="loading">
|
||||||
<ng-template pTemplate="header">
|
<ng-template pTemplate="header">
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { FormsModule } from '@angular/forms';
|
|||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { ButtonModule } from 'primeng/button';
|
import { ButtonModule } from 'primeng/button';
|
||||||
import { InputTextModule } from 'primeng/inputtext';
|
import { InputTextModule } from 'primeng/inputtext';
|
||||||
import { selectStaffLoaded,selectState } from '../state/staff.selectors';
|
import { selectStaffLoaded,selectStaff } from '../state/staff.selectors';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'staff-list',
|
selector: 'staff-list',
|
||||||
@@ -31,9 +31,8 @@ export class StaffComponent implements OnInit, OnDestroy{
|
|||||||
lastname = '';
|
lastname = '';
|
||||||
loading = false;
|
loading = false;
|
||||||
userList:StaffView[] = [];
|
userList:StaffView[] = [];
|
||||||
appState = this.store.selectSignal(selectState);
|
users = this.store.selectSignal(selectStaff);
|
||||||
users = this.appState().staffs;
|
staffloadyet = this.store.selectSignal(selectStaffLoaded)
|
||||||
staffloadyet = this.appState().staffloaded;
|
|
||||||
private cd = inject(ChangeDetectorRef);
|
private cd = inject(ChangeDetectorRef);
|
||||||
msg ="[Staff component]";
|
msg ="[Staff component]";
|
||||||
|
|
||||||
@@ -101,8 +100,12 @@ export class StaffComponent implements OnInit, OnDestroy{
|
|||||||
|
|
||||||
const criteria = this.getSearchCiteria();
|
const criteria = this.getSearchCiteria();
|
||||||
this.staffService.searchCriteria = criteria;
|
this.staffService.searchCriteria = criteria;
|
||||||
console.log("search function store staffload yet",this.staffloadyet, this.users);
|
console.log("search function store staffload yet",this.staffloadyet(), this.users);
|
||||||
if (this.staffloadyet != true) {
|
if (this.staffloadyet() != true) {
|
||||||
|
this.store.dispatch(StaffsActions.loadStaff({criteria}));
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if (this.staffloadyet() != true) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
const loadStaff$ = this.staffService.searchStaffs(criteria);
|
const loadStaff$ = this.staffService.searchStaffs(criteria);
|
||||||
this.subscription.add(
|
this.subscription.add(
|
||||||
@@ -124,6 +127,7 @@ export class StaffComponent implements OnInit, OnDestroy{
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newUser():void {
|
newUser():void {
|
||||||
|
|||||||
@@ -10,6 +10,12 @@ import { StaffsActions, StaffsApiActions } from './staff.actions';
|
|||||||
import { StaffService } from '../staff/staff.service';
|
import { StaffService } from '../staff/staff.service';
|
||||||
import { StaffSearch } from '../models';
|
import { StaffSearch } from '../models';
|
||||||
|
|
||||||
|
/* how to use this load and put in store. then use selector to get slide of entity
|
||||||
|
|
||||||
|
this.store.dispatch(StaffsApiActions.loadStaff());
|
||||||
|
then using
|
||||||
|
selector to get from store
|
||||||
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class staffEffects {
|
export class staffEffects {
|
||||||
private actions$: Actions = inject(Actions);
|
private actions$: Actions = inject(Actions);
|
||||||
|
|||||||
Reference in New Issue
Block a user