From 8a5831d99b201e519480da1cf52077095d890baf Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 22 May 2022 14:54:52 -0500 Subject: add eslint and basic config --- src/web/.eslintrc | 30 +++++++++++ src/web/package-lock.json | 129 ++++++++++++++++++++-------------------------- src/web/package.json | 22 ++++---- 3 files changed, 98 insertions(+), 83 deletions(-) create mode 100644 src/web/.eslintrc (limited to 'src/web') diff --git a/src/web/.eslintrc b/src/web/.eslintrc new file mode 100644 index 00000000..060d0f2a --- /dev/null +++ b/src/web/.eslintrc @@ -0,0 +1,30 @@ +{ + "env": { + "browser": true, + "jest": true, + "es6": true + }, + "plugins": ["import"], + "extends": ["eslint:recommended", "react-app"], + "parserOptions": { + "ecmaVersion": "latest" + }, + "rules": { + "max-len": ["warn", 120], + "quotes": ["warn", "double"], + "indent": ["warn", 2], + "comma-dangle": ["warn", { + "arrays": "always-multiline", + "objects": "always-multiline", + "imports": "always-multiline", + "exports": "always-multiline", + "functions": "never" + }], + "camelcase": "warn", + "import/first": "warn", + "prefer-destructuring": ["warn"], + "no-await-in-loop": "error", + "require-atomic-updates": "error", + "curly": ["warn", "multi-line"] + } +} \ No newline at end of file diff --git a/src/web/package-lock.json b/src/web/package-lock.json index 86bb72af..0e1481c9 100644 --- a/src/web/package-lock.json +++ b/src/web/package-lock.json @@ -5,7 +5,6 @@ "requires": true, "packages": { "": { - "name": "web", "version": "0.1.0", "hasInstallScript": true, "dependencies": { @@ -31,6 +30,7 @@ }, "devDependencies": { "@semantic-ui-react/css-patch": "^1.0.0", + "eslint": "^8.16.0", "react-scripts": "^5.0.0" } }, @@ -2353,19 +2353,19 @@ } }, "node_modules/@eslint/eslintrc": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.1.0.tgz", - "integrity": "sha512-C1DfL7XX4nPqGd6jcP01W9pVM1HYCuUkFk1432D7F0v3JSlUIeOYn9oCoi3eoLZ+iwBSb29BMFxxny0YrrEZqg==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", + "integrity": "sha512-UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw==", "dev": true, "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", - "espree": "^9.3.1", - "globals": "^13.9.0", - "ignore": "^4.0.6", + "espree": "^9.3.2", + "globals": "^13.15.0", + "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.1.0", - "minimatch": "^3.0.4", + "minimatch": "^3.1.2", "strip-json-comments": "^3.1.1" }, "engines": { @@ -2379,9 +2379,9 @@ "dev": true }, "node_modules/@eslint/eslintrc/node_modules/globals": { - "version": "13.12.1", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.12.1.tgz", - "integrity": "sha512-317dFlgY2pdJZ9rspXDks7073GpDmXdfbM3vYYp0HAMKGDh1FfWPleI2ljVNLQX5M5lXcAslTcPTrOrMEFOjyw==", + "version": "13.15.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.15.0.tgz", + "integrity": "sha512-bpzcOlgDhMG070Av0Vy5Owklpv1I6+j96GhUI7Rh7IzDCKLzboflLrrfqMu8NquDbiR4EOQk7XzJwqVJxicxog==", "dev": true, "dependencies": { "type-fest": "^0.20.2" @@ -2393,15 +2393,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/@eslint/eslintrc/node_modules/ignore": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", - "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", - "dev": true, - "engines": { - "node": ">= 4" - } - }, "node_modules/@eslint/eslintrc/node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -4388,9 +4379,9 @@ } }, "node_modules/acorn": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz", - "integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==", + "version": "8.7.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", + "integrity": "sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -7565,12 +7556,12 @@ } }, "node_modules/eslint": { - "version": "8.9.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.9.0.tgz", - "integrity": "sha512-PB09IGwv4F4b0/atrbcMFboF/giawbBLVC7fyDamk5Wtey4Jh2K+rYaBhCAbUyEI4QzB1ly09Uglc9iCtFaG2Q==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.16.0.tgz", + "integrity": "sha512-MBndsoXY/PeVTDJeWsYj7kLZ5hQpJOfMYLsF6LicLHQWbRDG19lK5jOix4DPl8yY4SUFcE3txy86OzFLWT+yoA==", "dev": true, "dependencies": { - "@eslint/eslintrc": "^1.1.0", + "@eslint/eslintrc": "^1.3.0", "@humanwhocodes/config-array": "^0.9.2", "ajv": "^6.10.0", "chalk": "^4.0.0", @@ -7581,14 +7572,14 @@ "eslint-scope": "^7.1.1", "eslint-utils": "^3.0.0", "eslint-visitor-keys": "^3.3.0", - "espree": "^9.3.1", + "espree": "^9.3.2", "esquery": "^1.4.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^6.0.1", "functional-red-black-tree": "^1.0.1", "glob-parent": "^6.0.1", - "globals": "^13.6.0", + "globals": "^13.15.0", "ignore": "^5.2.0", "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", @@ -7597,7 +7588,7 @@ "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", "lodash.merge": "^4.6.2", - "minimatch": "^3.0.4", + "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.1", "regexpp": "^3.2.0", @@ -8047,9 +8038,9 @@ } }, "node_modules/eslint/node_modules/globals": { - "version": "13.12.1", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.12.1.tgz", - "integrity": "sha512-317dFlgY2pdJZ9rspXDks7073GpDmXdfbM3vYYp0HAMKGDh1FfWPleI2ljVNLQX5M5lXcAslTcPTrOrMEFOjyw==", + "version": "13.15.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.15.0.tgz", + "integrity": "sha512-bpzcOlgDhMG070Av0Vy5Owklpv1I6+j96GhUI7Rh7IzDCKLzboflLrrfqMu8NquDbiR4EOQk7XzJwqVJxicxog==", "dev": true, "dependencies": { "type-fest": "^0.20.2" @@ -8098,13 +8089,13 @@ } }, "node_modules/espree": { - "version": "9.3.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.3.1.tgz", - "integrity": "sha512-bvdyLmJMfwkV3NCRl5ZhJf22zBFo1y8bYh3VYb+bfzqNB4Je68P2sSuXyuFquzWLebHpNd2/d5uv7yoP9ISnGQ==", + "version": "9.3.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.3.2.tgz", + "integrity": "sha512-D211tC7ZwouTIuY5x9XnS0E9sWNChB7IYKX/Xp5eQj3nFXhqmiUDB9q27y76oFl8jTg3pXcQx/bpxMfs3CIZbA==", "dev": true, "dependencies": { - "acorn": "^8.7.0", - "acorn-jsx": "^5.3.1", + "acorn": "^8.7.1", + "acorn-jsx": "^5.3.2", "eslint-visitor-keys": "^3.3.0" }, "engines": { @@ -21202,19 +21193,19 @@ } }, "@eslint/eslintrc": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.1.0.tgz", - "integrity": "sha512-C1DfL7XX4nPqGd6jcP01W9pVM1HYCuUkFk1432D7F0v3JSlUIeOYn9oCoi3eoLZ+iwBSb29BMFxxny0YrrEZqg==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", + "integrity": "sha512-UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw==", "dev": true, "requires": { "ajv": "^6.12.4", "debug": "^4.3.2", - "espree": "^9.3.1", - "globals": "^13.9.0", - "ignore": "^4.0.6", + "espree": "^9.3.2", + "globals": "^13.15.0", + "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.1.0", - "minimatch": "^3.0.4", + "minimatch": "^3.1.2", "strip-json-comments": "^3.1.1" }, "dependencies": { @@ -21225,20 +21216,14 @@ "dev": true }, "globals": { - "version": "13.12.1", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.12.1.tgz", - "integrity": "sha512-317dFlgY2pdJZ9rspXDks7073GpDmXdfbM3vYYp0HAMKGDh1FfWPleI2ljVNLQX5M5lXcAslTcPTrOrMEFOjyw==", + "version": "13.15.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.15.0.tgz", + "integrity": "sha512-bpzcOlgDhMG070Av0Vy5Owklpv1I6+j96GhUI7Rh7IzDCKLzboflLrrfqMu8NquDbiR4EOQk7XzJwqVJxicxog==", "dev": true, "requires": { "type-fest": "^0.20.2" } }, - "ignore": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", - "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", - "dev": true - }, "js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -22752,9 +22737,9 @@ } }, "acorn": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz", - "integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==", + "version": "8.7.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", + "integrity": "sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==", "dev": true }, "acorn-globals": { @@ -25200,12 +25185,12 @@ } }, "eslint": { - "version": "8.9.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.9.0.tgz", - "integrity": "sha512-PB09IGwv4F4b0/atrbcMFboF/giawbBLVC7fyDamk5Wtey4Jh2K+rYaBhCAbUyEI4QzB1ly09Uglc9iCtFaG2Q==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.16.0.tgz", + "integrity": "sha512-MBndsoXY/PeVTDJeWsYj7kLZ5hQpJOfMYLsF6LicLHQWbRDG19lK5jOix4DPl8yY4SUFcE3txy86OzFLWT+yoA==", "dev": true, "requires": { - "@eslint/eslintrc": "^1.1.0", + "@eslint/eslintrc": "^1.3.0", "@humanwhocodes/config-array": "^0.9.2", "ajv": "^6.10.0", "chalk": "^4.0.0", @@ -25216,14 +25201,14 @@ "eslint-scope": "^7.1.1", "eslint-utils": "^3.0.0", "eslint-visitor-keys": "^3.3.0", - "espree": "^9.3.1", + "espree": "^9.3.2", "esquery": "^1.4.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^6.0.1", "functional-red-black-tree": "^1.0.1", "glob-parent": "^6.0.1", - "globals": "^13.6.0", + "globals": "^13.15.0", "ignore": "^5.2.0", "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", @@ -25232,7 +25217,7 @@ "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", "lodash.merge": "^4.6.2", - "minimatch": "^3.0.4", + "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.1", "regexpp": "^3.2.0", @@ -25255,9 +25240,9 @@ "dev": true }, "globals": { - "version": "13.12.1", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.12.1.tgz", - "integrity": "sha512-317dFlgY2pdJZ9rspXDks7073GpDmXdfbM3vYYp0HAMKGDh1FfWPleI2ljVNLQX5M5lXcAslTcPTrOrMEFOjyw==", + "version": "13.15.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.15.0.tgz", + "integrity": "sha512-bpzcOlgDhMG070Av0Vy5Owklpv1I6+j96GhUI7Rh7IzDCKLzboflLrrfqMu8NquDbiR4EOQk7XzJwqVJxicxog==", "dev": true, "requires": { "type-fest": "^0.20.2" @@ -25591,13 +25576,13 @@ } }, "espree": { - "version": "9.3.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.3.1.tgz", - "integrity": "sha512-bvdyLmJMfwkV3NCRl5ZhJf22zBFo1y8bYh3VYb+bfzqNB4Je68P2sSuXyuFquzWLebHpNd2/d5uv7yoP9ISnGQ==", + "version": "9.3.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.3.2.tgz", + "integrity": "sha512-D211tC7ZwouTIuY5x9XnS0E9sWNChB7IYKX/Xp5eQj3nFXhqmiUDB9q27y76oFl8jTg3pXcQx/bpxMfs3CIZbA==", "dev": true, "requires": { - "acorn": "^8.7.0", - "acorn-jsx": "^5.3.1", + "acorn": "^8.7.1", + "acorn-jsx": "^5.3.2", "eslint-visitor-keys": "^3.3.0" } }, diff --git a/src/web/package.json b/src/web/package.json index 6603a2e5..2049e07a 100644 --- a/src/web/package.json +++ b/src/web/package.json @@ -3,6 +3,16 @@ "version": "0.1.0", "private": true, "homepage": ".", + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "test-unattended": "react-scripts test --watchAll false --passWithNoTests", + "eject": "react-scripts eject", + "postinstall": "semantic-ui-css-patch", + "lint": "eslint .", + "lint:fix": "eslint --fix ." + }, "dependencies": { "@codemirror/highlight": "^0.19.7", "@codemirror/legacy-modes": "^0.19.0", @@ -26,19 +36,9 @@ }, "devDependencies": { "@semantic-ui-react/css-patch": "^1.0.0", + "eslint": "^8.16.0", "react-scripts": "^5.0.0" }, - "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "test-unattended": "react-scripts test --watchAll false --passWithNoTests", - "eject": "react-scripts eject", - "postinstall": "semantic-ui-css-patch" - }, - "eslintConfig": { - "extends": "react-app" - }, "browserslist": { "production": [ ">0.3%", -- cgit v1.2.3 From 044c4c5bb2be3b0a310154cdaf14feb0ea66c55a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 22 May 2022 15:20:27 -0500 Subject: apply formatting changes to fix new linting rules --- src/web/.eslintrc | 2 +- src/web/src/components/App.js | 39 +++- src/web/src/components/Browse/Browse.js | 78 ++++--- src/web/src/components/Browse/Directory.js | 18 +- src/web/src/components/Browse/DirectoryTree.js | 52 ++--- src/web/src/components/Chat/Chat.js | 127 +++++----- src/web/src/components/Chat/ChatMenu.js | 2 +- src/web/src/components/Chat/SendMessageModal.js | 12 +- src/web/src/components/LoginForm.js | 6 +- src/web/src/components/Rooms/RoomJoinModal.js | 92 ++++---- src/web/src/components/Rooms/RoomMenu.js | 2 +- src/web/src/components/Rooms/RoomUserList.js | 2 +- src/web/src/components/Rooms/Rooms.js | 141 +++++------ .../src/components/Search/Detail/SearchDetail.js | 24 +- .../components/Search/Detail/SearchDetailHeader.js | 13 +- src/web/src/components/Search/List/SearchList.js | 56 +++-- .../src/components/Search/List/SearchListRow.js | 2 +- src/web/src/components/Search/Response.js | 242 +++++++++---------- src/web/src/components/Search/SearchStatusIcon.js | 30 +-- src/web/src/components/Search/Searches.js | 18 +- src/web/src/components/Shared/ErrorSegment.js | 10 +- src/web/src/components/Shared/FileList.js | 28 +-- .../src/components/Shared/PlaceholderSegment.js | 10 +- src/web/src/components/System/Logs.js | 12 +- src/web/src/components/System/Options/Edit.js | 3 +- src/web/src/components/System/System.js | 7 +- src/web/src/components/Transfers/TransferGroup.js | 258 +++++++++++---------- src/web/src/components/Transfers/TransferList.js | 237 +++++++++---------- src/web/src/components/Transfers/Transfers.js | 14 +- src/web/src/components/Users/User.js | 63 ++--- src/web/src/components/Users/Users.js | 13 +- src/web/src/config.js | 18 +- src/web/src/index.js | 9 +- src/web/src/lib/api.js | 16 +- src/web/src/lib/hubFactory.js | 6 +- src/web/src/lib/searches.js | 22 +- src/web/src/lib/searches.test.js | 108 ++++----- src/web/src/lib/util.js | 118 +++++----- 38 files changed, 1009 insertions(+), 901 deletions(-) (limited to 'src/web') diff --git a/src/web/.eslintrc b/src/web/.eslintrc index 060d0f2a..8b047235 100644 --- a/src/web/.eslintrc +++ b/src/web/.eslintrc @@ -11,7 +11,7 @@ }, "rules": { "max-len": ["warn", 120], - "quotes": ["warn", "double"], + "quotes": ["warn", "single"], "indent": ["warn", 2], "comma-dangle": ["warn", { "arrays": "always-multiline", diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index 5e5ed10f..1078935a 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { Route, Link, Switch, Redirect } from "react-router-dom"; +import { Route, Link, Switch, Redirect } from 'react-router-dom'; import { ToastContainer } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; @@ -29,7 +29,7 @@ import { Modal, Header, Button, - Loader + Loader, } from 'semantic-ui-react'; import Rooms from './Rooms/Rooms'; import ErrorSegment from './Shared/ErrorSegment'; @@ -37,7 +37,7 @@ import ErrorSegment from './Shared/ErrorSegment'; const initialState = { login: { pending: false, - error: undefined + error: undefined, }, applicationState: {}, applicationOptions: {}, @@ -125,9 +125,15 @@ class App extends Component { if (error) { return Lost connection to slskd
{(retriesExhausted ? 'Refresh to reconnect' : 'Retrying...')}}/>; + suppressPrefix + icon='attention' + caption={ + <> + + Lost connection to slskd
{(retriesExhausted ? 'Refresh to reconnect' : 'Retrying...')} + + + }/>; } if (!session.isLoggedIn() && !session.isPassthroughEnabled()) { @@ -218,7 +224,10 @@ class App extends Component { > New Version! -

You are currently running version {current} while version {latest} is available.

+

+ You are currently running version {current} + while version {latest} is available. +

diff --git a/src/web/src/components/Rooms/RoomMenu.js b/src/web/src/components/Rooms/RoomMenu.js index c77dd8fb..485646d6 100644 --- a/src/web/src/components/Rooms/RoomMenu.js +++ b/src/web/src/components/Rooms/RoomMenu.js @@ -2,7 +2,7 @@ import React from 'react'; import './Rooms.css'; import { - Icon, Button, Menu + Icon, Button, Menu, } from 'semantic-ui-react'; import RoomJoinModal from './RoomJoinModal'; diff --git a/src/web/src/components/Rooms/RoomUserList.js b/src/web/src/components/Rooms/RoomUserList.js index c719e5f1..0a891e88 100644 --- a/src/web/src/components/Rooms/RoomUserList.js +++ b/src/web/src/components/Rooms/RoomUserList.js @@ -2,7 +2,7 @@ import React, { useMemo } from 'react'; import './Rooms.css'; import { - Icon, Flag, List, Popup + Icon, Flag, List, Popup, } from 'semantic-ui-react'; const RoomUserList = ({ users }) => { diff --git a/src/web/src/components/Rooms/Rooms.js b/src/web/src/components/Rooms/Rooms.js index 524aeee9..e19face3 100644 --- a/src/web/src/components/Rooms/Rooms.js +++ b/src/web/src/components/Rooms/Rooms.js @@ -13,13 +13,13 @@ const initialState = { joined: [], room: { messages: [], - users: [] + users: [], }, intervals: { rooms: undefined, - messages: undefined + messages: undefined, }, - loading: false + loading: false, } class Rooms extends Component { @@ -31,9 +31,9 @@ class Rooms extends Component { this.setState({ intervals: { rooms: window.setInterval(this.fetchJoinedRooms, 500), - messages: window.setInterval(this.fetchActiveRoom, 1000) + messages: window.setInterval(this.fetchActiveRoom, 1000), }, - active: sessionStorage.getItem(activeRoomKey) || '' + active: sessionStorage.getItem(activeRoomKey) || '', }, async () => { await this.fetchJoinedRooms(); this.selectRoom(this.state.active || this.getFirstRoom()) @@ -54,9 +54,9 @@ class Rooms extends Component { } fetchJoinedRooms = async () => { - const joined = await rooms.getJoined();; + const joined = await rooms.getJoined(); this.setState({ - joined + joined, }, () => { if (!this.state.joined.includes(this.state.active)) { this.selectRoom(this.getFirstRoom()); @@ -75,8 +75,8 @@ class Rooms extends Component { this.setState({ room: { users, - messages - } + messages, + }, }); }; @@ -84,7 +84,7 @@ class Rooms extends Component { this.setState({ active: roomName, room: initialState.room, - loading: true + loading: true, }, async () => { const { active } = this.state; @@ -94,7 +94,9 @@ class Rooms extends Component { this.setState({ loading: false }, () => { try { this.listRef.current.lastChild.scrollIntoView(); - } catch {} + } catch { + // no-op + } }); }); }; @@ -111,7 +113,9 @@ class Rooms extends Component { this.selectRoom(this.getFirstRoom()); }; - validInput = () => (this.state.active || '').length > 0 && ((this.messageRef && this.messageRef.current && this.messageRef.current.value) || '').length > 0; + validInput = () => + (this.state.active || '').length > 0 + && ((this.messageRef && this.messageRef.current && this.messageRef.current.value) || '').length > 0; focusInput = () => { this.messageRef.current.focus(); @@ -120,10 +124,10 @@ class Rooms extends Component { formatTimestamp = (timestamp) => { const date = new Date(timestamp); const dtfUS = new Intl.DateTimeFormat('en', { - month: 'numeric', - day: 'numeric', - hour: 'numeric', - minute: '2-digit' + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: '2-digit', }); return dtfUS.format(date); @@ -155,65 +159,66 @@ class Rooms extends Component { /> {!active ? - : - - this.focusInput()}> - - - {active} - : + + this.focusInput()}> + + + {active} + this.leaveRoom(active)} - /> - -
- {loading ? : <> - - - - - {room.messages.map((message, index) => - - {this.formatTimestamp(message.timestamp)} - {message.username}: - {message.message} - - )} - - - - - - } - ref={input => this.messageRef = input && input.inputRef} - action={{ - icon: , - className: 'room-message-button', onClick: this.sendMessage, - disabled: !this.validInput() - }} - onKeyUp={(e) => e.key === 'Enter' ? this.sendMessage() : ''} - /> - - - - - - } -
-
-
} + /> +
+
+ {loading ? : <> + + + + + {room.messages.map((message, index) => + + {this.formatTimestamp(message.timestamp)} + {message.username}: + {message.message} + + )} + + + + + + } + ref={input => this.messageRef = input && input.inputRef} + action={{ + icon: , + className: 'room-message-button', onClick: this.sendMessage, + disabled: !this.validInput(), + }} + onKeyUp={(e) => e.key === 'Enter' ? this.sendMessage() : ''} + /> + + + + + + } +
+
+
} ) }; -}; +} export default Rooms; \ No newline at end of file diff --git a/src/web/src/components/Search/Detail/SearchDetail.js b/src/web/src/components/Search/Detail/SearchDetail.js index 9c66d4e0..be64aabd 100644 --- a/src/web/src/components/Search/Detail/SearchDetail.js +++ b/src/web/src/components/Search/Detail/SearchDetail.js @@ -18,7 +18,7 @@ import SearchDetailHeader from './SearchDetailHeader'; const sortDropdownOptions = [ { key: 'uploadSpeed', text: 'Upload Speed (Fastest to Slowest)', value: 'uploadSpeed' }, - { key: 'queueLength', text: 'Queue Depth (Least to Most)', value: 'queueLength' } + { key: 'queueLength', text: 'Queue Depth (Least to Most)', value: 'queueLength' }, ]; const SearchDetail = ({ search, creating, stopping, removing, disabled, onCreate, onStop, onRemove }) => { @@ -68,7 +68,7 @@ const SearchDetail = ({ search, creating, stopping, removing, disabled, onCreate const sortedAndFilteredResults = useMemo(() => { const sortOptions = { uploadSpeed: { field: 'uploadSpeed', order: 'desc' }, - queueLength: { field: 'queueLength', order: 'asc' } + queueLength: { field: 'queueLength', order: 'asc' }, } const { field, order } = sortOptions[resultSort]; @@ -141,8 +141,11 @@ const SearchDetail = ({ search, creating, stopping, removing, disabled, onCreate - {state === 'InProgress' ? `Found ${fileCount} files ${lockedFileCount > 0 ? `(plus ${lockedFileCount} locked) ` : ''}from ${responseCount} users` - : 'Loading results...'} + {state === 'InProgress' + ? `Found ${fileCount} files ${lockedFileCount > 0 + ? `(plus ${lockedFileCount} locked) ` + : ''}from ${responseCount} users` + : 'Loading results...'} } loading={loading && } @@ -184,7 +187,10 @@ const SearchDetail = ({ search, creating, stopping, removing, disabled, onCreate setResultFilters(data.value)} @@ -204,10 +210,14 @@ const SearchDetail = ({ search, creating, stopping, removing, disabled, onCreate {loaded && (remainingCount > 0 ? : filteredCount > 0 ? - : '')} + : '')} ) diff --git a/src/web/src/components/Search/Detail/SearchDetailHeader.js b/src/web/src/components/Search/Detail/SearchDetailHeader.js index 8eaf111c..9e04ba6d 100644 --- a/src/web/src/components/Search/Detail/SearchDetailHeader.js +++ b/src/web/src/components/Search/Detail/SearchDetailHeader.js @@ -9,7 +9,18 @@ import { } from 'semantic-ui-react'; import SearchStatusIcon from '../SearchStatusIcon'; -const SearchDetailHeader = ({ search, loading, loaded, creating, removing, stopping, disabled, onCreate, onStop, onRemove }) => { +const SearchDetailHeader = ({ + search, + loading, + loaded, + creating, + removing, + stopping, + disabled, + onCreate, + onStop, + onRemove, +}) => { const isSmallScreen = useMediaQuery({ query: '(max-width: 899px)' }); const isTinyScreen = useMediaQuery({ query: '(max-width: 684px)'}); diff --git a/src/web/src/components/Search/List/SearchList.js b/src/web/src/components/Search/List/SearchList.js index c65c949d..b6e001a6 100644 --- a/src/web/src/components/Search/List/SearchList.js +++ b/src/web/src/components/Search/List/SearchList.js @@ -11,10 +11,16 @@ import { Loader, Segment, Header, - List + List, } from 'semantic-ui-react'; -const SearchList = ({ connecting = false, error = undefined, searches = {}, onRemove = () => {}, onStop = () => {} }) => { +const SearchList = ({ + connecting = false, + error = undefined, + searches = {}, + onRemove = () => { }, + onStop = () => { }, +}) => { const searchCount = useMemo(() => { return Object.values(searches).length }, [searches]) @@ -40,29 +46,29 @@ const SearchList = ({ connecting = false, error = undefined, searches = {}, onRe No searches to display } > - - - - - Search - Files - Locked - Responses - Ended - - - - - {Object.values(searches) - .sort((a, b) => (new Date(b.startedAt) - new Date(a.startedAt))) - .map((search, index) => )} - -
+ + + + + Search + Files + Locked + Responses + Ended + + + + + {Object.values(searches) + .sort((a, b) => (new Date(b.startedAt) - new Date(a.startedAt))) + .map((search, index) => )} + +
diff --git a/src/web/src/components/Search/List/SearchListRow.js b/src/web/src/components/Search/List/SearchListRow.js index c2552892..fd762069 100644 --- a/src/web/src/components/Search/List/SearchListRow.js +++ b/src/web/src/components/Search/List/SearchListRow.js @@ -3,7 +3,7 @@ import React, { useState } from 'react'; import { Link, useRouteMatch, -} from "react-router-dom"; +} from 'react-router-dom'; import { Table, diff --git a/src/web/src/components/Search/Response.js b/src/web/src/components/Search/Response.js index 4e389288..05d5544c 100644 --- a/src/web/src/components/Search/Response.js +++ b/src/web/src/components/Search/Response.js @@ -6,134 +6,136 @@ import { formatBytes, getDirectoryName } from '../../lib/util'; import FileList from '../Shared/FileList' import { - Button, - Card, - Icon, - Label + Button, + Card, + Icon, + Label, } from 'semantic-ui-react'; const buildTree = (response) => { - let { files = [], lockedFiles = [] } = response; - files = files.concat(lockedFiles.map(file => ({ ...file, locked: true }))); - - return files.reduce((dict, file) => { - let dir = getDirectoryName(file.filename); - let selectable = { selected: false, ...file }; - dict[dir] = dict[dir] === undefined ? [ selectable ] : dict[dir].concat(selectable); - return dict; - }, {}); + let { files = [], lockedFiles = [] } = response; + files = files.concat(lockedFiles.map(file => ({ ...file, locked: true }))); + + return files.reduce((dict, file) => { + let dir = getDirectoryName(file.filename); + let selectable = { selected: false, ...file }; + dict[dir] = dict[dir] === undefined ? [ selectable ] : dict[dir].concat(selectable); + return dict; + }, {}); } class Response extends Component { - state = { - tree: buildTree(this.props.response), - downloadRequest: undefined, - downloadError: '', - isFolded: this.props.isInitiallyFolded, + state = { + tree: buildTree(this.props.response), + downloadRequest: undefined, + downloadError: '', + isFolded: this.props.isInitiallyFolded, + } + + componentDidUpdate = (prevProps) => { + if (JSON.stringify(this.props.response) !== JSON.stringify(prevProps.response)) { + this.setState({ tree: buildTree(this.props.response) }); } - - componentDidUpdate = (prevProps) => { - if (JSON.stringify(this.props.response) !== JSON.stringify(prevProps.response)) { - this.setState({ tree: buildTree(this.props.response) }); - } - if (this.props.isInitiallyFolded !== prevProps.isInitiallyFolded) { - this.setState({ isFolded: this.props.isInitiallyFolded }); - } - } - - onFileSelectionChange = (file, state) => { - file.selected = state; - this.setState({ tree: this.state.tree, downloadRequest: undefined, downloadError: '' }) - } - - download = (username, files) => { - this.setState({ downloadRequest: 'inProgress' }, async () => { - try { - const requests = (files || []).map(({ filename, size }) => ({ filename, size })) - await transfers.download({ username, files: requests }) - - this.setState({ downloadRequest: 'complete' }) - } catch (err) { - this.setState({ downloadRequest: 'error', downloadError: err.response }) - } - }); - } - - toggleFolded = () => { - this.setState({ isFolded: !this.state.isFolded }); - } - - render = () => { - let response = this.props.response; - let free = response.freeUploadSlots > 0; - - let { tree, downloadRequest, downloadError, isFolded } = this.state; - - let selectedFiles = Object.keys(tree) - .reduce((list, dict) => list.concat(tree[dict]), []) - .filter(f => f.selected); - - let selectedSize = formatBytes(selectedFiles.reduce((total, f) => total + f.size, 0)); - - return ( - - - - - - {response.username} - this.props.onHide()} - /> - - - Upload Speed: {formatBytes(response.uploadSpeed)}/s, Free Upload Slot: {free ? 'YES' : 'NO'}, Queue Length: {response.queueLength} - - {((!isFolded && Object.keys(tree)) || []).map((dir, i) => - file.locked)} - files={tree[dir]} - disabled={downloadRequest === 'inProgress'} - onSelectionChange={this.onFileSelectionChange} - /> - )} - - {selectedFiles.length > 0 && - - diff --git a/src/web/src/components/System/System.js b/src/web/src/components/System/System.js index ca88c50d..a4c79e12 100644 --- a/src/web/src/components/System/System.js +++ b/src/web/src/components/System/System.js @@ -1,5 +1,5 @@ import React from 'react'; -import { useRouteMatch, useHistory, Redirect } from "react-router-dom"; +import { useRouteMatch, useHistory, Redirect } from 'react-router-dom'; import { Segment, Tab } from 'semantic-ui-react'; @@ -15,7 +15,10 @@ const System = ({ state = {}, options = {} }) => { const panes = [ { route: 'info', menuItem: 'Info', render: () => }, - { route: 'options', menuItem: 'Options', render: () => }, + { + route: 'options', menuItem: 'Options', render: () => + , + }, { route: 'logs', menuItem: 'Logs', render: () => }, ] diff --git a/src/web/src/components/Transfers/TransferGroup.js b/src/web/src/components/Transfers/TransferGroup.js index 35955120..69b766a2 100644 --- a/src/web/src/components/Transfers/TransferGroup.js +++ b/src/web/src/components/Transfers/TransferGroup.js @@ -2,162 +2,164 @@ import React, { Component } from 'react'; import * as transfers from '../../lib/transfers'; import { - Card, - Button, - Icon + Card, + Button, + Icon, } from 'semantic-ui-react'; import TransferList from './TransferList'; class TransferGroup extends Component { - state = { - selections: new Set(), - isFolded: false - } + state = { + selections: new Set(), + isFolded: false, + } - onSelectionChange = (directoryName, file, selected) => { - const selections = this.state.selections; - const obj = JSON.stringify({ directory: directoryName, filename: file.filename }); - selected ? selections.add(obj) : selections.delete(obj); + onSelectionChange = (directoryName, file, selected) => { + const {selections} = this.state; + const obj = JSON.stringify({ directory: directoryName, filename: file.filename }); + selected ? selections.add(obj) : selections.delete(obj); - this.setState({ selections }); - } + this.setState({ selections }); + } - isSelected = (directoryName, file) => - this.state.selections.has(JSON.stringify({ directory: directoryName, filename: file.filename })); + isSelected = (directoryName, file) => + this.state.selections.has(JSON.stringify({ directory: directoryName, filename: file.filename })); - getSelectedFiles = () => { - const { user } = this.props; + getSelectedFiles = () => { + const { user } = this.props; - return Array.from(this.state.selections) - .map(s => JSON.parse(s)) - .map(s => user.directories - .find(d => d.directory === s.directory) - .files.find(f => f.filename === s.filename) - ).filter(s => s !== undefined); - } - - removeFileSelection = (file) => { - const selections = this.state.selections; - - const match = Array.from(selections) - .map(s => JSON.parse(s)) - .find(s => s.filename === file.filename); - - if (match) { - selections.delete(JSON.stringify(match)); - this.setState({ selections }); - } - } - - isStateRetryable = (state) => this.props.direction === 'download' && state.includes('Completed') && state !== 'Completed, Succeeded'; - isStateCancellable = (state) => ['InProgress', 'Requested', 'Queued', 'Queued, Remotely', 'Queued, Locally', 'Initializing'].find(s => s === state); - isStateRemovable = (state) => state.includes('Completed'); - - retryAll = async (selected) => { - await Promise.all(selected.map(file => this.retry(file))); - } - - cancelAll = async (direction, username, selected) => { - await Promise.all(selected.map(file => transfers.cancel({ direction, username, id: file.id}))); - } - - removeAll = async (direction, username, selected) => { - await Promise.all(selected.map(file => - transfers.cancel({ direction, username, id: file.id, remove: true }) - .then(() => this.removeFileSelection(file)))); + return Array.from(this.state.selections) + .map(s => JSON.parse(s)) + .map(s => user.directories + .find(d => d.directory === s.directory) + .files.find(f => f.filename === s.filename) + ).filter(s => s !== undefined); + } + + removeFileSelection = (file) => { + const {selections} = this.state; + + const match = Array.from(selections) + .map(s => JSON.parse(s)) + .find(s => s.filename === file.filename); + + if (match) { + selections.delete(JSON.stringify(match)); + this.setState({ selections }); } - - retry = async (file) => { - const { username, filename, size } = file; + } + + isStateRetryable = (state) => + this.props.direction === 'download' && state.includes('Completed') && state !== 'Completed, Succeeded'; + isStateCancellable = (state) => + ['InProgress', 'Requested', 'Queued', 'Queued, Remotely', 'Queued, Locally', 'Initializing'].find(s => s === state); + isStateRemovable = (state) => state.includes('Completed'); + + retryAll = async (selected) => { + await Promise.all(selected.map(file => this.retry(file))); + } + + cancelAll = async (direction, username, selected) => { + await Promise.all(selected.map(file => transfers.cancel({ direction, username, id: file.id}))); + } + + removeAll = async (direction, username, selected) => { + await Promise.all(selected.map(file => + transfers.cancel({ direction, username, id: file.id, remove: true }) + .then(() => this.removeFileSelection(file)))); + } + + retry = async (file) => { + const { username, filename, size } = file; - try { - await transfers.download({username, files: [{filename, size }] }); - } catch (error) { - console.log(error); - } + try { + await transfers.download({username, files: [{filename, size }] }); + } catch (error) { + console.log(error); } + } - fetchPlaceInQueue = async (file) => { - const { username, id } = file; + fetchPlaceInQueue = async (file) => { + const { username, id } = file; - try { - await transfers.getPlaceInQueue({ username, id }); - } catch (error) { - console.log(error); - } + try { + await transfers.getPlaceInQueue({ username, id }); + } catch (error) { + console.log(error); } + } - toggleFolded = () => { - this.setState({'isFolded': !this.state.isFolded}); - } + toggleFolded = () => { + this.setState({'isFolded': !this.state.isFolded}); + } - render = () => { - const { user, direction } = this.props; - const isFolded = this.state.isFolded; + render = () => { + const { user, direction } = this.props; + const {isFolded} = this.state; - const selected = this.getSelectedFiles(); - const all = selected.length > 1 ? ' Selected' : ''; + const selected = this.getSelectedFiles(); + const all = selected.length > 1 ? ' Selected' : ''; - const allRetryable = selected.filter(f => this.isStateRetryable(f.state)).length === selected.length; - const anyCancellable = selected.filter(f => this.isStateCancellable(f.state)).length > 0; - const allRemovable = selected.filter(f => this.isStateRemovable(f.state)).length === selected.length; - - return ( - - - - this.toggleFolded()} - /> - {user.username} - - {user.directories && !isFolded && user.directories - .map((dir, index) => - ({ ...f, selected: this.isSelected(dir.directory, f) }))} - onSelectionChange={this.onSelectionChange} - direction={this.props.direction} - onPlaceInQueueRequested={this.fetchPlaceInQueue} - onRetryRequested={this.retry} - /> - )} - - {selected && selected.length > 0 && + const allRetryable = selected.filter(f => this.isStateRetryable(f.state)).length === selected.length; + const anyCancellable = selected.filter(f => this.isStateCancellable(f.state)).length > 0; + const allRemovable = selected.filter(f => this.isStateRemovable(f.state)).length === selected.length; + + return ( + + + + this.toggleFolded()} + /> + {user.username} + + {user.directories && !isFolded && user.directories + .map((dir, index) => + ({ ...f, selected: this.isSelected(dir.directory, f) }))} + onSelectionChange={this.onSelectionChange} + direction={this.props.direction} + onPlaceInQueueRequested={this.fetchPlaceInQueue} + onRetryRequested={this.retry} + /> + )} + + {selected && selected.length > 0 && - { - {allRetryable && + { + {allRetryable &&