add redux initial state in eqlair

This commit is contained in:
Tykayn 2025-10-14 10:27:55 +02:00 committed by tykayn
parent 88e63695bf
commit 2f9f4527e8
6 changed files with 106 additions and 5 deletions

View file

@ -14,6 +14,8 @@
"@angular/forms": "^20.1.0", "@angular/forms": "^20.1.0",
"@angular/platform-browser": "^20.1.0", "@angular/platform-browser": "^20.1.0",
"@angular/router": "^20.1.0", "@angular/router": "^20.1.0",
"@ngrx/store": "^20.0.0",
"remixicon": "^4.6.0",
"rxjs": "~7.8.0", "rxjs": "~7.8.0",
"sae-lib": "file:../my-workspace/dist/sae-lib", "sae-lib": "file:../my-workspace/dist/sae-lib",
"tslib": "^2.3.0", "tslib": "^2.3.0",
@ -2455,6 +2457,19 @@
"node": ">= 10" "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": { "node_modules/@npmcli/agent": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/@npmcli/agent/-/agent-3.0.0.tgz", "resolved": "https://registry.npmjs.org/@npmcli/agent/-/agent-3.0.0.tgz",

View file

@ -26,8 +26,11 @@
"@angular/forms": "^20.1.0", "@angular/forms": "^20.1.0",
"@angular/platform-browser": "^20.1.0", "@angular/platform-browser": "^20.1.0",
"@angular/router": "^20.1.0", "@angular/router": "^20.1.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0", "tslib": "^2.3.0",
"@ngrx/store": "^20.0.0",
"remixicon": "^4.6.0",
"rxjs": "~7.8.0",
"zone.js": "~0.15.0", "zone.js": "~0.15.0",
"sae-lib": "file:../my-workspace/dist/sae-lib" "sae-lib": "file:../my-workspace/dist/sae-lib"
}, },

View file

@ -1,12 +1,15 @@
import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core'; import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core';
import { provideStore } from '@ngrx/store';
import { provideRouter } from '@angular/router'; import { provideRouter } from '@angular/router';
import { routes } from './app.routes'; import { routes } from './app.routes';
import { reducers, metaReducers } from './redux/reducers';
export const appConfig: ApplicationConfig = { export const appConfig: ApplicationConfig = {
providers: [ providers: [
provideBrowserGlobalErrorListeners(), provideBrowserGlobalErrorListeners(),
provideZoneChangeDetection({ eventCoalescing: true }), provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(routes) provideRouter(routes),
provideStore(reducers, { metaReducers })
] ]
}; };

View file

@ -1,7 +1,8 @@
import {CommonModule} from '@angular/common'; 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 {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 {FormsModule} from '@angular/forms';
import {Stepper} from 'sae-lib/stepper/stepper'; import {Stepper} from 'sae-lib/stepper/stepper';
@ -9,7 +10,6 @@ import {Stepper} from 'sae-lib/stepper/stepper';
selector: 'app-home', selector: 'app-home',
imports: [ imports: [
MainButton, MainButton,
WipBlock,
CommonModule, CommonModule,
FormsModule, FormsModule,
Stepper Stepper
@ -18,8 +18,14 @@ import {Stepper} from 'sae-lib/stepper/stepper';
styleUrl: './home.scss' styleUrl: './home.scss'
}) })
export class Home { export class Home {
fromText: string = ''; fromText: string = '';
disableSearch: boolean = true; disableSearch: boolean = true;
keywords: string = ''; keywords: string = '';
constructor(private store: Store<StateInterface>) {
this.store.dispatch({ type: ActionTypes.UPDATE_APP, payload: { demoMode: true } });
}
} }

View 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;

View 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() ? [] : [];