From 7d70a864fd18366c181eb05b7880848f6bf0776d Mon Sep 17 00:00:00 2001 From: ntr Date: Wed, 17 Oct 2018 13:22:48 +1100 Subject: [PATCH] sort cryp names --- client/.eslintrc.js | 82 +++++++++++---------- client/package.json | 1 + client/src/components/cryp.list.jsx | 6 +- client/src/components/cryp.spawn.button.jsx | 1 - client/src/keyboard.jsx | 3 - client/src/utils.jsx | 20 +++++ 6 files changed, 69 insertions(+), 44 deletions(-) create mode 100644 client/src/utils.jsx diff --git a/client/.eslintrc.js b/client/.eslintrc.js index 0900f02a..f00fd3d1 100755 --- a/client/.eslintrc.js +++ b/client/.eslintrc.js @@ -1,39 +1,45 @@ -module.exports = { - extends: [ - 'eslint:recommended', - 'plugin:react/recommended', - ], - env: { - "browser": true, - "node": true - }, - parserOptions: { - "ecmaVersion": 6 - }, - rules: { - // prevents stupid complaints a la - // (req) { - // req.something = x; - // } - 'no-param-reassign': [2, { props: false }], - 'no-multi-spaces': [0], - 'max-len': ['error', 120], - 'import/no-extraneous-dependencies': [0], - 'prefer-arrow-callback': [0], - 'arrow-body-style': [0], - 'no-return-assign': [2, 'except-parens'], - 'no-console': [0], - // i like loops - 'no-plusplus': [0], - 'no-await-in-loop': [0], - 'indent': ['error', 4], - - // for preact - "react/react-in-jsx-scope": [0], - "react/jsx-indent": [2, 4], - "react/jsx-uses-react": 1, - "react/jsx-uses-vars": 1, - "react/prefer-stateless-function": 1, - "react/prop-types": 0 - }, +module.exports = { + extends: [ + 'eslint:recommended', + 'plugin:react/recommended', + ], + env: { + browser: true, + node: true + }, + parserOptions: { + ecmaVersion: 6 + }, + settings: { + react: { + pragma: "preact", + version: "15.0", + } + }, + rules: { + // prevents stupid complaints a la + // (req) { + // req.something = x; + // } + 'no-param-reassign': [2, { props: false }], + 'no-multi-spaces': [0], + 'max-len': ['error', 120], + 'import/no-extraneous-dependencies': [0], + 'prefer-arrow-callback': [0], + 'arrow-body-style': [0], + 'no-return-assign': [2, 'except-parens'], + 'no-console': [0], + // i like loops + 'no-plusplus': [0], + 'no-await-in-loop': [0], + 'indent': ['error', 4], + + // for preact + "react/react-in-jsx-scope": [0], + "react/jsx-indent": [2, 4], + "react/jsx-uses-react": 1, + "react/jsx-uses-vars": 1, + "react/prefer-stateless-function": 1, + "react/prop-types": 0 + }, }; \ No newline at end of file diff --git a/client/package.json b/client/package.json index eea90bd9..84b02d99 100755 --- a/client/package.json +++ b/client/package.json @@ -17,6 +17,7 @@ "jdenticon": "^2.1.0", "key": "^0.1.11", "keymaster": "^1.6.2", + "lodash": "^4.17.11", "preact": "^8.3.1", "preact-redux": "^2.0.3", "redux": "^4.0.0" diff --git a/client/src/components/cryp.list.jsx b/client/src/components/cryp.list.jsx index 622ee418..7795c2a1 100755 --- a/client/src/components/cryp.list.jsx +++ b/client/src/components/cryp.list.jsx @@ -1,9 +1,11 @@ -// eslint-disable-next-line const preact = require('preact'); +const { stringSort } = require('./../utils'); +const nameSort = stringSort('name'); + function CrypList({ cryps, activeItem, sendCombatPve, sendItemUse }) { if (!cryps) return
not ready
; - const crypPanels = cryps.map(cryp => ( + const crypPanels = cryps.sort(nameSort).map(cryp => (
{ + if (desc) { + return (a, b) => { + if (!get(a, k)) return 1; + if (!get(b, k)) return -1; + return get(b, k).localeCompare(get(a, k)); + }; + } + return (a, b) => { + if (!get(a, k)) return 1; + if (!get(b, k)) return -1; + return get(a, k).localeCompare(get(b, k)); + }; +}; + +module.exports = { + stringSort, +}