add redux initial state in eqlair
This commit is contained in:
parent
88e63695bf
commit
2f9f4527e8
6 changed files with 106 additions and 5 deletions
15
eqlair/package-lock.json
generated
15
eqlair/package-lock.json
generated
|
|
@ -14,6 +14,8 @@
|
|||
"@angular/forms": "^20.1.0",
|
||||
"@angular/platform-browser": "^20.1.0",
|
||||
"@angular/router": "^20.1.0",
|
||||
"@ngrx/store": "^20.0.0",
|
||||
"remixicon": "^4.6.0",
|
||||
"rxjs": "~7.8.0",
|
||||
"sae-lib": "file:../my-workspace/dist/sae-lib",
|
||||
"tslib": "^2.3.0",
|
||||
|
|
@ -2455,6 +2457,19 @@
|
|||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@ngrx/store": {
|
||||
"version": "20.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@ngrx/store/-/store-20.0.1.tgz",
|
||||
"integrity": "sha512-SWIHKe9lBoNf4rOklaWbCRAz8ie1Duf1iL4SMe6BipqhdUfJ/pEbcz3xMQUIlv1CciHhRgMJFTzFrDxamYHknQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "^2.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@angular/core": "^20.0.0",
|
||||
"rxjs": "^6.5.3 || ^7.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@npmcli/agent": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@npmcli/agent/-/agent-3.0.0.tgz",
|
||||
|
|
|
|||
|
|
@ -26,8 +26,11 @@
|
|||
"@angular/forms": "^20.1.0",
|
||||
"@angular/platform-browser": "^20.1.0",
|
||||
"@angular/router": "^20.1.0",
|
||||
"rxjs": "~7.8.0",
|
||||
|
||||
"tslib": "^2.3.0",
|
||||
"@ngrx/store": "^20.0.0",
|
||||
"remixicon": "^4.6.0",
|
||||
"rxjs": "~7.8.0",
|
||||
"zone.js": "~0.15.0",
|
||||
"sae-lib": "file:../my-workspace/dist/sae-lib"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core';
|
||||
import { provideStore } from '@ngrx/store';
|
||||
import { provideRouter } from '@angular/router';
|
||||
|
||||
import { routes } from './app.routes';
|
||||
import { reducers, metaReducers } from './redux/reducers';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideBrowserGlobalErrorListeners(),
|
||||
provideZoneChangeDetection({ eventCoalescing: true }),
|
||||
provideRouter(routes)
|
||||
provideRouter(routes),
|
||||
provideStore(reducers, { metaReducers })
|
||||
]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import {CommonModule} from '@angular/common';
|
||||
import {Component} from '@angular/core';
|
||||
import {Component, inject} from '@angular/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { ActionTypes, StateInterface } from '../../redux/reducers';
|
||||
import {MainButton} from 'sae-lib/buttons/main-button/main-button';
|
||||
import {WipBlock} from 'sae-lib/layouts/wip-block/wip-block';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Stepper} from 'sae-lib/stepper/stepper';
|
||||
|
||||
|
|
@ -9,7 +10,6 @@ import {Stepper} from 'sae-lib/stepper/stepper';
|
|||
selector: 'app-home',
|
||||
imports: [
|
||||
MainButton,
|
||||
WipBlock,
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
Stepper
|
||||
|
|
@ -18,8 +18,14 @@ import {Stepper} from 'sae-lib/stepper/stepper';
|
|||
styleUrl: './home.scss'
|
||||
})
|
||||
export class Home {
|
||||
|
||||
fromText: string = '';
|
||||
disableSearch: boolean = true;
|
||||
keywords: string = '';
|
||||
|
||||
constructor(private store: Store<StateInterface>) {
|
||||
this.store.dispatch({ type: ActionTypes.UPDATE_APP, payload: { demoMode: true } });
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
23
eqlair/src/app/redux/initialState.ts
Normal file
23
eqlair/src/app/redux/initialState.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
const initialState = {
|
||||
user: {
|
||||
isAuthenticated: false,
|
||||
id: '',
|
||||
login: '',
|
||||
token: ''
|
||||
},
|
||||
app: {
|
||||
demoMode: false,
|
||||
loading: false,
|
||||
backendAPIRoot: '',
|
||||
searchInput: '',
|
||||
filters: {
|
||||
|
||||
},
|
||||
fromText : '',
|
||||
toText : '',
|
||||
botMessage : '',
|
||||
},
|
||||
};
|
||||
|
||||
export default initialState;
|
||||
|
||||
51
eqlair/src/app/redux/reducers/index.ts
Normal file
51
eqlair/src/app/redux/reducers/index.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import { isDevMode } from '@angular/core';
|
||||
import { ActionReducerMap, MetaReducer } from '@ngrx/store';
|
||||
import initialState from '../initialState';
|
||||
|
||||
export enum ActionTypes {
|
||||
UPDATE_USER = '[User] Update User',
|
||||
UPDATE_APP = '[App] Update App',
|
||||
}
|
||||
|
||||
export interface UpdateUserAction {
|
||||
type: ActionTypes.UPDATE_USER;
|
||||
payload: Partial<typeof initialState.user>;
|
||||
}
|
||||
|
||||
export interface UpdateAppAction {
|
||||
type: ActionTypes.UPDATE_APP;
|
||||
payload: Partial<typeof initialState.app>;
|
||||
}
|
||||
|
||||
export type AppActions = UpdateUserAction | UpdateAppAction;
|
||||
|
||||
export interface StateInterface {
|
||||
user: typeof initialState.user;
|
||||
app: typeof initialState.app;
|
||||
}
|
||||
|
||||
function userReducer(state = initialState.user, action: AppActions) {
|
||||
switch (action.type) {
|
||||
case ActionTypes.UPDATE_USER:
|
||||
return { ...state, ...(action as UpdateUserAction).payload };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
function appReducer(state = initialState.app, action: AppActions) {
|
||||
switch (action.type) {
|
||||
case ActionTypes.UPDATE_APP:
|
||||
return { ...state, ...(action as UpdateAppAction).payload };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export const reducers: ActionReducerMap<StateInterface, AppActions> = {
|
||||
user: userReducer,
|
||||
app: appReducer,
|
||||
};
|
||||
|
||||
export const metaReducers: MetaReducer<StateInterface, AppActions>[] = isDevMode() ? [] : [];
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue