From 9c4438b6f43e5b737194c31a7505ff46bfe39d2a Mon Sep 17 00:00:00 2001 From: Pavel Movchan Date: Mon, 17 Jan 2022 16:07:55 +0900 Subject: [PATCH 1/3] Added main functionality --- README.md | 47 +- package-lock.json | 412 ++++++++++++++++++ package.json | 3 + public/index.html | 25 +- public/logo192.png | Bin 4153 -> 0 bytes public/logo512.png | Bin 12066 -> 0 bytes public/manifest.json | 16 +- src/App.css | 39 -- src/App.js | 58 --- src/App.test.js | 15 - src/actions/actions.js | 46 ++ src/app/store.js | 8 - src/components/App/App.css | 0 src/components/App/App.js | 16 + src/components/App/store.js | 6 + src/components/Button/Button.js | 23 + src/components/CalcPalette/CalcPalette.css | 3 + src/components/CalcPalette/CalcPalette.js | 101 +++++ src/components/Desk/Desk.css | 40 ++ src/components/Desk/Desk.js | 151 +++++++ src/components/Digital-block/DigitalBlock.css | 15 + src/components/Digital-block/DigitalBlock.js | 48 ++ src/components/Display/Display.css | 17 + src/components/Display/Display.js | 33 ++ src/components/Equal-block/EqualBlock.css | 10 + src/components/Equal-block/EqualBlock.js | 36 ++ src/components/Operations/Operations.css | 12 + src/components/Operations/Operations.js | 45 ++ src/features/counter/Counter.js | 67 --- src/features/counter/Counter.module.css | 78 ---- src/features/counter/counterAPI.js | 6 - src/features/counter/counterSlice.js | 73 ---- src/features/counter/counterSlice.spec.js | 33 -- src/index.css | 13 - src/index.js | 21 +- src/logo.svg | 1 - src/reducers/CalcReducer.js | 141 ++++++ src/reducers/DragReducer.js | 68 +++ src/reducers/reducer.js | 11 + src/serviceWorker.js | 137 ------ src/setupTests.js | 5 - 41 files changed, 1250 insertions(+), 629 deletions(-) delete mode 100644 public/logo192.png delete mode 100644 public/logo512.png delete mode 100644 src/App.css delete mode 100644 src/App.js delete mode 100644 src/App.test.js create mode 100644 src/actions/actions.js delete mode 100644 src/app/store.js create mode 100644 src/components/App/App.css create mode 100644 src/components/App/App.js create mode 100644 src/components/App/store.js create mode 100644 src/components/Button/Button.js create mode 100644 src/components/CalcPalette/CalcPalette.css create mode 100644 src/components/CalcPalette/CalcPalette.js create mode 100644 src/components/Desk/Desk.css create mode 100644 src/components/Desk/Desk.js create mode 100644 src/components/Digital-block/DigitalBlock.css create mode 100644 src/components/Digital-block/DigitalBlock.js create mode 100644 src/components/Display/Display.css create mode 100644 src/components/Display/Display.js create mode 100644 src/components/Equal-block/EqualBlock.css create mode 100644 src/components/Equal-block/EqualBlock.js create mode 100644 src/components/Operations/Operations.css create mode 100644 src/components/Operations/Operations.js delete mode 100644 src/features/counter/Counter.js delete mode 100644 src/features/counter/Counter.module.css delete mode 100644 src/features/counter/counterAPI.js delete mode 100644 src/features/counter/counterSlice.js delete mode 100644 src/features/counter/counterSlice.spec.js delete mode 100644 src/index.css delete mode 100644 src/logo.svg create mode 100644 src/reducers/CalcReducer.js create mode 100644 src/reducers/DragReducer.js create mode 100644 src/reducers/reducer.js delete mode 100644 src/serviceWorker.js delete mode 100644 src/setupTests.js diff --git a/README.md b/README.md index f91225f..54c811b 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,7 @@ -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app), using the [Redux](https://redux.js.org/) and [Redux Toolkit](https://redux-toolkit.js.org/) template. +# Calc-constructor -## Available Scripts +This is small calc-constructor where you can : -In the project directory, you can run: - -### `npm start` - -Runs the app in the development mode.
-Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -The page will reload if you make edits.
-You will also see any lint errors in the console. - -### `npm test` - -Launches the test runner in the interactive watch mode.
-See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `npm run build` - -Builds the app for production to the `build` folder.
-It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.
-Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** - -If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. - -You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). +1. Drag elements from pallete to desk when constructor mode enabled; +2. Use calculator functional when constructor mode disabled; +3. Remove elements from desk on Double Click; diff --git a/package-lock.json b/package-lock.json index 76c2b54..f68fbad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1212,6 +1212,120 @@ "resolved": "https://registry.npmjs.org/@csstools/normalize.css/-/normalize.css-10.1.0.tgz", "integrity": "sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg==" }, + "@emotion/babel-plugin": { + "version": "11.7.2", + "resolved": "https://registry.npmjs.org/@emotion/babel-plugin/-/babel-plugin-11.7.2.tgz", + "integrity": "sha512-6mGSCWi9UzXut/ZAN6lGFu33wGR3SJisNl3c0tvlmb8XChH1b2SUvxvnOh7hvLpqyRdHHU9AiazV3Cwbk5SXKQ==", + "requires": { + "@babel/helper-module-imports": "^7.12.13", + "@babel/plugin-syntax-jsx": "^7.12.13", + "@babel/runtime": "^7.13.10", + "@emotion/hash": "^0.8.0", + "@emotion/memoize": "^0.7.5", + "@emotion/serialize": "^1.0.2", + "babel-plugin-macros": "^2.6.1", + "convert-source-map": "^1.5.0", + "escape-string-regexp": "^4.0.0", + "find-root": "^1.1.0", + "source-map": "^0.5.7", + "stylis": "4.0.13" + }, + "dependencies": { + "escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==" + } + } + }, + "@emotion/cache": { + "version": "11.7.1", + "resolved": "https://registry.npmjs.org/@emotion/cache/-/cache-11.7.1.tgz", + "integrity": "sha512-r65Zy4Iljb8oyjtLeCuBH8Qjiy107dOYC6SJq7g7GV5UCQWMObY4SJDPGFjiiVpPrOJ2hmJOoBiYTC7hwx9E2A==", + "requires": { + "@emotion/memoize": "^0.7.4", + "@emotion/sheet": "^1.1.0", + "@emotion/utils": "^1.0.0", + "@emotion/weak-memoize": "^0.2.5", + "stylis": "4.0.13" + } + }, + "@emotion/hash": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@emotion/hash/-/hash-0.8.0.tgz", + "integrity": "sha512-kBJtf7PH6aWwZ6fka3zQ0p6SBYzx4fl1LoZXE2RrnYST9Xljm7WfKJrU4g/Xr3Beg72MLrp1AWNUmuYJTL7Cow==" + }, + "@emotion/is-prop-valid": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-1.1.1.tgz", + "integrity": "sha512-bW1Tos67CZkOURLc0OalnfxtSXQJMrAMV0jZTVGJUPSOd4qgjF3+tTD5CwJM13PHA8cltGW1WGbbvV9NpvUZPw==", + "requires": { + "@emotion/memoize": "^0.7.4" + } + }, + "@emotion/memoize": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.7.5.tgz", + "integrity": "sha512-igX9a37DR2ZPGYtV6suZ6whr8pTFtyHL3K/oLUotxpSVO2ASaprmAe2Dkq7tBo7CRY7MMDrAa9nuQP9/YG8FxQ==" + }, + "@emotion/react": { + "version": "11.7.1", + "resolved": "https://registry.npmjs.org/@emotion/react/-/react-11.7.1.tgz", + "integrity": "sha512-DV2Xe3yhkF1yT4uAUoJcYL1AmrnO5SVsdfvu+fBuS7IbByDeTVx9+wFmvx9Idzv7/78+9Mgx2Hcmr7Fex3tIyw==", + "requires": { + "@babel/runtime": "^7.13.10", + "@emotion/cache": "^11.7.1", + "@emotion/serialize": "^1.0.2", + "@emotion/sheet": "^1.1.0", + "@emotion/utils": "^1.0.0", + "@emotion/weak-memoize": "^0.2.5", + "hoist-non-react-statics": "^3.3.1" + } + }, + "@emotion/serialize": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@emotion/serialize/-/serialize-1.0.2.tgz", + "integrity": "sha512-95MgNJ9+/ajxU7QIAruiOAdYNjxZX7G2mhgrtDWswA21VviYIRP1R5QilZ/bDY42xiKsaktP4egJb3QdYQZi1A==", + "requires": { + "@emotion/hash": "^0.8.0", + "@emotion/memoize": "^0.7.4", + "@emotion/unitless": "^0.7.5", + "@emotion/utils": "^1.0.0", + "csstype": "^3.0.2" + } + }, + "@emotion/sheet": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@emotion/sheet/-/sheet-1.1.0.tgz", + "integrity": "sha512-u0AX4aSo25sMAygCuQTzS+HsImZFuS8llY8O7b9MDRzbJM0kVJlAz6KNDqcG7pOuQZJmj/8X/rAW+66kMnMW+g==" + }, + "@emotion/styled": { + "version": "11.6.0", + "resolved": "https://registry.npmjs.org/@emotion/styled/-/styled-11.6.0.tgz", + "integrity": "sha512-mxVtVyIOTmCAkFbwIp+nCjTXJNgcz4VWkOYQro87jE2QBTydnkiYusMrRGFtzuruiGK4dDaNORk4gH049iiQuw==", + "requires": { + "@babel/runtime": "^7.13.10", + "@emotion/babel-plugin": "^11.3.0", + "@emotion/is-prop-valid": "^1.1.1", + "@emotion/serialize": "^1.0.2", + "@emotion/utils": "^1.0.0" + } + }, + "@emotion/unitless": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.7.5.tgz", + "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==" + }, + "@emotion/utils": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@emotion/utils/-/utils-1.0.0.tgz", + "integrity": "sha512-mQC2b3XLDs6QCW+pDQDiyO/EdGZYOygE8s5N5rrzjSI4M3IejPE/JPndCBwRT9z982aqQNi6beWs1UeayrQxxA==" + }, + "@emotion/weak-memoize": { + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/@emotion/weak-memoize/-/weak-memoize-0.2.5.tgz", + "integrity": "sha512-6U71C2Wp7r5XtFtQzYrW5iKFT67OixrSxjI4MptCHzdSVlgabczzqLe0ZSgnub/5Kp4hSbpDB1tMytZY9pwxxA==" + }, "@eslint/eslintrc": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.3.tgz", @@ -1795,6 +1909,112 @@ } } }, + "@mui/base": { + "version": "5.0.0-alpha.63", + "resolved": "https://registry.npmjs.org/@mui/base/-/base-5.0.0-alpha.63.tgz", + "integrity": "sha512-/jURXlBAYqZaWw92XfJgc6aiHnDcNVuRxBskub57HXWCMK3OiVVdfUEWJEdCjOacCKiw3+Etc5alI9Omaqrg2g==", + "requires": { + "@babel/runtime": "^7.16.3", + "@emotion/is-prop-valid": "^1.1.1", + "@mui/utils": "^5.2.3", + "@popperjs/core": "^2.4.4", + "clsx": "^1.1.1", + "prop-types": "^15.7.2", + "react-is": "^17.0.2" + }, + "dependencies": { + "react-is": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" + } + } + }, + "@mui/material": { + "version": "5.2.7", + "resolved": "https://registry.npmjs.org/@mui/material/-/material-5.2.7.tgz", + "integrity": "sha512-JaDl9GJSV17QLf4OoDUZKvVjZ/7UvqOBAxwLwUTnKZEME4REaGTkaAeHrzLpcKCm0LlNGD2HOKAIeykI6WJiqg==", + "requires": { + "@babel/runtime": "^7.16.3", + "@mui/base": "5.0.0-alpha.63", + "@mui/system": "^5.2.6", + "@mui/types": "^7.1.0", + "@mui/utils": "^5.2.3", + "@types/react-transition-group": "^4.4.4", + "clsx": "^1.1.1", + "csstype": "^3.0.10", + "hoist-non-react-statics": "^3.3.2", + "prop-types": "^15.7.2", + "react-is": "^17.0.2", + "react-transition-group": "^4.4.2" + }, + "dependencies": { + "react-is": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" + } + } + }, + "@mui/private-theming": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@mui/private-theming/-/private-theming-5.2.3.tgz", + "integrity": "sha512-Lc1Cmu8lSsYZiXADi9PBb17Ho82ZbseHQujUFAcp6bCJ5x/d+87JYCIpCBMagPu/isRlFCwbziuXPmz7WOzJPQ==", + "requires": { + "@babel/runtime": "^7.16.3", + "@mui/utils": "^5.2.3", + "prop-types": "^15.7.2" + } + }, + "@mui/styled-engine": { + "version": "5.2.6", + "resolved": "https://registry.npmjs.org/@mui/styled-engine/-/styled-engine-5.2.6.tgz", + "integrity": "sha512-bqAhli8eGS6v2qxivy2/4K0Ag8o//jsu1G2G6QcieFiT6y7oIF/nd/6Tvw6OSm3roOTifVQWNKwkt1yFWhGS+w==", + "requires": { + "@babel/runtime": "^7.16.3", + "@emotion/cache": "^11.7.1", + "prop-types": "^15.7.2" + } + }, + "@mui/system": { + "version": "5.2.6", + "resolved": "https://registry.npmjs.org/@mui/system/-/system-5.2.6.tgz", + "integrity": "sha512-PZ7bmpWOLikWgqn2zWv9/Xa7lxnRBOmfjoMH7c/IVYJs78W3971brXJ3xV9MEWWQcoqiYQeXzUJaNf4rFbKCBA==", + "requires": { + "@babel/runtime": "^7.16.3", + "@mui/private-theming": "^5.2.3", + "@mui/styled-engine": "^5.2.6", + "@mui/types": "^7.1.0", + "@mui/utils": "^5.2.3", + "clsx": "^1.1.1", + "csstype": "^3.0.10", + "prop-types": "^15.7.2" + } + }, + "@mui/types": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/@mui/types/-/types-7.1.0.tgz", + "integrity": "sha512-Hh7ALdq/GjfIwLvqH3XftuY3bcKhupktTm+S6qRIDGOtPtRuq2L21VWzOK4p7kblirK0XgGVH5BLwa6u8z/6QQ==" + }, + "@mui/utils": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@mui/utils/-/utils-5.2.3.tgz", + "integrity": "sha512-sQujlajIS0zQKcGIS6tZR0L1R+ib26B6UtuEn+cZqwKHsPo3feuS+SkdscYBdcCdMbrZs4gj8WIJHl2z6tbSzQ==", + "requires": { + "@babel/runtime": "^7.16.3", + "@types/prop-types": "^15.7.4", + "@types/react-is": "^16.7.1 || ^17.0.0", + "prop-types": "^15.7.2", + "react-is": "^17.0.2" + }, + "dependencies": { + "react-is": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" + } + } + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -1873,6 +2093,11 @@ } } }, + "@popperjs/core": { + "version": "2.11.2", + "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.2.tgz", + "integrity": "sha512-92FRmppjjqz29VMJ2dn+xdyXZBrMlE42AV6Kq6BwjWV7CNUW1hs2FtxSNLQE+gJhaZ6AAmYuO9y8dshhcBl7vA==" + }, "@reduxjs/toolkit": { "version": "1.6.2", "resolved": "https://registry.npmjs.org/@reduxjs/toolkit/-/toolkit-1.6.2.tgz", @@ -2437,6 +2662,14 @@ "@types/react": "*" } }, + "@types/react-is": { + "version": "17.0.3", + "resolved": "https://registry.npmjs.org/@types/react-is/-/react-is-17.0.3.tgz", + "integrity": "sha512-aBTIWg1emtu95bLTLx0cpkxwGW3ueZv71nE2YFBpL8k/z5czEW8yYpOo8Dp+UUAFAtKwNaOsh/ioSeQnWlZcfw==", + "requires": { + "@types/react": "*" + } + }, "@types/react-redux": { "version": "7.1.20", "resolved": "https://registry.npmjs.org/@types/react-redux/-/react-redux-7.1.20.tgz", @@ -2448,6 +2681,14 @@ "redux": "^4.0.0" } }, + "@types/react-transition-group": { + "version": "4.4.4", + "resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.4.tgz", + "integrity": "sha512-7gAPz7anVK5xzbeQW9wFBDg7G++aPLAFY0QaSMOou9rJZpbuI58WAuJrgu+qR92l61grlnCUe7AFX8KGahAgug==", + "requires": { + "@types/react": "*" + } + }, "@types/resolve": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-0.0.8.tgz", @@ -4340,6 +4581,11 @@ "wrap-ansi": "^6.2.0" } }, + "clsx": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/clsx/-/clsx-1.1.1.tgz", + "integrity": "sha512-6/bPho624p3S2pMyvP5kKBPXnI3ufHLObBFCfgx+LkeR5lg2XYy2hqZqUf45ypD8COn2bhgGJSUE+l5dhNBieA==" + }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -5321,6 +5567,15 @@ "utila": "~0.4" } }, + "dom-helpers": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-5.2.1.tgz", + "integrity": "sha512-nRCa7CK3VTrM2NmGkIy4cbK7IZlgBE/PYMn55rrXefr5xXDP0LdtfPnblFDoVdcAfslJ7or6iqAUnx0CCGIWQA==", + "requires": { + "@babel/runtime": "^7.8.7", + "csstype": "^3.0.2" + } + }, "dom-serializer": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.2.2.tgz", @@ -5472,6 +5727,11 @@ } } }, + "email-addresses": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/email-addresses/-/email-addresses-3.1.0.tgz", + "integrity": "sha512-k0/r7GrWVL32kZlGwfPNgB2Y/mMXVTq/decgLczm/j34whdaspNrZO8CnXPf1laaHxI6ptUlsnAxN+UAPw+fzg==" + }, "emittery": { "version": "0.7.2", "resolved": "https://registry.npmjs.org/emittery/-/emittery-0.7.2.tgz", @@ -6697,6 +6957,21 @@ } } }, + "filename-reserved-regex": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz", + "integrity": "sha1-q/c9+rc10EVECr/qLZHzieu/oik=" + }, + "filenamify": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/filenamify/-/filenamify-4.3.0.tgz", + "integrity": "sha512-hcFKyUG57yWGAzu1CMt/dPzYZuv+jAJUT85bL8mrXvNe6hWj6yEHEc4EdcgiA6Z3oi1/9wXJdZPXF2dZNgwgOg==", + "requires": { + "filename-reserved-regex": "^2.0.0", + "strip-outer": "^1.0.1", + "trim-repeated": "^1.0.0" + } + }, "filesize": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/filesize/-/filesize-6.1.0.tgz", @@ -6749,6 +7024,11 @@ "pkg-dir": "^3.0.0" } }, + "find-root": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/find-root/-/find-root-1.1.0.tgz", + "integrity": "sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==" + }, "find-up": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", @@ -7052,6 +7332,106 @@ "resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz", "integrity": "sha1-3BXKHGcjh8p2vTesCjlbogQqLCg=" }, + "gh-pages": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/gh-pages/-/gh-pages-3.2.3.tgz", + "integrity": "sha512-jA1PbapQ1jqzacECfjUaO9gV8uBgU6XNMV0oXLtfCX3haGLe5Atq8BxlrADhbD6/UdG9j6tZLWAkAybndOXTJg==", + "requires": { + "async": "^2.6.1", + "commander": "^2.18.0", + "email-addresses": "^3.0.1", + "filenamify": "^4.3.0", + "find-cache-dir": "^3.3.1", + "fs-extra": "^8.1.0", + "globby": "^6.1.0" + }, + "dependencies": { + "array-union": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz", + "integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=", + "requires": { + "array-uniq": "^1.0.1" + } + }, + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + }, + "find-cache-dir": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.2.tgz", + "integrity": "sha512-wXZV5emFEjrridIgED11OoUKLxiYjAcqot/NJdAkOhlJ+vGzwhOAfcG5OX1jP+S0PcjEn8bdMJv+g2jwQ3Onig==", + "requires": { + "commondir": "^1.0.1", + "make-dir": "^3.0.2", + "pkg-dir": "^4.1.0" + } + }, + "fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "globby": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-6.1.0.tgz", + "integrity": "sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=", + "requires": { + "array-union": "^1.0.1", + "glob": "^7.0.3", + "object-assign": "^4.0.1", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0" + } + }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "requires": { + "graceful-fs": "^4.1.6" + } + }, + "make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "requires": { + "semver": "^6.0.0" + } + }, + "pify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=" + }, + "pkg-dir": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", + "integrity": "sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==", + "requires": { + "find-up": "^4.0.0" + } + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + }, + "universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" + } + } + }, "glob": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", @@ -12448,6 +12828,17 @@ "workbox-webpack-plugin": "5.1.4" } }, + "react-transition-group": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.2.tgz", + "integrity": "sha512-/RNYfRAMlZwDSr6z4zNKV6xu53/e2BuaBbGhbyYIXTrmgu/bGHzmqOs7mJSJBHy9Ud+ApHx3QjrkKSp1pxvlFg==", + "requires": { + "@babel/runtime": "^7.5.5", + "dom-helpers": "^5.0.1", + "loose-envify": "^1.4.0", + "prop-types": "^15.6.2" + } + }, "read-pkg": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.2.0.tgz", @@ -14000,6 +14391,14 @@ "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==" }, + "strip-outer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/strip-outer/-/strip-outer-1.0.1.tgz", + "integrity": "sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==", + "requires": { + "escape-string-regexp": "^1.0.2" + } + }, "style-loader": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/style-loader/-/style-loader-1.3.0.tgz", @@ -14031,6 +14430,11 @@ } } }, + "stylis": { + "version": "4.0.13", + "resolved": "https://registry.npmjs.org/stylis/-/stylis-4.0.13.tgz", + "integrity": "sha512-xGPXiFVl4YED9Jh7Euv2V220mriG9u4B2TA6Ybjc1catrstKD2PpIdU3U0RKpkVBC2EhmL/F0sPCr9vrFTNRag==" + }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -14424,6 +14828,14 @@ "punycode": "^2.1.1" } }, + "trim-repeated": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/trim-repeated/-/trim-repeated-1.0.0.tgz", + "integrity": "sha1-42RqLqTokTEr9+rObPsFOAvAHCE=", + "requires": { + "escape-string-regexp": "^1.0.2" + } + }, "tryer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/tryer/-/tryer-1.0.1.tgz", diff --git a/package.json b/package.json index c81b062..9432a1d 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "0.1.0", "private": true, "dependencies": { + "@emotion/react": "^11.7.1", + "@emotion/styled": "^11.6.0", + "@mui/material": "^5.2.7", "@reduxjs/toolkit": "^1.6.2", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.5.0", diff --git a/public/index.html b/public/index.html index 1dbdca6..0f8a4af 100644 --- a/public/index.html +++ b/public/index.html @@ -9,35 +9,12 @@ name="description" content="Web site created using create-react-app" /> - - + - React Redux App
- diff --git a/public/logo192.png b/public/logo192.png deleted file mode 100644 index 33624109cdc98874ea8657a2a3a7ce71c81d1837..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4153 zcmbtY`8U*!_kX{~V1@=W)+B~T_AJ@5WX3*ZiLy^A#RySCnlN_qh%8C6RhF`)(1h%I zWC@Wn_I(h8&|vWK{0raj53hUg>z;dmd7X35z30YTTbdv^ggF2JK;TUcZH|1?e}J(a zS({OB_9F-PGj;R_0Dk@d02)>5*8l+bGTsn(={|LZU~yOYE9$^lnY3w%o`+6nV>KP# z^U$HUva$Eu@2;h!ufs>R!uum6r-l%dP!vmFZ z^-OXH#`sID8365GK%V`SS0M0yy4oS>3gtZp+o7)qTGv0|I%wx5->VcYqfjweY5g#` zD+e0%`_b2^3z&lPp8Tf3M1)?z>lHOk4*2{i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&^%6aaG15x9n)X zCp1eZIdwEl9)5UH)%ADFLG z%RNQL+5Xf#Aw`zI;ACKazU7auJ$^>AgLB6_kfPb?>ueWN&chc)(UIvsdnNIwYOpw& z6~*VI65VQ$!i!sJ3-1%WkK+7T!FUMYu$^Ps_>ggVz)T<7DC9}yBrrasno#i08y&z6 z_44lY+mVPlHFD&)wungRu4Cc?VftQf9s!U4eR9?9s{C}-v{rD5`<5Bdg}JYAi8Sk2 z)S~r!omBS}46T`#J_wZgU7-=;=pmbsUvft}ElT=PNKc3ypJBvrgP~(yNXqYv%j~_zJ5_&)Rv!gsJ#!A#9 zCEA3Xg3oO&rQf7UM|>ZQDI~Q{B(dU7-exl*+YhppE2u4D8Y-xrIh+^6LTm~{^v zhoq^8z(`xF7M>pmpVsJo5VajFk=_F79vT->lRv&ly~|a2AMO!PutU_C&}TfX3Pf2O z=b-oJ*f7Pp4@#B?JR~+V>33P-aS8UY8=7gQljrYcK6(U5btpCWw#wQMznV_=NvKzw zK0m3JnKm@r8EIo0!Zo_e2Y#clh72=97XxmhX~~JB3Ge=Wxbs@GSXdL?hHMmlYgA`h zCJy93F4(QO!rB?@tj(lOY0JsQ#yGHyE@j7`@ diff --git a/public/logo512.png b/public/logo512.png deleted file mode 100644 index b3516222f0b978579b871c871b955b5fc5b4ca5e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12066 zcmb_?={uC)|M;0P7$!_*$v%Z7p;X8^k&tYOtf5V0CuEyJO4dlJtVOm6+1D9Lq>z1Y zY&CYqlCjLp_xAn+eh+@v=fQp5XXc#yb9f%y&dJ_i5;^e$bz?mx0LZsa8}Soe)0ng4V06ZQ`CF=^x6 zBl2j=&{g&roddB?V`6S#%EK~YS|>Z$;nK*$2}$!zmD%JYDv1XU1=B+`%s$QhZtueO zZtSLRrK;0C<3z}^h`i-um%<^Tab|APS@0t1lH^S>CtAUM$Z0Qesa_UVn;hxPwI z@c%6*1jo32S$;2*FXhDOdPN(qQ(h|`(X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ew zZit?tOeK6+H;6BiSVC>L(`ij~TbE`gH~^1D1^%TymNfYZ<$uuX-8Wj$3kE$Y450fR0KX6G|1p5CGHgWJRSg^YclKB6X&YYpq-h`ae-rA4 A^#A|> diff --git a/public/manifest.json b/public/manifest.json index 080d6c7..0452f8c 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -2,21 +2,7 @@ "short_name": "React App", "name": "Create React App Sample", "icons": [ - { - "src": "favicon.ico", - "sizes": "64x64 32x32 24x24 16x16", - "type": "image/x-icon" - }, - { - "src": "logo192.png", - "type": "image/png", - "sizes": "192x192" - }, - { - "src": "logo512.png", - "type": "image/png", - "sizes": "512x512" - } + ], "start_url": ".", "display": "standalone", diff --git a/src/App.css b/src/App.css deleted file mode 100644 index 01cc586..0000000 --- a/src/App.css +++ /dev/null @@ -1,39 +0,0 @@ -.App { - text-align: center; -} - -.App-logo { - height: 40vmin; - pointer-events: none; -} - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-float infinite 3s ease-in-out; - } -} - -.App-header { - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); -} - -.App-link { - color: rgb(112, 76, 182); -} - -@keyframes App-logo-float { - 0% { - transform: translateY(0); - } - 50% { - transform: translateY(10px); - } - 100% { - transform: translateY(0px); - } -} diff --git a/src/App.js b/src/App.js deleted file mode 100644 index a40f66d..0000000 --- a/src/App.js +++ /dev/null @@ -1,58 +0,0 @@ -import React from 'react'; -import logo from './logo.svg'; -import { Counter } from './features/counter/Counter'; -import './App.css'; - -function App() { - return ( -
-
- logo - -

- Edit src/App.js and save to reload. -

- - Learn - - React - - , - - Redux - - , - - Redux Toolkit - - , and - - React Redux - - -
-
- ); -} - -export default App; diff --git a/src/App.test.js b/src/App.test.js deleted file mode 100644 index 659cc13..0000000 --- a/src/App.test.js +++ /dev/null @@ -1,15 +0,0 @@ -import React from 'react'; -import { render } from '@testing-library/react'; -import { Provider } from 'react-redux'; -import { store } from './app/store'; -import App from './App'; - -test('renders learn react link', () => { - const { getByText } = render( - - - - ); - - expect(getByText(/learn/i)).toBeInTheDocument(); -}); diff --git a/src/actions/actions.js b/src/actions/actions.js new file mode 100644 index 0000000..f60a6c4 --- /dev/null +++ b/src/actions/actions.js @@ -0,0 +1,46 @@ +const addDigit = (payload) => { + return { type: 'ADD_DIGIT', payload: payload }; +}; + +const chooseOperation = (payload) => { + return { type: 'CHOOSE_OPERATION', payload: payload }; +}; + +const setBlocks = (payload) => { + return { type: 'SET_BLOCKS', payload: payload }; +}; + +const setDraggableBlock = (payload) => { + return { type: 'SET_DRAGGABLE_BLOCK', payload: payload }; +}; + +const evaluate = () => { + return { type: 'EVALUATE' }; +}; + +const dragEnd = () => { + return { type: 'DRAG_END' }; +}; + +const dragging = (payload) => { + return { type: 'DRAG_START', payload: payload }; +}; + +const setDroppableSection = (payload) => { + return { type: 'SET_DROPPABLE_SECTION', payload: payload }; +}; + +const changeConstructorMode = () => { + return { type: 'CHANGE_CONSTRUCTOR_MODE' }; +}; +export { + addDigit, + chooseOperation, + evaluate, + dragging, + setDroppableSection, + changeConstructorMode, + dragEnd, + setBlocks, + setDraggableBlock, +}; diff --git a/src/app/store.js b/src/app/store.js deleted file mode 100644 index 9eca6d2..0000000 --- a/src/app/store.js +++ /dev/null @@ -1,8 +0,0 @@ -import { configureStore } from '@reduxjs/toolkit'; -import counterReducer from '../features/counter/counterSlice'; - -export const store = configureStore({ - reducer: { - counter: counterReducer, - }, -}); diff --git a/src/components/App/App.css b/src/components/App/App.css new file mode 100644 index 0000000..e69de29 diff --git a/src/components/App/App.js b/src/components/App/App.js new file mode 100644 index 0000000..742586b --- /dev/null +++ b/src/components/App/App.js @@ -0,0 +1,16 @@ +import React from 'react'; +import CalcPalette from '../CalcPalette/CalcPalette'; +import Desk from '../Desk/Desk'; + +import './App.css'; + +function App() { + return ( +
+ + +
+ ); +} + +export default App; diff --git a/src/components/App/store.js b/src/components/App/store.js new file mode 100644 index 0000000..1bdbfc3 --- /dev/null +++ b/src/components/App/store.js @@ -0,0 +1,6 @@ +import { createStore } from 'redux'; +import reducer from '../../reducers/reducer'; + +const store = createStore(reducer); + +export default store; diff --git a/src/components/Button/Button.js b/src/components/Button/Button.js new file mode 100644 index 0000000..8547be8 --- /dev/null +++ b/src/components/Button/Button.js @@ -0,0 +1,23 @@ +import React from 'react'; +import { connect } from 'react-redux'; +import { addDigit } from '../../actions/actions'; + +const Button = ({ className, value, clickHandle }) => { + return ( +
+ {value} +
+ ); +}; + +const mapDispatchToProps = (dispatch) => { + return { + addDigit: (newValue) => { + dispatch(addDigit(newValue)); + }, + }; +}; + +export default connect(() => { + return {}; +}, mapDispatchToProps)(Button); diff --git a/src/components/CalcPalette/CalcPalette.css b/src/components/CalcPalette/CalcPalette.css new file mode 100644 index 0000000..49d244a --- /dev/null +++ b/src/components/CalcPalette/CalcPalette.css @@ -0,0 +1,3 @@ +.calc-palete { + gap: 10px; +} \ No newline at end of file diff --git a/src/components/CalcPalette/CalcPalette.js b/src/components/CalcPalette/CalcPalette.js new file mode 100644 index 0000000..08916af --- /dev/null +++ b/src/components/CalcPalette/CalcPalette.js @@ -0,0 +1,101 @@ +import React, { useState } from 'react'; +import { + dragEnd, + dragging, + setDroppableSection, + setBlocks, +} from '../../actions/actions'; +import { connect } from 'react-redux'; +import './CalcPalette.css'; + +const CalcPalette = ({ + draggableBlock, + droppableSection, + dragging, + constructorModeEnable, + setDroppableSection, + dragEnd, + blocks, + setBlocks, +}) => { + const [index, setIndex] = useState(null); + + const dragOverHandler = (e) => { + e.preventDefault(); + }; + + const dragStartHandler = (e, item) => { + const elemIdx = blocks.indexOf(item); + if (constructorModeEnable) { + setIndex(elemIdx); + dragging(item); + setTimeout(() => (e.target.style.visibility = 'hidden'), 50); + } + return; + }; + + const dragEndHandler = (e) => { + e.preventDefault(); + if (droppableSection) { + const updatedState = [ + ...blocks.slice(0, index), + ...blocks.slice(index + 1), + ]; + setBlocks(updatedState); + setDroppableSection(null); + } + dragEnd(); + e.target.style.visibility = 'visible'; + }; + + const dropHandler = (e) => { + e.preventDefault(); + if (droppableSection) { + return; + } + + const updatedState = [ + ...blocks.slice(0, index - 1), + draggableBlock, + ...blocks.slice(index), + ]; + setBlocks(updatedState); + }; + + return ( +
+ {blocks.map((block) => ( + dragOverHandler(e)} + onDragStart={(e) => dragStartHandler(e, block)} + onDragEnd={(e) => dragEndHandler(e)} + onDrop={(e) => dropHandler(e)} + /> + ))} +
+ ); +}; + +const mapStateToProps = ({ + drag: { draggableBlock, droppableSection, constructorModeEnable, blocks }, +}) => { + return { + draggableBlock: draggableBlock, + droppableSection: droppableSection, + constructorModeEnable: constructorModeEnable, + blocks: blocks, + }; +}; + +const mapDispatchToProps = (dispatch) => { + return { + dragging: (element) => dispatch(dragging(element)), + setDroppableSection: (section) => dispatch(setDroppableSection(section)), + dragEnd: () => dispatch(dragEnd()), + setBlocks: (blocks) => dispatch(setBlocks(blocks)), + }; +}; + +export default connect(mapStateToProps, mapDispatchToProps)(CalcPalette); diff --git a/src/components/Desk/Desk.css b/src/components/Desk/Desk.css new file mode 100644 index 0000000..02b0b79 --- /dev/null +++ b/src/components/Desk/Desk.css @@ -0,0 +1,40 @@ +.desk { + border: 2px dashed blue; + height: 500px; + width: 300px; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +.desk-item { + flex-basis: 33%; + padding-top: 20px; + width: 100%; + padding-left:50px ; + display: flex; + flex-direction: column; + gap: 20px; +} + +.desk h5 { + font-size: 15px; + color: blue; + text-align: center; + position: absolute; +} + +.desk p { + font-weight: 300; +} + +.right-side { + display: flex; + flex-direction: column; + align-items: center; +} + +.deskInfo { + z-index: -1; +} \ No newline at end of file diff --git a/src/components/Desk/Desk.js b/src/components/Desk/Desk.js new file mode 100644 index 0000000..3568257 --- /dev/null +++ b/src/components/Desk/Desk.js @@ -0,0 +1,151 @@ +import React, { useState } from 'react'; +import { connect } from 'react-redux'; +import { + changeConstructorMode, + setDroppableSection, + dragEnd, + setBlocks, + setDraggableBlock, +} from '../../actions/actions'; +import FormGroup from '@mui/material/FormGroup'; +import FormControlLabel from '@mui/material/FormControlLabel'; +import Switch from '@mui/material/Switch'; +import './Desk.css'; + +const Desk = ({ + draggableBlock, + setDroppableSection, + changeConstructorMode, + constructorModeEnable, + blocks, + setBlocks, + setDraggableBlock, +}) => { + const [desk, setDesk] = useState([ + { id: 1, section: 'top', items: [] }, + { id: 2, section: 'middle', items: [] }, + { id: 3, section: 'bottom', items: [] }, + ]); + + const [filled, setFill] = useState(false); + + const dragOverHandler = (e, section) => { + e.preventDefault(); + if (e.target.className === 'desk-item') { + e.target.style.backgroundColor = 'rgba(0, 159, 249, 0.4)'; + } + setDroppableSection(section); + }; + + const removeBlockFromDesk = (block, section) => { + if (!constructorModeEnable) { + return; + } + setDraggableBlock(block); + const blockIndex = section.items.indexOf(block); + const sectionIndex = desk.findIndex( + (item) => item.section === section.section + ); + + const updatedPalette = [ + ...blocks.slice(0, block.id - 1), + block, + ...blocks.slice(block.id - 1), + ]; + + setDesk((state) => { + const newDesk = state.slice(); + newDesk[sectionIndex].items.splice(blockIndex, 1); + return newDesk; + }); + setBlocks(updatedPalette); + setDraggableBlock(null); + }; + + const dropHandler = (e, section) => { + e.preventDefault(); + if (e.target.className === 'desk-item') { + e.target.style.backgroundColor = ''; + } + + if (!draggableBlock) { + return; + } + + const itemId = desk.indexOf(section); + + setDesk((state) => { + let newState = state.slice(); + newState[itemId].items.push(draggableBlock); + return newState; + }); + dragEnd(); + setFill(true); + }; + + const dragLeaveHandler = (e) => { + e.preventDefault(); + if (e.target.className === 'desk-item') { + e.target.style.backgroundColor = ''; + } + setDroppableSection(null); + }; + + return ( +
+ + } + label={`Constructor Mode ${constructorModeEnable ? 'On' : 'Off'}`} + /> + +
+ {desk.map((section) => ( +
dragOverHandler(e, section)} + onDragLeave={(e) => dragLeaveHandler(e)} + onDrop={(e) => dropHandler(e, section)} + className="desk-item" + > + {section.items.map((item) => ( + removeBlockFromDesk(item, section)} + draggable={false} + /> + ))} +
+ ))} + {filled ? null : ( +
+ Перетащите сюда +

любой элемент из левой панели

+
+ )} +
+
+ ); +}; + +const mapStateToProps = ({ + drag: { draggableBlock, constructorModeEnable, blocks }, +}) => { + return { + draggableBlock: draggableBlock, + constructorModeEnable: constructorModeEnable, + blocks: blocks, + }; +}; + +const mapDispatchToProps = (dispatch) => { + return { + setDroppableSection: (section) => dispatch(setDroppableSection(section)), + changeConstructorMode: () => dispatch(changeConstructorMode()), + dragEnd: () => dispatch(dragEnd()), + setBlocks: (blocks) => dispatch(setBlocks(blocks)), + setDraggableBlock: (block) => dispatch(setDraggableBlock(block)), + }; +}; + +export default connect(mapStateToProps, mapDispatchToProps)(Desk); diff --git a/src/components/Digital-block/DigitalBlock.css b/src/components/Digital-block/DigitalBlock.css new file mode 100644 index 0000000..0e92b84 --- /dev/null +++ b/src/components/Digital-block/DigitalBlock.css @@ -0,0 +1,15 @@ +.digital-block { + display: grid; + padding: 5px; + border-radius: 5px; + height: 200px; + width: 200px; + grid-template-columns: 1fr 1fr 1fr; + grid-gap: 5px; + box-shadow: 0 3px 2px rgba(0,0,0,0.2); +} + +.numbers_0 { + grid-column-start: 1; + grid-column-end: 3; +} \ No newline at end of file diff --git a/src/components/Digital-block/DigitalBlock.js b/src/components/Digital-block/DigitalBlock.js new file mode 100644 index 0000000..c68a277 --- /dev/null +++ b/src/components/Digital-block/DigitalBlock.js @@ -0,0 +1,48 @@ +import React from 'react'; +import Button from '../Button/Button'; +import { connect } from 'react-redux'; +import { addDigit } from '../../actions/actions'; +import './DigitalBlock.css'; + +const DigitalBlock = ({ + onDragEnd, + onDragStart, + addDigit, + draggable, + onDblClick, +}) => { + const numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.']; + + return ( +
+ {numbers.map((item) => ( +
+ ); +}; + +const mapStateToProps = (state) => { + return state; +}; + +const mapDispatchToProps = (dispatch) => { + return { + addDigit: (digit) => { + dispatch(addDigit(digit)); + }, + }; +}; + +export default connect(mapStateToProps, mapDispatchToProps)(DigitalBlock); diff --git a/src/components/Display/Display.css b/src/components/Display/Display.css new file mode 100644 index 0000000..625fa2e --- /dev/null +++ b/src/components/Display/Display.css @@ -0,0 +1,17 @@ +.display { + border-radius: 5px; + box-shadow: 0 3px 2px rgba(0,0,0,0.2); + padding: 5px; + width: 200px; +} + +.display_text-field { + background-color: gray; + border-radius: 5px; + padding: 5px; +} + +.display_text-field h3 { + margin: 0; + text-align: end; +} \ No newline at end of file diff --git a/src/components/Display/Display.js b/src/components/Display/Display.js new file mode 100644 index 0000000..3570655 --- /dev/null +++ b/src/components/Display/Display.js @@ -0,0 +1,33 @@ +import React from 'react'; +import { connect } from 'react-redux'; +import './Display.css'; + +const Display = ({ + onDragStart, + onDragEnd, + currentOperand, + draggable = true, + onDblClick, +}) => { + return ( +
+
+

{currentOperand || '0'}

+
+
+ ); +}; + +const mapStateToProps = ({ calc: { currentOperand } }) => { + return { + currentOperand: currentOperand, + }; +}; + +export default connect(mapStateToProps)(Display); diff --git a/src/components/Equal-block/EqualBlock.css b/src/components/Equal-block/EqualBlock.css new file mode 100644 index 0000000..b26638e --- /dev/null +++ b/src/components/Equal-block/EqualBlock.css @@ -0,0 +1,10 @@ +.equal { + box-shadow: 0 3px 2px rgba(0,0,0,0.2); + padding: 5px; + border-radius: 5px; + width: 200px; +} + +.equal_btn { + display: block; +} \ No newline at end of file diff --git a/src/components/Equal-block/EqualBlock.js b/src/components/Equal-block/EqualBlock.js new file mode 100644 index 0000000..f7178b8 --- /dev/null +++ b/src/components/Equal-block/EqualBlock.js @@ -0,0 +1,36 @@ +import React from 'react'; +import { connect } from 'react-redux'; +import { evaluate } from '../../actions/actions'; +import './EqualBlock.css'; + +const EqualBlock = ({ + onDragStart, + onDragEnd, + evaluate, + draggable = true, + onDblClick, +}) => { + return ( +
+
+ = +
+
+ ); +}; + +const mapDispatchToProps = (dispatch) => { + return { + evaluate: () => dispatch(evaluate()), + }; +}; + +export default connect(() => { + return {}; +}, mapDispatchToProps)(EqualBlock); diff --git a/src/components/Operations/Operations.css b/src/components/Operations/Operations.css new file mode 100644 index 0000000..b0be61c --- /dev/null +++ b/src/components/Operations/Operations.css @@ -0,0 +1,12 @@ +.operations { + display: flex; + gap: 5px; + padding: 5px; + border-radius: 5px; + width: 200px; + box-shadow: 0 3px 2px rgba(0,0,0,0.2); +} + +.operations .btn { + flex-basis: 33%; +} \ No newline at end of file diff --git a/src/components/Operations/Operations.js b/src/components/Operations/Operations.js new file mode 100644 index 0000000..fdb1fb8 --- /dev/null +++ b/src/components/Operations/Operations.js @@ -0,0 +1,45 @@ +import React from 'react'; +import Button from '../Button/Button'; +import { chooseOperation } from '../../actions/actions'; +import { connect } from 'react-redux'; +import './Operations.css'; + +const Operations = ({ + onDragStart, + onDragEnd, + chooseOperation, + draggable = true, + onDblClick, +}) => { + const operations = ['/', 'x', '-', '+']; + + return ( +
+ {operations.map((item) => ( +
+ ); +}; + +const mapDispatchToProps = (dispatch) => { + return { + chooseOperation: (operation) => { + dispatch(chooseOperation(operation)); + }, + }; +}; +export default connect(() => { + return {}; +}, mapDispatchToProps)(Operations); diff --git a/src/features/counter/Counter.js b/src/features/counter/Counter.js deleted file mode 100644 index 772a6ba..0000000 --- a/src/features/counter/Counter.js +++ /dev/null @@ -1,67 +0,0 @@ -import React, { useState } from 'react'; -import { useSelector, useDispatch } from 'react-redux'; -import { - decrement, - increment, - incrementByAmount, - incrementAsync, - incrementIfOdd, - selectCount, -} from './counterSlice'; -import styles from './Counter.module.css'; - -export function Counter() { - const count = useSelector(selectCount); - const dispatch = useDispatch(); - const [incrementAmount, setIncrementAmount] = useState('2'); - - const incrementValue = Number(incrementAmount) || 0; - - return ( -
-
- - {count} - -
-
- setIncrementAmount(e.target.value)} - /> - - - -
-
- ); -} diff --git a/src/features/counter/Counter.module.css b/src/features/counter/Counter.module.css deleted file mode 100644 index 004ae33..0000000 --- a/src/features/counter/Counter.module.css +++ /dev/null @@ -1,78 +0,0 @@ -.row { - display: flex; - align-items: center; - justify-content: center; -} - -.row > button { - margin-left: 4px; - margin-right: 8px; -} -.row:not(:last-child) { - margin-bottom: 16px; -} - -.value { - font-size: 78px; - padding-left: 16px; - padding-right: 16px; - margin-top: 2px; - font-family: 'Courier New', Courier, monospace; -} - -.button { - appearance: none; - background: none; - font-size: 32px; - padding-left: 12px; - padding-right: 12px; - outline: none; - border: 2px solid transparent; - color: rgb(112, 76, 182); - padding-bottom: 4px; - cursor: pointer; - background-color: rgba(112, 76, 182, 0.1); - border-radius: 2px; - transition: all 0.15s; -} - -.textbox { - font-size: 32px; - padding: 2px; - width: 64px; - text-align: center; - margin-right: 4px; -} - -.button:hover, -.button:focus { - border: 2px solid rgba(112, 76, 182, 0.4); -} - -.button:active { - background-color: rgba(112, 76, 182, 0.2); -} - -.asyncButton { - composes: button; - position: relative; -} - -.asyncButton:after { - content: ''; - background-color: rgba(112, 76, 182, 0.15); - display: block; - position: absolute; - width: 100%; - height: 100%; - left: 0; - top: 0; - opacity: 0; - transition: width 1s linear, opacity 0.5s ease 1s; -} - -.asyncButton:active:after { - width: 0%; - opacity: 1; - transition: 0s; -} diff --git a/src/features/counter/counterAPI.js b/src/features/counter/counterAPI.js deleted file mode 100644 index cc9b4a4..0000000 --- a/src/features/counter/counterAPI.js +++ /dev/null @@ -1,6 +0,0 @@ -// A mock function to mimic making an async request for data -export function fetchCount(amount = 1) { - return new Promise((resolve) => - setTimeout(() => resolve({ data: amount }), 500) - ); -} diff --git a/src/features/counter/counterSlice.js b/src/features/counter/counterSlice.js deleted file mode 100644 index 8dc4b5c..0000000 --- a/src/features/counter/counterSlice.js +++ /dev/null @@ -1,73 +0,0 @@ -import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'; -import { fetchCount } from './counterAPI'; - -const initialState = { - value: 0, - status: 'idle', -}; - -// The function below is called a thunk and allows us to perform async logic. It -// can be dispatched like a regular action: `dispatch(incrementAsync(10))`. This -// will call the thunk with the `dispatch` function as the first argument. Async -// code can then be executed and other actions can be dispatched. Thunks are -// typically used to make async requests. -export const incrementAsync = createAsyncThunk( - 'counter/fetchCount', - async (amount) => { - const response = await fetchCount(amount); - // The value we return becomes the `fulfilled` action payload - return response.data; - } -); - -export const counterSlice = createSlice({ - name: 'counter', - initialState, - // The `reducers` field lets us define reducers and generate associated actions - reducers: { - increment: (state) => { - // Redux Toolkit allows us to write "mutating" logic in reducers. It - // doesn't actually mutate the state because it uses the Immer library, - // which detects changes to a "draft state" and produces a brand new - // immutable state based off those changes - state.value += 1; - }, - decrement: (state) => { - state.value -= 1; - }, - // Use the PayloadAction type to declare the contents of `action.payload` - incrementByAmount: (state, action) => { - state.value += action.payload; - }, - }, - // The `extraReducers` field lets the slice handle actions defined elsewhere, - // including actions generated by createAsyncThunk or in other slices. - extraReducers: (builder) => { - builder - .addCase(incrementAsync.pending, (state) => { - state.status = 'loading'; - }) - .addCase(incrementAsync.fulfilled, (state, action) => { - state.status = 'idle'; - state.value += action.payload; - }); - }, -}); - -export const { increment, decrement, incrementByAmount } = counterSlice.actions; - -// The function below is called a selector and allows us to select a value from -// the state. Selectors can also be defined inline where they're used instead of -// in the slice file. For example: `useSelector((state: RootState) => state.counter.value)` -export const selectCount = (state) => state.counter.value; - -// We can also write thunks by hand, which may contain both sync and async logic. -// Here's an example of conditionally dispatching actions based on current state. -export const incrementIfOdd = (amount) => (dispatch, getState) => { - const currentValue = selectCount(getState()); - if (currentValue % 2 === 1) { - dispatch(incrementByAmount(amount)); - } -}; - -export default counterSlice.reducer; diff --git a/src/features/counter/counterSlice.spec.js b/src/features/counter/counterSlice.spec.js deleted file mode 100644 index c1fed2c..0000000 --- a/src/features/counter/counterSlice.spec.js +++ /dev/null @@ -1,33 +0,0 @@ -import counterReducer, { - increment, - decrement, - incrementByAmount, -} from './counterSlice'; - -describe('counter reducer', () => { - const initialState = { - value: 3, - status: 'idle', - }; - it('should handle initial state', () => { - expect(counterReducer(undefined, { type: 'unknown' })).toEqual({ - value: 0, - status: 'idle', - }); - }); - - it('should handle increment', () => { - const actual = counterReducer(initialState, increment()); - expect(actual.value).toEqual(4); - }); - - it('should handle decrement', () => { - const actual = counterReducer(initialState, decrement()); - expect(actual.value).toEqual(2); - }); - - it('should handle incrementByAmount', () => { - const actual = counterReducer(initialState, incrementByAmount(2)); - expect(actual.value).toEqual(5); - }); -}); diff --git a/src/index.css b/src/index.css deleted file mode 100644 index ec2585e..0000000 --- a/src/index.css +++ /dev/null @@ -1,13 +0,0 @@ -body { - margin: 0; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', - 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', - sans-serif; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -code { - font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', - monospace; -} diff --git a/src/index.js b/src/index.js index 9cc8015..d273bb1 100644 --- a/src/index.js +++ b/src/index.js @@ -1,21 +1,12 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import './index.css'; -import App from './App'; -import { store } from './app/store'; +import App from './components/App/App'; +import store from './components/App/store'; import { Provider } from 'react-redux'; -import * as serviceWorker from './serviceWorker'; ReactDOM.render( - - - - - , - document.getElementById('root') + + + , + document.getElementById('root') ); - -// If you want your app to work offline and load faster, you can change -// unregister() to register() below. Note this comes with some pitfalls. -// Learn more about service workers: https://bit.ly/CRA-PWA -serviceWorker.unregister(); diff --git a/src/logo.svg b/src/logo.svg deleted file mode 100644 index 8466738..0000000 --- a/src/logo.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/reducers/CalcReducer.js b/src/reducers/CalcReducer.js new file mode 100644 index 0000000..2106350 --- /dev/null +++ b/src/reducers/CalcReducer.js @@ -0,0 +1,141 @@ +const initialState = { + currentOperand: null, + previousOperand: null, + operation: null, + evaluated: false, +}; + +const evaluate = ({ calc: { currentOperand, previousOperand, operation } }) => { + const prev = parseFloat(previousOperand); + const current = parseFloat(currentOperand); + if (isNaN(prev) || isNaN(current)) { + return '0'; + } + + let computation = ''; + + switch (operation) { + case '+': + computation = prev + current; + break; + case '-': + computation = prev - current; + break; + case '/': + computation = prev / current; + break; + case 'x': + computation = prev * current; + break; + default: + return ''; + } + + return computation.toString(); +}; + +const CalcReducer = (state, { type, payload }) => { + if (state === undefined) { + return initialState; + } + switch (type) { + case 'ADD_DIGIT': + if (state.drag.constructorModeEnable) { + return state.calc; + } + + if ( + state.calc.evaluated || + (state.calc.currentOperand === null && payload !== '.') + ) { + return { + ...state.calc, + currentOperand: payload, + evaluated: false, + }; + } + + if (state.calc.currentOperand.length === 11) { + return state.calc; + } + + if (payload === '0' && state.calc.currentOperand === null) { + return state.calc; + } + + if (payload === '.' && state.calc.currentOperand.includes('.')) { + return state.calc; + } + + return { + ...state.calc, + currentOperand: `${state.calc.currentOperand}${payload}`, + }; + + case 'CHOOSE_OPERATION': + if (state.drag.constructorModeEnable) { + return state.calc; + } + + if ( + state.calc.currentOperand === null && + state.calc.previousOperand == null + ) { + return state.calc; + } + + if ( + (!state.calc.evaluated && state.calc.currentOperand === null) || + (state.calc.evaluated && + state.calc.currentOperand === state.calc.previousOperand) + ) { + return { + ...state.calc, + operation: payload, + }; + } + + if (state.calc.previousOperand == null) { + return { + ...state.calc, + operation: payload, + previousOperand: state.calc.currentOperand, + currentOperand: null, + }; + } + + return { + ...state.calc, + currentOperand: evaluate(state), + previousOperand: evaluate(state), + evaluated: true, + operation: payload, + }; + + case 'EVALUATE': + if (state.drag.constructorModeEnable) { + return state.calc; + } + + if ( + state.calc.operation === null || + state.calc.currentOperand === null || + state.calc.previousOperand === null + ) { + return state.calc; + } + + return { + ...state.calc, + evaluated: true, + currentOperand: evaluate(state), + previousOperand: null, + operation: null, + }; + + default: + return state.calc; + } +}; + +export default CalcReducer; diff --git a/src/reducers/DragReducer.js b/src/reducers/DragReducer.js new file mode 100644 index 0000000..5360ea1 --- /dev/null +++ b/src/reducers/DragReducer.js @@ -0,0 +1,68 @@ +import DigitalBlock from '../components/Digital-block/DigitalBlock'; +import Display from '../components/Display/Display'; +import EqualBlock from '../components/Equal-block/EqualBlock'; +import Operations from '../components/Operations/Operations'; + +const initialState = { + isDraging: false, + draggableBlock: null, + droppableSection: null, + constructorModeEnable: true, + blocks: [ + { id: 1, name: 'display', component: Display }, + { id: 2, name: 'operations', component: Operations }, + { id: 3, name: 'digitalBlock', component: DigitalBlock }, + { id: 4, name: 'equalBlock', component: EqualBlock }, + ], +}; + +const DragReducer = (state, { type, payload }) => { + if (state === undefined) { + return initialState; + } + switch (type) { + case 'SET_BLOCKS': + return { + ...state.drag, + blocks: payload, + }; + case 'DRAG_START': + if (state.drag.draggableBlock === payload) { + return { ...state.drag }; + } + return { + ...state.drag, + isDraging: true, + draggableBlock: payload, + }; + + case 'DRAG_END': + return { + ...state.drag, + isDraging: false, + draggableBlock: null, + }; + + case 'SET_DROPPABLE_SECTION': + return { + ...state.drag, + droppableSection: payload, + }; + + case 'SET_DRAGGABLE_BLOCK': + return { + ...state.drag, + draggableBlock: payload, + }; + + case 'CHANGE_CONSTRUCTOR_MODE': + return { + ...state.drag, + constructorModeEnable: !state.drag.constructorModeEnable, + }; + default: + return state.drag; + } +}; + +export default DragReducer; diff --git a/src/reducers/reducer.js b/src/reducers/reducer.js new file mode 100644 index 0000000..056b3da --- /dev/null +++ b/src/reducers/reducer.js @@ -0,0 +1,11 @@ +import CalcReducer from './CalcReducer'; +import DragReducer from './DragReducer'; + +const reducer = (state, action) => { + return { + calc: CalcReducer(state, action), + drag: DragReducer(state, action), + }; +}; + +export default reducer; diff --git a/src/serviceWorker.js b/src/serviceWorker.js deleted file mode 100644 index 6f9c97b..0000000 --- a/src/serviceWorker.js +++ /dev/null @@ -1,137 +0,0 @@ -// This optional code is used to register a service worker. -// register() is not called by default. - -// This lets the app load faster on subsequent visits in production, and gives -// it offline capabilities. However, it also means that developers (and users) -// will only see deployed updates on subsequent visits to a page, after all the -// existing tabs open on the page have been closed, since previously cached -// resources are updated in the background. - -// To learn more about the benefits of this model and instructions on how to -// opt-in, read https://bit.ly/CRA-PWA - -const isLocalhost = Boolean( - window.location.hostname === 'localhost' || - // [::1] is the IPv6 localhost address. - window.location.hostname === '[::1]' || - // 127.0.0.0/8 are considered localhost for IPv4. - window.location.hostname.match( - /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ - ) -); - -export function register(config) { - if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { - // The URL constructor is available in all browsers that support SW. - const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); - if (publicUrl.origin !== window.location.origin) { - // Our service worker won't work if PUBLIC_URL is on a different origin - // from what our page is served on. This might happen if a CDN is used to - // serve assets; see https://github.com/facebook/create-react-app/issues/2374 - return; - } - - window.addEventListener('load', () => { - const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; - - if (isLocalhost) { - // This is running on localhost. Let's check if a service worker still exists or not. - checkValidServiceWorker(swUrl, config); - - // Add some additional logging to localhost, pointing developers to the - // service worker/PWA documentation. - navigator.serviceWorker.ready.then(() => { - console.log( - 'This web app is being served cache-first by a service ' + - 'worker. To learn more, visit https://bit.ly/CRA-PWA' - ); - }); - } else { - // Is not localhost. Just register service worker - registerValidSW(swUrl, config); - } - }); - } -} - -function registerValidSW(swUrl, config) { - navigator.serviceWorker - .register(swUrl) - .then((registration) => { - registration.onupdatefound = () => { - const installingWorker = registration.installing; - if (installingWorker == null) { - return; - } - installingWorker.onstatechange = () => { - if (installingWorker.state === 'installed') { - if (navigator.serviceWorker.controller) { - // At this point, the updated precached content has been fetched, - // but the previous service worker will still serve the older - // content until all client tabs are closed. - console.log( - 'New content is available and will be used when all ' + - 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' - ); - - // Execute callback - if (config && config.onUpdate) { - config.onUpdate(registration); - } - } else { - // At this point, everything has been precached. - // It's the perfect time to display a - // "Content is cached for offline use." message. - console.log('Content is cached for offline use.'); - - // Execute callback - if (config && config.onSuccess) { - config.onSuccess(registration); - } - } - } - }; - }; - }) - .catch((error) => { - console.error('Error during service worker registration:', error); - }); -} - -function checkValidServiceWorker(swUrl, config) { - // Check if the service worker can be found. If it can't reload the page. - fetch(swUrl, { - headers: { 'Service-Worker': 'script' }, - }) - .then((response) => { - // Ensure service worker exists, and that we really are getting a JS file. - const contentType = response.headers.get('content-type'); - if ( - response.status === 404 || - (contentType != null && contentType.indexOf('javascript') === -1) - ) { - // No service worker found. Probably a different app. Reload the page. - navigator.serviceWorker.ready.then((registration) => { - registration.unregister().then(() => { - window.location.reload(); - }); - }); - } else { - // Service worker found. Proceed as normal. - registerValidSW(swUrl, config); - } - }) - .catch(() => { - console.log( - 'No internet connection found. App is running in offline mode.' - ); - }); -} - -export function unregister() { - if ('serviceWorker' in navigator) { - navigator.serviceWorker.ready.then((registration) => { - registration.unregister(); - }); - } -} diff --git a/src/setupTests.js b/src/setupTests.js deleted file mode 100644 index 74b1a27..0000000 --- a/src/setupTests.js +++ /dev/null @@ -1,5 +0,0 @@ -// jest-dom adds custom jest matchers for asserting on DOM nodes. -// allows you to do things like: -// expect(element).toHaveTextContent(/react/i) -// learn more: https://github.com/testing-library/jest-dom -import '@testing-library/jest-dom/extend-expect'; From 008dc2a21296fd9f43241654a17e19fe31aa20f0 Mon Sep 17 00:00:00 2001 From: Pavel Movchan Date: Mon, 24 Jan 2022 18:27:32 +0900 Subject: [PATCH 2/3] bug fix & refactoring --- package-lock.json | 29 ++++- package.json | 3 + src/HOC/eventHoc.js | 16 +++ src/actions/actions.js | 42 ++++--- src/actions/constants.js | 21 ++++ src/components/App/App.js | 1 - src/components/Button/Button.js | 18 +-- src/components/CalcPalette/CalcPalette.js | 45 ++------ src/components/Desk/Desk.js | 26 +++-- src/components/Digital-block/DigitalBlock.js | 35 ++---- src/components/Display/Display.css | 4 +- src/components/Display/Display.js | 27 ++--- src/components/Equal-block/EqualBlock.js | 27 +---- src/components/Operations/Operations.js | 32 ++---- src/reducers/CalcReducer.js | 109 +++++++++++-------- src/reducers/DragReducer.js | 44 ++++---- src/reducers/reducer.js | 17 ++- 17 files changed, 248 insertions(+), 248 deletions(-) create mode 100644 src/HOC/eventHoc.js create mode 100644 src/actions/constants.js diff --git a/package-lock.json b/package-lock.json index f68fbad..ff5bacf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5730,7 +5730,8 @@ "email-addresses": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/email-addresses/-/email-addresses-3.1.0.tgz", - "integrity": "sha512-k0/r7GrWVL32kZlGwfPNgB2Y/mMXVTq/decgLczm/j34whdaspNrZO8CnXPf1laaHxI6ptUlsnAxN+UAPw+fzg==" + "integrity": "sha512-k0/r7GrWVL32kZlGwfPNgB2Y/mMXVTq/decgLczm/j34whdaspNrZO8CnXPf1laaHxI6ptUlsnAxN+UAPw+fzg==", + "dev": true }, "emittery": { "version": "0.7.2", @@ -6960,12 +6961,14 @@ "filename-reserved-regex": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz", - "integrity": "sha1-q/c9+rc10EVECr/qLZHzieu/oik=" + "integrity": "sha1-q/c9+rc10EVECr/qLZHzieu/oik=", + "dev": true }, "filenamify": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/filenamify/-/filenamify-4.3.0.tgz", "integrity": "sha512-hcFKyUG57yWGAzu1CMt/dPzYZuv+jAJUT85bL8mrXvNe6hWj6yEHEc4EdcgiA6Z3oi1/9wXJdZPXF2dZNgwgOg==", + "dev": true, "requires": { "filename-reserved-regex": "^2.0.0", "strip-outer": "^1.0.1", @@ -7336,6 +7339,7 @@ "version": "3.2.3", "resolved": "https://registry.npmjs.org/gh-pages/-/gh-pages-3.2.3.tgz", "integrity": "sha512-jA1PbapQ1jqzacECfjUaO9gV8uBgU6XNMV0oXLtfCX3haGLe5Atq8BxlrADhbD6/UdG9j6tZLWAkAybndOXTJg==", + "dev": true, "requires": { "async": "^2.6.1", "commander": "^2.18.0", @@ -7350,6 +7354,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz", "integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=", + "dev": true, "requires": { "array-uniq": "^1.0.1" } @@ -7357,12 +7362,14 @@ "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true }, "find-cache-dir": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.2.tgz", "integrity": "sha512-wXZV5emFEjrridIgED11OoUKLxiYjAcqot/NJdAkOhlJ+vGzwhOAfcG5OX1jP+S0PcjEn8bdMJv+g2jwQ3Onig==", + "dev": true, "requires": { "commondir": "^1.0.1", "make-dir": "^3.0.2", @@ -7373,6 +7380,7 @@ "version": "8.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "dev": true, "requires": { "graceful-fs": "^4.2.0", "jsonfile": "^4.0.0", @@ -7383,6 +7391,7 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/globby/-/globby-6.1.0.tgz", "integrity": "sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=", + "dev": true, "requires": { "array-union": "^1.0.1", "glob": "^7.0.3", @@ -7395,6 +7404,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "dev": true, "requires": { "graceful-fs": "^4.1.6" } @@ -7403,6 +7413,7 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "dev": true, "requires": { "semver": "^6.0.0" } @@ -7410,12 +7421,14 @@ "pify": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", - "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=" + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", + "dev": true }, "pkg-dir": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", "integrity": "sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==", + "dev": true, "requires": { "find-up": "^4.0.0" } @@ -7423,12 +7436,14 @@ "semver": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true }, "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "dev": true } } }, @@ -14395,6 +14410,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/strip-outer/-/strip-outer-1.0.1.tgz", "integrity": "sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==", + "dev": true, "requires": { "escape-string-regexp": "^1.0.2" } @@ -14832,6 +14848,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/trim-repeated/-/trim-repeated-1.0.0.tgz", "integrity": "sha1-42RqLqTokTEr9+rObPsFOAvAHCE=", + "dev": true, "requires": { "escape-string-regexp": "^1.0.2" } diff --git a/package.json b/package.json index 9432a1d..4eab137 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,5 @@ { + "homepage": "https://skippikp.github.io/Calc-constructor", "name": "calc-constructor", "version": "0.1.0", "private": true, @@ -16,6 +17,8 @@ "react-scripts": "4.0.3" }, "scripts": { + "predeploy": "npm run build", + "deploy": "gh-pages -d build", "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", diff --git a/src/HOC/eventHoc.js b/src/HOC/eventHoc.js new file mode 100644 index 0000000..3783329 --- /dev/null +++ b/src/HOC/eventHoc.js @@ -0,0 +1,16 @@ +const eventHoc = (Component) => { + return ({ onDragStart, onDragEnd, draggable, onDblClick, ...props }) => { + return ( +
+ +
+ ); + }; +}; + +export default eventHoc; diff --git a/src/actions/actions.js b/src/actions/actions.js index f60a6c4..ae1fe65 100644 --- a/src/actions/actions.js +++ b/src/actions/actions.js @@ -1,37 +1,49 @@ -const addDigit = (payload) => { - return { type: 'ADD_DIGIT', payload: payload }; +import { + ADD_DIGIT, + CHOOSE_OPERATION, + SET_DROPPABLE_SECTION, + EVALUATE, + SET_DRAGGABLE_BLOCK, + SET_BLOCKS, + DRAG_START, + DRAG_END, + CHANGE_CONSTRUCTOR_MODE, +} from './constants'; + +const addDigit = (digit) => { + return { type: ADD_DIGIT, payload: digit }; }; -const chooseOperation = (payload) => { - return { type: 'CHOOSE_OPERATION', payload: payload }; +const chooseOperation = (operation) => { + return { type: CHOOSE_OPERATION, payload: operation }; }; -const setBlocks = (payload) => { - return { type: 'SET_BLOCKS', payload: payload }; +const setBlocks = (blocks) => { + return { type: SET_BLOCKS, payload: blocks }; }; -const setDraggableBlock = (payload) => { - return { type: 'SET_DRAGGABLE_BLOCK', payload: payload }; +const setDraggableBlock = (block) => { + return { type: SET_DRAGGABLE_BLOCK, payload: block }; }; const evaluate = () => { - return { type: 'EVALUATE' }; + return { type: EVALUATE }; }; const dragEnd = () => { - return { type: 'DRAG_END' }; + return { type: DRAG_END }; }; -const dragging = (payload) => { - return { type: 'DRAG_START', payload: payload }; +const dragging = (draggableBlock) => { + return { type: DRAG_START, payload: draggableBlock }; }; -const setDroppableSection = (payload) => { - return { type: 'SET_DROPPABLE_SECTION', payload: payload }; +const setDroppableSection = (section) => { + return { type: SET_DROPPABLE_SECTION, payload: section }; }; const changeConstructorMode = () => { - return { type: 'CHANGE_CONSTRUCTOR_MODE' }; + return { type: CHANGE_CONSTRUCTOR_MODE }; }; export { addDigit, diff --git a/src/actions/constants.js b/src/actions/constants.js new file mode 100644 index 0000000..7c13731 --- /dev/null +++ b/src/actions/constants.js @@ -0,0 +1,21 @@ +const ADD_DIGIT = 'ADD_DIGIT'; +const CHOOSE_OPERATION = 'CHOOSE_OPERATION'; +const SET_BLOCKS = 'SET_BLOCKS'; +const SET_DRAGGABLE_BLOCK = 'SET_DRAGGABLE_BLOCK'; +const EVALUATE = 'EVALUATE'; +const DRAG_END = 'DRAG_END'; +const DRAG_START = 'DRAG_START'; +const SET_DROPPABLE_SECTION = 'SET_DROPPABLE_SECTION'; +const CHANGE_CONSTRUCTOR_MODE = 'CHANGE_CONSTRUCTOR_MODE'; + +export { + ADD_DIGIT, + CHOOSE_OPERATION, + SET_BLOCKS, + SET_DRAGGABLE_BLOCK, + EVALUATE, + DRAG_END, + DRAG_START, + SET_DROPPABLE_SECTION, + CHANGE_CONSTRUCTOR_MODE, +}; diff --git a/src/components/App/App.js b/src/components/App/App.js index 742586b..26b7b7c 100644 --- a/src/components/App/App.js +++ b/src/components/App/App.js @@ -1,7 +1,6 @@ import React from 'react'; import CalcPalette from '../CalcPalette/CalcPalette'; import Desk from '../Desk/Desk'; - import './App.css'; function App() { diff --git a/src/components/Button/Button.js b/src/components/Button/Button.js index 8547be8..84af938 100644 --- a/src/components/Button/Button.js +++ b/src/components/Button/Button.js @@ -1,23 +1,11 @@ import React from 'react'; -import { connect } from 'react-redux'; -import { addDigit } from '../../actions/actions'; -const Button = ({ className, value, clickHandle }) => { +const Button = ({ className, value, onClick }) => { return ( -
+
{value}
); }; -const mapDispatchToProps = (dispatch) => { - return { - addDigit: (newValue) => { - dispatch(addDigit(newValue)); - }, - }; -}; - -export default connect(() => { - return {}; -}, mapDispatchToProps)(Button); +export default Button; diff --git a/src/components/CalcPalette/CalcPalette.js b/src/components/CalcPalette/CalcPalette.js index 08916af..d541fd6 100644 --- a/src/components/CalcPalette/CalcPalette.js +++ b/src/components/CalcPalette/CalcPalette.js @@ -20,10 +20,6 @@ const CalcPalette = ({ }) => { const [index, setIndex] = useState(null); - const dragOverHandler = (e) => { - e.preventDefault(); - }; - const dragStartHandler = (e, item) => { const elemIdx = blocks.indexOf(item); if (constructorModeEnable) { @@ -48,30 +44,14 @@ const CalcPalette = ({ e.target.style.visibility = 'visible'; }; - const dropHandler = (e) => { - e.preventDefault(); - if (droppableSection) { - return; - } - - const updatedState = [ - ...blocks.slice(0, index - 1), - draggableBlock, - ...blocks.slice(index), - ]; - setBlocks(updatedState); - }; - return (
{blocks.map((block) => ( dragOverHandler(e)} onDragStart={(e) => dragStartHandler(e, block)} - onDragEnd={(e) => dragEndHandler(e)} - onDrop={(e) => dropHandler(e)} + onDragEnd={dragEndHandler} /> ))}
@@ -79,23 +59,22 @@ const CalcPalette = ({ }; const mapStateToProps = ({ - drag: { draggableBlock, droppableSection, constructorModeEnable, blocks }, + drag: { draggableBlock, droppableSection, blocks }, + calc: { constructorModeEnable }, }) => { return { - draggableBlock: draggableBlock, - droppableSection: droppableSection, - constructorModeEnable: constructorModeEnable, - blocks: blocks, + draggableBlock, + droppableSection, + constructorModeEnable, + blocks, }; }; -const mapDispatchToProps = (dispatch) => { - return { - dragging: (element) => dispatch(dragging(element)), - setDroppableSection: (section) => dispatch(setDroppableSection(section)), - dragEnd: () => dispatch(dragEnd()), - setBlocks: (blocks) => dispatch(setBlocks(blocks)), - }; +const mapDispatchToProps = { + dragging, + setDroppableSection, + dragEnd, + setBlocks, }; export default connect(mapStateToProps, mapDispatchToProps)(CalcPalette); diff --git a/src/components/Desk/Desk.js b/src/components/Desk/Desk.js index 3568257..2edd65b 100644 --- a/src/components/Desk/Desk.js +++ b/src/components/Desk/Desk.js @@ -31,6 +31,9 @@ const Desk = ({ const dragOverHandler = (e, section) => { e.preventDefault(); + if (!draggableBlock) { + return; + } if (e.target.className === 'desk-item') { e.target.style.backgroundColor = 'rgba(0, 159, 249, 0.4)'; } @@ -129,23 +132,22 @@ const Desk = ({ }; const mapStateToProps = ({ - drag: { draggableBlock, constructorModeEnable, blocks }, + drag: { draggableBlock, blocks }, + calc: { constructorModeEnable }, }) => { return { - draggableBlock: draggableBlock, - constructorModeEnable: constructorModeEnable, - blocks: blocks, + draggableBlock, + constructorModeEnable, + blocks, }; }; -const mapDispatchToProps = (dispatch) => { - return { - setDroppableSection: (section) => dispatch(setDroppableSection(section)), - changeConstructorMode: () => dispatch(changeConstructorMode()), - dragEnd: () => dispatch(dragEnd()), - setBlocks: (blocks) => dispatch(setBlocks(blocks)), - setDraggableBlock: (block) => dispatch(setDraggableBlock(block)), - }; +const mapDispatchToProps = { + setDroppableSection, + changeConstructorMode, + dragEnd, + setBlocks, + setDraggableBlock, }; export default connect(mapStateToProps, mapDispatchToProps)(Desk); diff --git a/src/components/Digital-block/DigitalBlock.js b/src/components/Digital-block/DigitalBlock.js index c68a277..bab6e01 100644 --- a/src/components/Digital-block/DigitalBlock.js +++ b/src/components/Digital-block/DigitalBlock.js @@ -2,47 +2,28 @@ import React from 'react'; import Button from '../Button/Button'; import { connect } from 'react-redux'; import { addDigit } from '../../actions/actions'; +import eventHoc from '../../HOC/eventHoc'; import './DigitalBlock.css'; -const DigitalBlock = ({ - onDragEnd, - onDragStart, - addDigit, - draggable, - onDblClick, -}) => { - const numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.']; +const numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.']; +const DigitalBlock = ({ addDigit }) => { return ( -
+
{numbers.map((item) => (
); }; -const mapStateToProps = (state) => { - return state; -}; - -const mapDispatchToProps = (dispatch) => { - return { - addDigit: (digit) => { - dispatch(addDigit(digit)); - }, - }; +const mapDispatchToProps = { + addDigit, }; -export default connect(mapStateToProps, mapDispatchToProps)(DigitalBlock); +export default connect(null, mapDispatchToProps)(eventHoc(DigitalBlock)); diff --git a/src/components/Display/Display.css b/src/components/Display/Display.css index 625fa2e..d05e33d 100644 --- a/src/components/Display/Display.css +++ b/src/components/Display/Display.css @@ -3,15 +3,17 @@ box-shadow: 0 3px 2px rgba(0,0,0,0.2); padding: 5px; width: 200px; + } .display_text-field { background-color: gray; border-radius: 5px; padding: 5px; + height: 45px; } -.display_text-field h3 { +.display_text-field h3,h6 { margin: 0; text-align: end; } \ No newline at end of file diff --git a/src/components/Display/Display.js b/src/components/Display/Display.js index 3570655..76d124e 100644 --- a/src/components/Display/Display.js +++ b/src/components/Display/Display.js @@ -1,24 +1,19 @@ import React from 'react'; import { connect } from 'react-redux'; +import eventHoc from '../../HOC/eventHoc'; import './Display.css'; -const Display = ({ - onDragStart, - onDragEnd, - currentOperand, - draggable = true, - onDblClick, -}) => { +const Display = ({ currentOperand }) => { return ( -
+
-

{currentOperand || '0'}

+ {currentOperand?.length > 11 ? ( +
{`${currentOperand.slice(0, 21).toString()}\n${currentOperand + .slice(21) + .toString()}`}
+ ) : ( +

{currentOperand || '0'}

+ )}
); @@ -30,4 +25,4 @@ const mapStateToProps = ({ calc: { currentOperand } }) => { }; }; -export default connect(mapStateToProps)(Display); +export default connect(mapStateToProps)(eventHoc(Display)); diff --git a/src/components/Equal-block/EqualBlock.js b/src/components/Equal-block/EqualBlock.js index f7178b8..d8ee216 100644 --- a/src/components/Equal-block/EqualBlock.js +++ b/src/components/Equal-block/EqualBlock.js @@ -1,23 +1,12 @@ import React from 'react'; import { connect } from 'react-redux'; import { evaluate } from '../../actions/actions'; +import eventHoc from '../../HOC/eventHoc'; import './EqualBlock.css'; -const EqualBlock = ({ - onDragStart, - onDragEnd, - evaluate, - draggable = true, - onDblClick, -}) => { +const EqualBlock = ({ evaluate }) => { return ( -
+
=
@@ -25,12 +14,8 @@ const EqualBlock = ({ ); }; -const mapDispatchToProps = (dispatch) => { - return { - evaluate: () => dispatch(evaluate()), - }; +const mapDispatchToProps = { + evaluate, }; -export default connect(() => { - return {}; -}, mapDispatchToProps)(EqualBlock); +export default connect(null, mapDispatchToProps)(eventHoc(EqualBlock)); diff --git a/src/components/Operations/Operations.js b/src/components/Operations/Operations.js index fdb1fb8..3ef28e5 100644 --- a/src/components/Operations/Operations.js +++ b/src/components/Operations/Operations.js @@ -2,44 +2,28 @@ import React from 'react'; import Button from '../Button/Button'; import { chooseOperation } from '../../actions/actions'; import { connect } from 'react-redux'; +import eventHoc from '../../HOC/eventHoc'; import './Operations.css'; -const Operations = ({ - onDragStart, - onDragEnd, - chooseOperation, - draggable = true, - onDblClick, -}) => { +const Operations = ({ chooseOperation }) => { const operations = ['/', 'x', '-', '+']; return ( -
+
{operations.map((item) => (
); }; -const mapDispatchToProps = (dispatch) => { - return { - chooseOperation: (operation) => { - dispatch(chooseOperation(operation)); - }, - }; +const mapDispatchToProps = { + chooseOperation, }; -export default connect(() => { - return {}; -}, mapDispatchToProps)(Operations); + +export default connect(null, mapDispatchToProps)(eventHoc(Operations)); diff --git a/src/reducers/CalcReducer.js b/src/reducers/CalcReducer.js index 2106350..0dbdb1d 100644 --- a/src/reducers/CalcReducer.js +++ b/src/reducers/CalcReducer.js @@ -1,11 +1,19 @@ +import { + ADD_DIGIT, + CHOOSE_OPERATION, + EVALUATE, + CHANGE_CONSTRUCTOR_MODE, +} from '../actions/constants'; + const initialState = { currentOperand: null, previousOperand: null, operation: null, evaluated: false, + constructorModeEnable: true, }; -const evaluate = ({ calc: { currentOperand, previousOperand, operation } }) => { +const evaluate = ({ currentOperand, previousOperand, operation }) => { const prev = parseFloat(previousOperand); const current = parseFloat(currentOperand); if (isNaN(prev) || isNaN(current)) { @@ -34,99 +42,110 @@ const evaluate = ({ calc: { currentOperand, previousOperand, operation } }) => { return computation.toString(); }; -const CalcReducer = (state, { type, payload }) => { - if (state === undefined) { - return initialState; - } +const calcReducer = (state = initialState, { type, payload }) => { switch (type) { - case 'ADD_DIGIT': - if (state.drag.constructorModeEnable) { - return state.calc; + case CHANGE_CONSTRUCTOR_MODE: + return { + ...state, + constructorModeEnable: !state.constructorModeEnable, + }; + case ADD_DIGIT: + if (state.constructorModeEnable) { + return state; + } + + if (state.currentOperand === null && payload === '.') { + return { + ...state, + currentOperand: '0.', + }; } if ( - state.calc.evaluated || - (state.calc.currentOperand === null && payload !== '.') + state.evaluated || + (state.currentOperand === null && payload !== '.') ) { return { - ...state.calc, + ...state, currentOperand: payload, evaluated: false, }; } - if (state.calc.currentOperand.length === 11) { - return state.calc; + if (state.currentOperand.length === 11) { + return state; } - if (payload === '0' && state.calc.currentOperand === null) { - return state.calc; + if ( + payload === '0' && + (state.currentOperand === null || state.currentOperand === '0') + ) { + return state; } - if (payload === '.' && state.calc.currentOperand.includes('.')) { - return state.calc; + if (payload === '.' && state.currentOperand.includes('.')) { + return state; } return { - ...state.calc, - currentOperand: `${state.calc.currentOperand}${payload}`, + ...state, + currentOperand: `${state.currentOperand}${payload}`, }; - case 'CHOOSE_OPERATION': - if (state.drag.constructorModeEnable) { - return state.calc; + case CHOOSE_OPERATION: + if (state.constructorModeEnable) { + return state; } - if ( - state.calc.currentOperand === null && - state.calc.previousOperand == null - ) { - return state.calc; + if (state.currentOperand === null && state.previousOperand == null) { + return state; } if ( - (!state.calc.evaluated && state.calc.currentOperand === null) || - (state.calc.evaluated && - state.calc.currentOperand === state.calc.previousOperand) + (!state.evaluated && state.currentOperand === null) || + (state.evaluated && state.currentOperand === state.previousOperand) || + (state.previousOperand && + state.currentOperand === null && + state.operation) ) { return { - ...state.calc, + ...state, operation: payload, }; } - if (state.calc.previousOperand == null) { + if (state.previousOperand == null) { return { - ...state.calc, + ...state, operation: payload, - previousOperand: state.calc.currentOperand, + previousOperand: state.currentOperand, currentOperand: null, }; } return { - ...state.calc, + ...state, currentOperand: evaluate(state), previousOperand: evaluate(state), evaluated: true, operation: payload, }; - case 'EVALUATE': - if (state.drag.constructorModeEnable) { - return state.calc; + case EVALUATE: + if (state.constructorModeEnable) { + return state; } if ( - state.calc.operation === null || - state.calc.currentOperand === null || - state.calc.previousOperand === null + state.operation === null || + state.currentOperand === null || + state.previousOperand === null ) { - return state.calc; + return state; } return { - ...state.calc, + ...state, evaluated: true, currentOperand: evaluate(state), previousOperand: null, @@ -134,8 +153,8 @@ const CalcReducer = (state, { type, payload }) => { }; default: - return state.calc; + return state; } }; -export default CalcReducer; +export default calcReducer; diff --git a/src/reducers/DragReducer.js b/src/reducers/DragReducer.js index 5360ea1..b55ca8f 100644 --- a/src/reducers/DragReducer.js +++ b/src/reducers/DragReducer.js @@ -2,12 +2,18 @@ import DigitalBlock from '../components/Digital-block/DigitalBlock'; import Display from '../components/Display/Display'; import EqualBlock from '../components/Equal-block/EqualBlock'; import Operations from '../components/Operations/Operations'; +import { + SET_DROPPABLE_SECTION, + SET_DRAGGABLE_BLOCK, + SET_BLOCKS, + DRAG_START, + DRAG_END, +} from '../actions/constants'; const initialState = { isDraging: false, draggableBlock: null, droppableSection: null, - constructorModeEnable: true, blocks: [ { id: 1, name: 'display', component: Display }, { id: 2, name: 'operations', component: Operations }, @@ -16,53 +22,45 @@ const initialState = { ], }; -const DragReducer = (state, { type, payload }) => { - if (state === undefined) { - return initialState; - } +const dragReducer = (state = initialState, { type, payload }) => { switch (type) { - case 'SET_BLOCKS': + case SET_BLOCKS: return { - ...state.drag, + ...state, blocks: payload, }; - case 'DRAG_START': - if (state.drag.draggableBlock === payload) { + case DRAG_START: + if (state.draggableBlock === payload) { return { ...state.drag }; } return { - ...state.drag, + ...state, isDraging: true, draggableBlock: payload, }; - case 'DRAG_END': + case DRAG_END: return { - ...state.drag, + ...state, isDraging: false, draggableBlock: null, }; - case 'SET_DROPPABLE_SECTION': + case SET_DROPPABLE_SECTION: return { - ...state.drag, + ...state, droppableSection: payload, }; - case 'SET_DRAGGABLE_BLOCK': + case SET_DRAGGABLE_BLOCK: return { - ...state.drag, + ...state, draggableBlock: payload, }; - case 'CHANGE_CONSTRUCTOR_MODE': - return { - ...state.drag, - constructorModeEnable: !state.drag.constructorModeEnable, - }; default: - return state.drag; + return state; } }; -export default DragReducer; +export default dragReducer; diff --git a/src/reducers/reducer.js b/src/reducers/reducer.js index 056b3da..ed07baf 100644 --- a/src/reducers/reducer.js +++ b/src/reducers/reducer.js @@ -1,11 +1,10 @@ -import CalcReducer from './CalcReducer'; -import DragReducer from './DragReducer'; +import calcReducer from './CalcReducer'; +import dragReducer from './DragReducer'; +import { combineReducers } from 'redux'; -const reducer = (state, action) => { - return { - calc: CalcReducer(state, action), - drag: DragReducer(state, action), - }; -}; +const rootReducer = combineReducers({ + calc: calcReducer, + drag: dragReducer, +}); -export default reducer; +export default rootReducer; From 77150b27b72649cee41d380002088dd8f98193f5 Mon Sep 17 00:00:00 2001 From: Pavel Movchan Date: Wed, 2 Feb 2022 01:59:26 +0900 Subject: [PATCH 3/3] refactoring --- src/HOC/DragContainer.js | 25 ++++++++++++ src/HOC/eventHoc.js | 16 -------- src/actions/actions.js | 4 +- src/components/Button/Button.js | 19 +++++++-- src/components/CalcPalette/CalcPalette.js | 39 ++++++++++++++----- src/components/Desk/Desk.js | 29 ++++++++++++-- src/components/Digital-block/DigitalBlock.js | 7 ++-- src/components/Display/Display.js | 10 ++--- src/components/Equal-block/EqualBlock.js | 12 +++--- src/components/Operations/Operations.js | 8 ++-- src/reducers/CalcReducer.js | 25 +----------- .../{DragReducer.js => ConstructorReducer.js} | 28 ++++++------- src/reducers/reducer.js | 4 +- 13 files changed, 132 insertions(+), 94 deletions(-) create mode 100644 src/HOC/DragContainer.js delete mode 100644 src/HOC/eventHoc.js rename src/reducers/{DragReducer.js => ConstructorReducer.js} (52%) diff --git a/src/HOC/DragContainer.js b/src/HOC/DragContainer.js new file mode 100644 index 0000000..9215962 --- /dev/null +++ b/src/HOC/DragContainer.js @@ -0,0 +1,25 @@ +import React from 'react'; + +const DragContainer = ({ + children, + onDragStart, + onDragEnd, + draggable, + onDblClick, + ...props +}) => { + return ( +
+ {React.Children.map(children, (child) => { + return React.cloneElement(child, { props }); + })} +
+ ); +}; + +export default DragContainer; diff --git a/src/HOC/eventHoc.js b/src/HOC/eventHoc.js deleted file mode 100644 index 3783329..0000000 --- a/src/HOC/eventHoc.js +++ /dev/null @@ -1,16 +0,0 @@ -const eventHoc = (Component) => { - return ({ onDragStart, onDragEnd, draggable, onDblClick, ...props }) => { - return ( -
- -
- ); - }; -}; - -export default eventHoc; diff --git a/src/actions/actions.js b/src/actions/actions.js index ae1fe65..54ee7f3 100644 --- a/src/actions/actions.js +++ b/src/actions/actions.js @@ -34,7 +34,7 @@ const dragEnd = () => { return { type: DRAG_END }; }; -const dragging = (draggableBlock) => { +const dragStart = (draggableBlock) => { return { type: DRAG_START, payload: draggableBlock }; }; @@ -49,7 +49,7 @@ export { addDigit, chooseOperation, evaluate, - dragging, + dragStart, setDroppableSection, changeConstructorMode, dragEnd, diff --git a/src/components/Button/Button.js b/src/components/Button/Button.js index 84af938..00674c4 100644 --- a/src/components/Button/Button.js +++ b/src/components/Button/Button.js @@ -1,11 +1,24 @@ import React from 'react'; +import { connect } from 'react-redux'; -const Button = ({ className, value, onClick }) => { +const Button = ({ constructorModeEnable, className, value, onClick }) => { + const clickHandler = () => { + if (constructorModeEnable) { + return; + } + onClick(); + }; return ( -
+
{value}
); }; -export default Button; +const mapStateToProps = ({ drag: { constructorModeEnable } }) => { + return { + constructorModeEnable, + }; +}; + +export default connect(mapStateToProps)(Button); diff --git a/src/components/CalcPalette/CalcPalette.js b/src/components/CalcPalette/CalcPalette.js index d541fd6..ffc8f6c 100644 --- a/src/components/CalcPalette/CalcPalette.js +++ b/src/components/CalcPalette/CalcPalette.js @@ -1,17 +1,21 @@ import React, { useState } from 'react'; import { dragEnd, - dragging, + dragStart, setDroppableSection, setBlocks, } from '../../actions/actions'; import { connect } from 'react-redux'; import './CalcPalette.css'; +import DragContainer from '../../HOC/DragContainer'; +import Display from '../Display/Display'; +import DigitalBlock from '../Digital-block/DigitalBlock'; +import Operations from '../Operations/Operations'; +import EqualBlock from '../Equal-block/EqualBlock'; const CalcPalette = ({ - draggableBlock, droppableSection, - dragging, + dragStart, constructorModeEnable, setDroppableSection, dragEnd, @@ -24,7 +28,7 @@ const CalcPalette = ({ const elemIdx = blocks.indexOf(item); if (constructorModeEnable) { setIndex(elemIdx); - dragging(item); + dragStart(item); setTimeout(() => (e.target.style.visibility = 'hidden'), 50); } return; @@ -44,26 +48,41 @@ const CalcPalette = ({ e.target.style.visibility = 'visible'; }; + const renderElement = (element) => { + switch (element) { + case 'Display': + return ; + case 'DigitalBlock': + return ; + case 'Operations': + return ; + case 'EqualBlock': + return ; + default: + return
Error
; + } + }; + return (
{blocks.map((block) => ( - dragStartHandler(e, block)} onDragEnd={dragEndHandler} - /> + > + {renderElement(block.component)} + ))}
); }; const mapStateToProps = ({ - drag: { draggableBlock, droppableSection, blocks }, - calc: { constructorModeEnable }, + drag: { droppableSection, blocks, constructorModeEnable }, }) => { return { - draggableBlock, droppableSection, constructorModeEnable, blocks, @@ -71,7 +90,7 @@ const mapStateToProps = ({ }; const mapDispatchToProps = { - dragging, + dragStart, setDroppableSection, dragEnd, setBlocks, diff --git a/src/components/Desk/Desk.js b/src/components/Desk/Desk.js index 2edd65b..e084a2e 100644 --- a/src/components/Desk/Desk.js +++ b/src/components/Desk/Desk.js @@ -10,6 +10,11 @@ import { import FormGroup from '@mui/material/FormGroup'; import FormControlLabel from '@mui/material/FormControlLabel'; import Switch from '@mui/material/Switch'; +import DragContainer from '../../HOC/DragContainer'; +import Display from '../Display/Display'; +import DigitalBlock from '../Digital-block/DigitalBlock'; +import Operations from '../Operations/Operations'; +import EqualBlock from '../Equal-block/EqualBlock'; import './Desk.css'; const Desk = ({ @@ -94,6 +99,21 @@ const Desk = ({ setDroppableSection(null); }; + const renderElement = (element) => { + switch (element) { + case 'Display': + return ; + case 'DigitalBlock': + return ; + case 'Operations': + return ; + case 'EqualBlock': + return ; + default: + return
Error
; + } + }; + return (
@@ -112,11 +132,13 @@ const Desk = ({ className="desk-item" > {section.items.map((item) => ( - removeBlockFromDesk(item, section)} draggable={false} - /> + > + {renderElement(item.component)} + ))}
))} @@ -132,8 +154,7 @@ const Desk = ({ }; const mapStateToProps = ({ - drag: { draggableBlock, blocks }, - calc: { constructorModeEnable }, + drag: { constructorModeEnable, draggableBlock, blocks }, }) => { return { draggableBlock, diff --git a/src/components/Digital-block/DigitalBlock.js b/src/components/Digital-block/DigitalBlock.js index bab6e01..e3e35e6 100644 --- a/src/components/Digital-block/DigitalBlock.js +++ b/src/components/Digital-block/DigitalBlock.js @@ -2,15 +2,14 @@ import React from 'react'; import Button from '../Button/Button'; import { connect } from 'react-redux'; import { addDigit } from '../../actions/actions'; -import eventHoc from '../../HOC/eventHoc'; import './DigitalBlock.css'; -const numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.']; +const NUMBERS = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.']; const DigitalBlock = ({ addDigit }) => { return (
- {numbers.map((item) => ( + {NUMBERS.map((item) => (
); }; @@ -18,4 +20,4 @@ const mapDispatchToProps = { evaluate, }; -export default connect(null, mapDispatchToProps)(eventHoc(EqualBlock)); +export default connect(null, mapDispatchToProps)(EqualBlock); diff --git a/src/components/Operations/Operations.js b/src/components/Operations/Operations.js index 3ef28e5..8da5f42 100644 --- a/src/components/Operations/Operations.js +++ b/src/components/Operations/Operations.js @@ -2,15 +2,13 @@ import React from 'react'; import Button from '../Button/Button'; import { chooseOperation } from '../../actions/actions'; import { connect } from 'react-redux'; -import eventHoc from '../../HOC/eventHoc'; import './Operations.css'; +const OPERATIONS = ['/', 'x', '-', '+']; const Operations = ({ chooseOperation }) => { - const operations = ['/', 'x', '-', '+']; - return (
- {operations.map((item) => ( + {OPERATIONS.map((item) => (