diff --git a/eqlair/package-lock.json b/eqlair/package-lock.json index 7bd2699..a4c6930 100644 --- a/eqlair/package-lock.json +++ b/eqlair/package-lock.json @@ -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", diff --git a/eqlair/package.json b/eqlair/package.json index d01ee70..354e08a 100644 --- a/eqlair/package.json +++ b/eqlair/package.json @@ -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" }, diff --git a/eqlair/src/app/app.config.ts b/eqlair/src/app/app.config.ts index d953f4c..d0a8990 100644 --- a/eqlair/src/app/app.config.ts +++ b/eqlair/src/app/app.config.ts @@ -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 }) ] }; diff --git a/eqlair/src/app/pages/home/home.ts b/eqlair/src/app/pages/home/home.ts index ab78719..39dd4ce 100644 --- a/eqlair/src/app/pages/home/home.ts +++ b/eqlair/src/app/pages/home/home.ts @@ -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) { + this.store.dispatch({ type: ActionTypes.UPDATE_APP, payload: { demoMode: true } }); + } + + } diff --git a/eqlair/src/app/redux/initialState.ts b/eqlair/src/app/redux/initialState.ts new file mode 100644 index 0000000..14c56ff --- /dev/null +++ b/eqlair/src/app/redux/initialState.ts @@ -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; + diff --git a/eqlair/src/app/redux/reducers/index.ts b/eqlair/src/app/redux/reducers/index.ts new file mode 100644 index 0000000..3419bb9 --- /dev/null +++ b/eqlair/src/app/redux/reducers/index.ts @@ -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; +} + +export interface UpdateAppAction { + type: ActionTypes.UPDATE_APP; + payload: Partial; +} + +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 = { + user: userReducer, + app: appReducer, +}; + +export const metaReducers: MetaReducer[] = isDevMode() ? [] : []; +