Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
rules: {
'prettier/prettier': 'error',
'@typescript-eslint/consistent-type-imports': 'warn',
'@typescript-eslint/no-unused-vars': 'warn',
'react/jsx-indent': [1, 2],
'react/jsx-indent-props': [1, 2],
indent: [1, 2],
Expand All @@ -44,8 +45,9 @@ module.exports = {
],
'import/no-extraneous-dependencies': 'off',
'no-underscore-dangle': 'off',
// временно отключено, чтобы не было ошибок при использовании i18next
'i18next/no-literal-string': [
'error',
0,
{
markupOnly: true,
ignoreAttribute: ['data-testid', 'to'],
Expand Down
3 changes: 0 additions & 3 deletions extractedTranslations/en/about.json

This file was deleted.

8 changes: 4 additions & 4 deletions json-server/db.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"posts": [{ "id": 1, "title": "json-server", "author": "typicode" }],
"comments": [{ "id": 1, "body": "some comment", "postId": 1 }],
"users": [{ "id": 1, "username": "admin", "password": "123" }],
"profile": { "name": "typicode" }
"posts": [{ "id": 1, "title": "json-server", "author": "typicode" }],
"comments": [{ "id": 1, "body": "some comment", "postId": 1 }],
"users": [{ "id": 1, "username": "admin", "password": "123" }],
"profile": { "name": "typicode" }
}
3 changes: 2 additions & 1 deletion json-server/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable no-console */
const fs = require('fs');
const jsonServer = require('json-server');
const path = require('path');

const jsonServer = require('json-server');

const server = jsonServer.create();

const router = jsonServer.router(path.resolve(__dirname, 'db.json'));
Expand Down
234 changes: 117 additions & 117 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,119 +1,119 @@
{
"name": "production-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack serve --env port=3000",
"start:dev:server": "node ./json-server/index.js",
"build:prod": "webpack --env mode=production",
"build:dev": "webpack --env mode=development",
"lint:ts": "eslint \"**/*.{ts,tsx}\"",
"lint:ts:fix": "eslint \"**/*.{ts,tsx}\" --fix && prettier --write \"**/*.{ts,tsx}\"",
"lint:scss": "npx stylelint \"**/*.scss\"",
"lint:scss:fix": "npx stylelint \"**/*.scss\" --fix",
"prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,scss,css,json}\"",
"format": "npm run lint:ts:fix && npm run lint:scss:fix",
"test:unit": "jest --config ./config/jest/jest.config.ts",
"test:ui": "npx loki test --reactUri=http://host.docker.internal:6006",
"test:ui:ok": "npx loki approve",
"test:ui:ci": "npx loki test --requireReference --reactUri=file:./storybook-static",
"test:ui:report": "npm run test:ui:json && npm run test:ui:html",
"test:ui:json": "node scripts/generate-visual-json-report.js",
"test:ui:html": "reg-cli --from .loki/report.json --report .loki/report.html",
"storybook": "start-storybook -p 6006 -c ./config/storybook",
"storybook:build": "build-storybook -c ./config/storybook",
"prepare": "husky install"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.17.5",
"@babel/preset-env": "^7.16.11",
"@babel/preset-react": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@storybook/addon-actions": "^6.4.19",
"@storybook/addon-essentials": "^6.4.19",
"@storybook/addon-interactions": "^6.4.19",
"@storybook/addon-links": "^6.4.19",
"@storybook/builder-webpack5": "^6.4.19",
"@storybook/manager-webpack5": "^6.4.19",
"@storybook/react": "^6.4.19",
"@storybook/testing-library": "^0.0.9",
"@svgr/webpack": "^6.2.1",
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.3",
"@types/jest": "^27.4.1",
"@types/lodash": "4.14.202",
"@types/node": "^17.0.21",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"@types/react-router-dom": "^5.3.3",
"@types/webpack": "^5.28.0",
"@types/webpack-bundle-analyzer": "^4.4.1",
"@types/webpack-dev-server": "^4.7.2",
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"babel-loader": "^8.2.3",
"babel-plugin-i18next-extract": "^0.8.3",
"css-loader": "^6.6.0",
"eslint": "^8.10.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^10.1.5",
"eslint-plugin-i18next": "^5.1.2",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^5.4.1",
"eslint-plugin-react": "^7.29.2",
"eslint-plugin-react-hooks": "^4.3.0",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.5.0",
"husky": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^27.5.1",
"json-server": "^0.17.0",
"loki": "^0.28.1",
"mini-css-extract-plugin": "^2.5.3",
"prettier": "^3.5.3",
"reg-cli": "^0.17.6",
"regenerator-runtime": "^0.13.9",
"sass": "^1.49.9",
"sass-loader": "^12.6.0",
"style-loader": "^3.3.1",
"stylelint": "^14.5.3",
"stylelint-config-standard-scss": "^3.0.0",
"ts-loader": "^9.2.6",
"ts-node": "^10.5.0",
"typescript": "^4.5.5",
"webpack": "^5.69.1",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4"
},
"dependencies": {
"@reduxjs/toolkit": "1.8",
"axios": "^1.9.0",
"i18next": "^21.6.11",
"i18next-browser-languagedetector": "^6.1.3",
"i18next-http-backend": "^1.3.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-i18next": "^11.15.5",
"react-redux": "^7.2.6",
"react-router-dom": "^6.2.1"
},
"loki": {
"configurations": {
"chrome.laptop": {
"target": "chrome.docker",
"width": 1366,
"height": 768
},
"chrome.iphone7": {
"target": "chrome.docker",
"preset": "iPhone 7"
}
}
}
"name": "production-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack serve --env port=3000",
"start:dev:server": "node ./json-server/index.js",
"build:prod": "webpack --env mode=production",
"build:dev": "webpack --env mode=development",
"lint:ts": "eslint \"**/*.{ts,tsx}\"",
"lint:ts:fix": "prettier --write \"**/*.{ts,tsx}\" && eslint \"**/*.{ts,tsx}\" --fix",
"lint:scss": "npx stylelint \"**/*.scss\"",
"lint:scss:fix": "npx stylelint \"**/*.scss\" --fix",
"prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,scss,css,json}\"",
"format": "npm run lint:ts:fix && npm run lint:scss:fix",
"test:unit": "jest --config ./config/jest/jest.config.ts",
"test:ui": "npx loki test --reactUri=http://host.docker.internal:6006",
"test:ui:ok": "npx loki approve",
"test:ui:ci": "npx loki test --requireReference --reactUri=file:./storybook-static",
"test:ui:report": "npm run test:ui:json && npm run test:ui:html",
"test:ui:json": "node scripts/generate-visual-json-report.js",
"test:ui:html": "reg-cli --from .loki/report.json --report .loki/report.html",
"storybook": "start-storybook -p 6006 -c ./config/storybook",
"storybook:build": "build-storybook -c ./config/storybook",
"prepare": "husky install"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.17.5",
"@babel/preset-env": "^7.16.11",
"@babel/preset-react": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@storybook/addon-actions": "^6.4.19",
"@storybook/addon-essentials": "^6.4.19",
"@storybook/addon-interactions": "^6.4.19",
"@storybook/addon-links": "^6.4.19",
"@storybook/builder-webpack5": "^6.4.19",
"@storybook/manager-webpack5": "^6.4.19",
"@storybook/react": "^6.4.19",
"@storybook/testing-library": "^0.0.9",
"@svgr/webpack": "^6.2.1",
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.3",
"@types/jest": "^27.4.1",
"@types/lodash": "4.14.202",
"@types/node": "^17.0.21",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"@types/react-router-dom": "^5.3.3",
"@types/webpack": "^5.28.0",
"@types/webpack-bundle-analyzer": "^4.4.1",
"@types/webpack-dev-server": "^4.7.2",
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"babel-loader": "^8.2.3",
"babel-plugin-i18next-extract": "^0.8.3",
"css-loader": "^6.6.0",
"eslint": "^8.10.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^10.1.5",
"eslint-plugin-i18next": "^5.1.2",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^5.4.1",
"eslint-plugin-react": "^7.29.2",
"eslint-plugin-react-hooks": "^4.3.0",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.5.0",
"husky": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^27.5.1",
"json-server": "^0.17.0",
"loki": "^0.28.1",
"mini-css-extract-plugin": "^2.5.3",
"prettier": "^3.5.3",
"reg-cli": "^0.17.6",
"regenerator-runtime": "^0.13.9",
"sass": "^1.49.9",
"sass-loader": "^12.6.0",
"style-loader": "^3.3.1",
"stylelint": "^14.5.3",
"stylelint-config-standard-scss": "^3.0.0",
"ts-loader": "^9.2.6",
"ts-node": "^10.5.0",
"typescript": "^4.5.5",
"webpack": "^5.69.1",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4"
},
"dependencies": {
"@reduxjs/toolkit": "1.8",
"axios": "^1.9.0",
"i18next": "^21.6.11",
"i18next-browser-languagedetector": "^6.1.3",
"i18next-http-backend": "^1.3.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-i18next": "^11.15.5",
"react-redux": "^7.2.6",
"react-router-dom": "^6.2.1"
},
"loki": {
"configurations": {
"chrome.laptop": {
"target": "chrome.docker",
"width": 1366,
"height": 768
},
"chrome.iphone7": {
"target": "chrome.docker",
"preset": "iPhone 7"
}
}
}
}
1 change: 1 addition & 0 deletions src/app/providers/ErrorBoundary/ui/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
this.state = { hasError: false };
}

// eslint-disable-next-line
static getDerivedStateFromError(error: Error) {
// Update state so the next render will show the fallback UI.
return { hasError: true };
Expand Down
22 changes: 22 additions & 0 deletions src/app/providers/StoreProvider/config/StateSchema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
import type {
CombinedState,
AnyAction,
EnhancedStore,
Reducer,
ReducersMapObject,
} from '@reduxjs/toolkit';
import type { CounterSchema } from 'entities/Counter';
import type { UserSchema } from 'entities/User';
import type { LoginSchema } from 'features/AuthByUsername';

export interface StateSchema {
counter: CounterSchema;
user: UserSchema;

// Async reducers
loginForm?: LoginSchema;
}

export type StateSchemaKey = keyof StateSchema;

export interface ReducerManager {
getReducerMap: () => ReducersMapObject<StateSchema>;
reduce: (state: StateSchema, action: AnyAction) => CombinedState<StateSchema>;
add: (key: StateSchemaKey, reducer: Reducer) => void;
remove: (key: StateSchemaKey) => void;
}

export interface StoreWithManager extends EnhancedStore<StateSchema> {
reducerManager: ReducerManager;
}
44 changes: 44 additions & 0 deletions src/app/providers/StoreProvider/config/reducerManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { AnyAction, Reducer, ReducersMapObject } from '@reduxjs/toolkit';
import { combineReducers } from '@reduxjs/toolkit';

import type { ReducerManager, StateSchema, StateSchemaKey } from './StateSchema';

export function createReducerManager(
initialReducers: ReducersMapObject<StateSchema>,
): ReducerManager {
const reducers = { ...initialReducers };

let combinedReducer = combineReducers(reducers);

let keysToRemove: StateSchemaKey[] = [];

return {
getReducerMap: () => reducers,
reduce: (state: StateSchema, action: AnyAction) => {
if (keysToRemove.length > 0) {
state = { ...state };
keysToRemove.forEach((key) => {
delete state[key];
});
keysToRemove = [];
}
return combinedReducer(state, action);
},
add: (key: StateSchemaKey, reducer: Reducer) => {
if (!key || reducers[key]) {
return;
}
reducers[key] = reducer;

combinedReducer = combineReducers(reducers);
},
remove: (key: StateSchemaKey) => {
if (!key || !reducers[key]) {
return;
}
delete reducers[key];
keysToRemove.push(key);
combinedReducer = combineReducers(reducers);
},
};
}
14 changes: 10 additions & 4 deletions src/app/providers/StoreProvider/config/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@ import type { ReducersMapObject } from '@reduxjs/toolkit';
import { configureStore } from '@reduxjs/toolkit';
import { counterReducer } from 'entities/Counter';
import { userReducer } from 'entities/User';
import { loginReducer } from 'features/AuthByUsername';

import type { StateSchema } from './StateSchema';
import { createReducerManager } from './reducerManager';

export function createReduxStore(initialState?: StateSchema) {
const rootReducers: ReducersMapObject<StateSchema> = {
counter: counterReducer,
user: userReducer,
loginForm: loginReducer,
};

return configureStore<StateSchema>({
reducer: rootReducers,
const reducerManager = createReducerManager(rootReducers);

const store = configureStore<StateSchema>({
reducer: reducerManager.reduce,
devTools: __IS_DEV__,
preloadedState: initialState,
});

// @ts-ignore
store.reducerManager = reducerManager;

return store;
}
Loading