From bde772db7f360b84d268316d62b38f1ab78701ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Stani=C3=B3w?= Date: Thu, 4 Jan 2018 00:15:16 +0100 Subject: [PATCH 01/40] Refactor: * Update create-react-app and React-oriented libs. * Remove all usages of decorators. * Change connected Components to React.PureComponent --- .gitignore | 20 +- config/env.js | 28 -- config/eslint.js | 196 ----------- config/jest/cssTransform.js | 12 - config/jest/fileTransform.js | 10 - config/paths.js | 45 --- config/polyfills.js | 14 - config/webpack.config.dev.js | 215 ------------ config/webpack.config.prod.js | 252 -------------- package.json | 143 ++------ public/manifest.json | 15 + scripts/build.js | 224 ------------- scripts/start.js | 315 ------------------ scripts/test.js | 31 -- src/App.css | 28 ++ src/App.js | 21 ++ src/App.test.js | 8 + src/api/config.js | 2 +- src/homepage/components/App.js | 2 +- src/homepage/components/TeamCreationForm.js | 125 +++---- src/index.css | 5 + src/matches/components/MatchesLayout.js | 73 ++-- src/play/components/FoosballTable.js | 7 +- src/play/components/PlayStats.js | 5 +- src/profile/components/ProfileLayout.js | 9 +- src/profile/components/ProfileMatches.js | 135 ++++---- src/profile/components/ProfileSettings.js | 65 ++-- src/profile/components/ProfileStats.js | 80 ++--- src/profile/components/index.js | 10 +- src/ranking/components/RankingLayout.js | 5 +- src/registerServiceWorker.js | 108 ++++++ src/setupTests.js | 5 + .../auth/components/InvitationLayout.js | 75 ++--- src/shared/components/Header.js | 105 +++--- src/shared/components/ModalMessage.js | 5 +- src/shared/components/Notifications.js | 3 +- src/shared/components/Widget.js | 40 +-- src/shared/shared.sagas.js | 34 +- src/shared/whatsnew.md | 25 +- src/teams/components/ClubsLayout.js | 3 +- src/teams/components/JoinTeamForm.js | 129 +++---- src/teams/components/PendingMemberList.js | 5 +- src/teams/components/TeamAdmin.js | 4 +- src/teams/components/TeamInvite.js | 4 +- src/teams/components/TeamList.js | 5 +- src/teams/components/index.js | 16 +- src/tournament/components/TournamentLayout.js | 38 +-- src/users/components/MatchToolbar.js | 5 +- src/users/components/UserPicker.js | 5 +- src/utils/checkMobile.js | 10 +- 50 files changed, 728 insertions(+), 1996 deletions(-) delete mode 100644 config/env.js delete mode 100644 config/eslint.js delete mode 100644 config/jest/cssTransform.js delete mode 100644 config/jest/fileTransform.js delete mode 100644 config/paths.js delete mode 100644 config/polyfills.js delete mode 100644 config/webpack.config.dev.js delete mode 100644 config/webpack.config.prod.js create mode 100644 public/manifest.json delete mode 100644 scripts/build.js delete mode 100644 scripts/start.js delete mode 100644 scripts/test.js create mode 100644 src/App.css create mode 100644 src/App.js create mode 100644 src/App.test.js create mode 100644 src/index.css create mode 100644 src/registerServiceWorker.js create mode 100644 src/setupTests.js diff --git a/.gitignore b/.gitignore index 5e4f0d5..d30f40e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,21 @@ -# See http://help.github.com/ignore-files/ for more about ignoring files. +# See https://help.github.com/ignore-files/ for more about ignoring files. # dependencies -node_modules +/node_modules # testing -coverage +/coverage # production -build -tfoostrap/build +/build # misc .DS_Store -.env -npm-debug.log -.idea/ +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/config/env.js b/config/env.js deleted file mode 100644 index 5d0ab7b..0000000 --- a/config/env.js +++ /dev/null @@ -1,28 +0,0 @@ -// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be -// injected into the application via DefinePlugin in Webpack configuration. - -var REACT_APP = /^REACT_APP_/i; - -function getClientEnvironment(publicUrl) { - var processEnv = Object - .keys(process.env) - .filter(key => REACT_APP.test(key)) - .reduce((env, key) => { - env[key] = JSON.stringify(process.env[key]); - return env; - }, { - // Useful for determining whether we’re running in production mode. - // Most importantly, it switches React into the correct mode. - 'NODE_ENV': JSON.stringify( - process.env.NODE_ENV || 'development' - ), - // Useful for resolving the correct path to static assets in `public`. - // For example, . - // This should only be used as an escape hatch. Normally you would put - // images into the `src` and `import` them in code to get their paths. - 'PUBLIC_URL': JSON.stringify(publicUrl) - }); - return {'process.env': processEnv}; -} - -module.exports = getClientEnvironment; diff --git a/config/eslint.js b/config/eslint.js deleted file mode 100644 index 1e0479f..0000000 --- a/config/eslint.js +++ /dev/null @@ -1,196 +0,0 @@ -// Inspired by https://github.com/airbnb/javascript but less opinionated. - -// We use eslint-loader so even warnings are very visibile. -// This is why we only use "WARNING" level for potential errors, -// and we don't use "ERROR" level at all. - -// In the future, we might create a separate list of rules for production. -// It would probably be more strict. - -module.exports = { - root: true, - - parser: 'babel-eslint', - - // import plugin is termporarily disabled, scroll below to see why - plugins: [/*'import', */'flowtype', 'jsx-a11y', 'react'], - - env: { - browser: true, - commonjs: true, - es6: true, - node: true - }, - - parserOptions: { - ecmaVersion: 6, - sourceType: 'module', - ecmaFeatures: { - jsx: true, - generators: true, - experimentalObjectRestSpread: true - } - }, - - settings: { - 'import/ignore': [ - 'node_modules', - '\\.(json|css|jpg|png|gif|eot|svg|ttf|woff|woff2|mp4|webm)$', - ], - 'import/extensions': ['.js'], - 'import/resolver': { - node: { - extensions: ['.js', '.json'] - } - } - }, - - rules: { - // http://eslint.org/docs/rules/ - 'array-callback-return': 'warn', - 'default-case': ['warn', { commentPattern: '^no default$' }], - 'dot-location': ['warn', 'property'], - eqeqeq: ['warn', 'allow-null'], - 'guard-for-in': 'warn', - 'new-cap': ['warn', { newIsCap: true }], - 'new-parens': 'warn', - 'no-array-constructor': 'warn', - 'no-caller': 'warn', - 'no-cond-assign': ['warn', 'always'], - 'no-const-assign': 'warn', - 'no-control-regex': 'warn', - 'no-delete-var': 'warn', - 'no-dupe-args': 'warn', - 'no-dupe-class-members': 'warn', - 'no-dupe-keys': 'warn', - 'no-duplicate-case': 'warn', - 'no-empty-character-class': 'warn', - 'no-empty-pattern': 'warn', - 'no-eval': 'warn', - 'no-ex-assign': 'warn', - 'no-extend-native': 'warn', - 'no-extra-bind': 'warn', - 'no-extra-label': 'warn', - 'no-fallthrough': 'warn', - 'no-func-assign': 'warn', - 'no-implied-eval': 'warn', - 'no-invalid-regexp': 'warn', - 'no-iterator': 'warn', - 'no-label-var': 'warn', - 'no-labels': ['warn', { allowLoop: false, allowSwitch: false }], - 'no-lone-blocks': 'warn', - 'no-loop-func': 'warn', - 'no-mixed-operators': ['warn', { - groups: [ - ['&', '|', '^', '~', '<<', '>>', '>>>'], - ['==', '!=', '===', '!==', '>', '>=', '<', '<='], - ['&&', '||'], - ['in', 'instanceof'] - ], - allowSamePrecedence: false - }], - 'no-multi-str': 'warn', - 'no-native-reassign': 'warn', - 'no-negated-in-lhs': 'warn', - 'no-new-func': 'warn', - 'no-new-object': 'warn', - 'no-new-symbol': 'warn', - 'no-new-wrappers': 'warn', - 'no-obj-calls': 'warn', - 'no-octal': 'warn', - 'no-octal-escape': 'warn', - 'no-redeclare': 'warn', - 'no-regex-spaces': 'warn', - 'no-restricted-syntax': [ - 'warn', - 'LabeledStatement', - 'WithStatement', - ], - 'no-return-assign': 'warn', - 'no-script-url': 'warn', - 'no-self-assign': 'warn', - 'no-self-compare': 'warn', - 'no-sequences': 'warn', - 'no-shadow-restricted-names': 'warn', - 'no-sparse-arrays': 'warn', - 'no-this-before-super': 'warn', - 'no-throw-literal': 'warn', - 'no-undef': 'warn', - 'no-unexpected-multiline': 'warn', - 'no-unreachable': 'warn', - 'no-unused-expressions': 'warn', - 'no-unused-labels': 'warn', - 'no-unused-vars': ['warn', { vars: 'local', args: 'none' }], - 'no-use-before-define': ['warn', 'nofunc'], - 'no-useless-computed-key': 'warn', - 'no-useless-concat': 'warn', - 'no-useless-constructor': 'warn', - 'no-useless-escape': 'warn', - 'no-useless-rename': ['warn', { - ignoreDestructuring: false, - ignoreImport: false, - ignoreExport: false, - }], - 'no-with': 'warn', - 'no-whitespace-before-property': 'warn', - 'operator-assignment': ['warn', 'always'], - radix: 'warn', - 'require-yield': 'warn', - 'rest-spread-spacing': ['warn', 'never'], - strict: ['warn', 'never'], - 'unicode-bom': ['warn', 'never'], - 'use-isnan': 'warn', - 'valid-typeof': 'warn', - - // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/ - - // TODO: import rules are temporarily disabled because they don't play well - // with how eslint-loader only checks the file you change. So if module A - // imports module B, and B is missing a default export, the linter will - // record this as an issue in module A. Now if you fix module B, the linter - // will not be aware that it needs to re-lint A as well, so the error - // will stay until the next restart, which is really confusing. - - // This is probably fixable with a patch to eslint-loader. - // When file A is saved, we want to invalidate all files that import it - // *and* that currently have lint errors. This should fix the problem. - - // 'import/default': 'warn', - // 'import/export': 'warn', - // 'import/named': 'warn', - // 'import/namespace': 'warn', - // 'import/no-amd': 'warn', - // 'import/no-duplicates': 'warn', - // 'import/no-extraneous-dependencies': 'warn', - // 'import/no-named-as-default': 'warn', - // 'import/no-named-as-default-member': 'warn', - // 'import/no-unresolved': ['warn', { commonjs: true }], - - // https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules - 'react/jsx-equals-spacing': ['warn', 'never'], - 'react/jsx-no-duplicate-props': ['warn', { ignoreCase: true }], - 'react/jsx-no-undef': 'warn', - 'react/jsx-pascal-case': ['warn', { - allowAllCaps: true, - ignore: [], - }], - 'react/jsx-uses-react': 'warn', - 'react/jsx-uses-vars': 'warn', - 'react/no-deprecated': 'warn', - 'react/no-direct-mutation-state': 'warn', - 'react/no-is-mounted': 'warn', - 'react/react-in-jsx-scope': 'warn', - 'react/require-render-return': 'warn', - - // https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules - 'jsx-a11y/aria-role': 'warn', - 'jsx-a11y/img-has-alt': 'warn', - 'jsx-a11y/img-redundant-alt': 'warn', - 'jsx-a11y/no-access-key': 'warn', - - // https://github.com/gajus/eslint-plugin-flowtype - 'flowtype/define-flow-type': 'warn', - 'flowtype/require-valid-file-annotation': 'warn', - 'flowtype/use-flow-type': 'warn' - } -}; diff --git a/config/jest/cssTransform.js b/config/jest/cssTransform.js deleted file mode 100644 index aa17d12..0000000 --- a/config/jest/cssTransform.js +++ /dev/null @@ -1,12 +0,0 @@ -// This is a custom Jest transformer turning style imports into empty objects. -// http://facebook.github.io/jest/docs/tutorial-webpack.html - -module.exports = { - process() { - return 'module.exports = {};'; - }, - getCacheKey(fileData, filename) { - // The output is always the same. - return 'cssTransform'; - }, -}; diff --git a/config/jest/fileTransform.js b/config/jest/fileTransform.js deleted file mode 100644 index 927eb30..0000000 --- a/config/jest/fileTransform.js +++ /dev/null @@ -1,10 +0,0 @@ -const path = require('path'); - -// This is a custom Jest transformer turning file imports into filenames. -// http://facebook.github.io/jest/docs/tutorial-webpack.html - -module.exports = { - process(src, filename) { - return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';'; - }, -}; diff --git a/config/paths.js b/config/paths.js deleted file mode 100644 index e831b59..0000000 --- a/config/paths.js +++ /dev/null @@ -1,45 +0,0 @@ -var path = require('path'); -var fs = require('fs'); - -// Make sure any symlinks in the project folder are resolved: -// https://github.com/facebookincubator/create-react-app/issues/637 -var appDirectory = fs.realpathSync(process.cwd()); -function resolveApp(relativePath) { - return path.resolve(appDirectory, relativePath); -} - -// We support resolving modules according to `NODE_PATH`. -// This lets you use absolute paths in imports inside large monorepos: -// https://github.com/facebookincubator/create-react-app/issues/253. - -// It works similar to `NODE_PATH` in Node itself: -// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders - -// We will export `nodePaths` as an array of absolute paths. -// It will then be used by Webpack configs. -// Jest doesn’t need this because it already handles `NODE_PATH` out of the box. - -// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored. -// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. -// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421 - -var nodePaths = (process.env.NODE_PATH || '') - .split(process.platform === 'win32' ? ';' : ':') - .filter(Boolean) - .filter(folder => !path.isAbsolute(folder)) - .map(resolveApp); - -// config after eject: we're in ./config/ -module.exports = { - appBuild: resolveApp('build'), - appPublic: resolveApp('public'), - appHtml: resolveApp('public/index.html'), - appIndexJs: resolveApp('src/index.js'), - appPackageJson: resolveApp('package.json'), - appSrc: resolveApp('src'), - yarnLockFile: resolveApp('yarn.lock'), - testsSetup: resolveApp('src/setupTests.js'), - appNodeModules: resolveApp('node_modules'), - ownNodeModules: resolveApp('node_modules'), - nodePaths: nodePaths -}; diff --git a/config/polyfills.js b/config/polyfills.js deleted file mode 100644 index 7e60150..0000000 --- a/config/polyfills.js +++ /dev/null @@ -1,14 +0,0 @@ -if (typeof Promise === 'undefined') { - // Rejection tracking prevents a common issue where React gets into an - // inconsistent state due to an error, but it gets swallowed by a Promise, - // and the user has no idea what causes React's erratic future behavior. - require('promise/lib/rejection-tracking').enable(); - window.Promise = require('promise/lib/es6-extensions.js'); -} - -// fetch() polyfill for making API calls. -require('whatwg-fetch'); - -// Object.assign() is commonly used with React. -// It will use the native implementation if it's present and isn't buggy. -Object.assign = require('object-assign'); diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js deleted file mode 100644 index 3e4ae6a..0000000 --- a/config/webpack.config.dev.js +++ /dev/null @@ -1,215 +0,0 @@ -var autoprefixer = require('autoprefixer'); -var webpack = require('webpack'); -var HtmlWebpackPlugin = require('html-webpack-plugin'); -var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); -var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); -var WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin'); -var getClientEnvironment = require('./env'); -var paths = require('./paths'); - - - -// Webpack uses `publicPath` to determine where the app is being served from. -// In development, we always serve from the root. This makes config easier. -var publicPath = '/'; -// `publicUrl` is just like `publicPath`, but we will provide it to our app -// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript. -// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz. -var publicUrl = ''; -// Get environment variables to inject into our app. -var env = getClientEnvironment(publicUrl); - -// This is the development configuration. -// It is focused on developer experience and fast rebuilds. -// The production configuration is different and lives in a separate file. -module.exports = { - // You may want 'eval' instead if you prefer to see the compiled output in DevTools. - // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343. - devtool: 'cheap-module-source-map', - // These are the "entry points" to our application. - // This means they will be the "root" imports that are included in JS bundle. - // The first two entry points enable "hot" CSS and auto-refreshes for JS. - entry: [ - // Include an alternative client for WebpackDevServer. A client's job is to - // connect to WebpackDevServer by a socket and get notified about changes. - // When you save a file, the client will either apply hot updates (in case - // of CSS changes), or refresh the page (in case of JS changes). When you - // make a syntax error, this client will display a syntax error overlay. - // Note: instead of the default WebpackDevServer client, we use a custom one - // to bring better experience for Create React App users. You can replace - // the line below with these two lines if you prefer the stock client: - // require.resolve('webpack-dev-server/client') + '?/', - // require.resolve('webpack/hot/dev-server'), - require.resolve('react-dev-utils/webpackHotDevClient'), - // We ship a few polyfills by default: - require.resolve('./polyfills'), - // Finally, this is your app's code: - paths.appIndexJs - // We include the app code last so that if there is a runtime error during - // initialization, it doesn't blow up the WebpackDevServer client, and - // changing JS code would still trigger a refresh. - ], - output: { - // Next line is not used in dev but WebpackDevServer crashes without it: - path: paths.appBuild, - // Add /* filename */ comments to generated require()s in the output. - pathinfo: true, - // This does not produce a real file. It's just the virtual path that is - // served by WebpackDevServer in development. This is the JS bundle - // containing code from all our entry points, and the Webpack runtime. - filename: 'static/js/bundle.js', - // This is the URL that app is served from. We use "/" in development. - publicPath: publicPath - }, - resolve: { - // This allows you to set a fallback for where Webpack should look for modules. - // We read `NODE_PATH` environment variable in `paths.js` and pass paths here. - // We use `fallback` instead of `root` because we want `node_modules` to "win" - // if there any conflicts. This matches Node resolution mechanism. - // https://github.com/facebookincubator/create-react-app/issues/253 - fallback: paths.nodePaths, - // These are the reasonable defaults supported by the Node ecosystem. - // We also include JSX as a common component filename extension to support - // some tools, although we do not recommend using it, see: - // https://github.com/facebookincubator/create-react-app/issues/290 - extensions: ['.js', '.json', '.jsx', ''], - alias: { - // Support React Native Web - // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ - 'react-native': 'react-native-web' - } - }, - - module: { - // First, run the linter. - // It's important to do this before Babel processes the JS. - preLoaders: [ - { - test: /\.(js|jsx)$/, - loader: 'eslint', - include: paths.appSrc, - } - ], - loaders: [ - // Default loader: load all assets that are not handled - // by other loaders with the url loader. - // Note: This list needs to be updated with every change of extensions - // the other loaders match. - // E.g., when adding a loader for a new supported file extension, - // we need to add the supported extension to this loader too. - // Add one new line in `exclude` for each loader. - // - // "file" loader makes sure those assets get served by WebpackDevServer. - // When you `import` an asset, you get its (virtual) filename. - // In production, they would get copied to the `build` folder. - // "url" loader works like "file" loader except that it embeds assets - // smaller than specified limit in bytes as data URLs to avoid requests. - // A missing `test` is equivalent to a match. - { - exclude: [ - /\.html$/, - /\.(js|jsx)$/, - /\.css$/, - /\.json$/, - /\.svg$/, - /\.md$/ - ], - loader: 'url', - query: { - limit: 10000, - name: 'static/media/[name].[hash:8].[ext]' - } - }, - // Process Markdown as raw - { - test: /\.md$/, - include: paths.appSrc, - loader: 'raw-loader' - }, - // Process JS with Babel. - { - test: /\.(js|jsx)$/, - include: paths.appSrc, - loader: 'babel', - query: { - - // This is a feature of `babel-loader` for webpack (not Babel itself). - // It enables caching results in ./node_modules/.cache/babel-loader/ - // directory for faster rebuilds. - cacheDirectory: true - } - }, - // "postcss" loader applies autoprefixer to our CSS. - // "css" loader resolves paths in CSS and adds assets as dependencies. - // "style" loader turns CSS into JS modules that inject