Archived
cokolwiek
This commit is contained in:
1 parent
5801ecfd29
commit
d8c8482696
36 files changed
+745
-508
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import { createAction, props } from '@ngrx/store';
|
||||
import { IssueModel } from 'src/app/models/issue.model';
|
||||
|
||||
export const receiveAllIssuesAction = createAction(
|
||||
'[issues] receive all issues'
|
||||
);
|
||||
export const receivedAllIssuesSuccessAction = createAction(
|
||||
'[issues] received all issues success',
|
||||
props<{ issues: IssueModel[] }>()
|
||||
);
|
||||
export const receivedAllIssuesErrorAction = createAction(
|
||||
'[issues] received all issues error'
|
||||
);
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Actions, createEffect, ofType } from '@ngrx/effects';
|
||||
import { first, switchMap } from 'rxjs';
|
||||
import { IssueModel } from 'src/app/models/issue.model';
|
||||
import { IssueService } from 'src/app/services/issues.service';
|
||||
import {
|
||||
receiveAllIssuesAction,
|
||||
receivedAllIssuesSuccessAction,
|
||||
} from '../actions/issue.actions';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class IssueEffect {
|
||||
preloadAutomaticOffer$ = createEffect(() => {
|
||||
return this.actions$.pipe(
|
||||
ofType(receiveAllIssuesAction),
|
||||
switchMap((action) => this.issueService.getIssues()),
|
||||
switchMap((issues: IssueModel[]) => [
|
||||
receivedAllIssuesSuccessAction({ issues }),
|
||||
]),
|
||||
first()
|
||||
);
|
||||
});
|
||||
|
||||
constructor(private actions$: Actions, private issueService: IssueService) {}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { createReducer, on } from '@ngrx/store';
|
||||
import { receivedAllIssuesSuccessAction } from '../actions/issue.actions';
|
||||
import { IssueState } from '../state/issue.state';
|
||||
|
||||
const initialState: IssueState = {
|
||||
issues: [
|
||||
{
|
||||
id: '1',
|
||||
cords: [18.57187, 54.40984],
|
||||
title: 'Dziura w drodze na Oliwi',
|
||||
createdAt: new Date(),
|
||||
description: 'Wielka dziura',
|
||||
photos: [],
|
||||
status: 'new',
|
||||
type: 'problem',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
cords: [18.58080765011577, 54.41806822519011],
|
||||
title: 'Dziura w drodze na Żabiance',
|
||||
createdAt: new Date(),
|
||||
description: 'Wielka dziura',
|
||||
photos: [],
|
||||
status: 'new',
|
||||
type: 'problem',
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
cords: [18.611836200396905, 54.405856587640585],
|
||||
title: 'Dziura w drodze na Nigdzie',
|
||||
createdAt: new Date(),
|
||||
description: 'Wielka dziura',
|
||||
photos: [],
|
||||
status: 'new',
|
||||
type: 'problem',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const issueReducer = createReducer(
|
||||
initialState,
|
||||
on(receivedAllIssuesSuccessAction, (state: IssueState, action) => ({
|
||||
issues: action.issues,
|
||||
}))
|
||||
);
|
||||
@@ -0,0 +1,9 @@
|
||||
import { createFeatureSelector, createSelector } from '@ngrx/store';
|
||||
import { IssueState } from '../state/issue.state';
|
||||
|
||||
const selectIssueFeatureState = createFeatureSelector<IssueState>('issueState');
|
||||
|
||||
export const selectAllIssues = createSelector(
|
||||
selectIssueFeatureState,
|
||||
(state) => state.issues
|
||||
);
|
||||
@@ -0,0 +1,5 @@
|
||||
import { IssueModel } from 'src/app/models/issue.model';
|
||||
|
||||
export interface IssueState {
|
||||
issues: IssueModel[];
|
||||
}
|
||||
Reference in new issue
Block a user