From 69115c731854c886579a1c7303e241062e54c19b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Delattre?= Date: Thu, 27 Feb 2020 13:33:45 +0100 Subject: [PATCH] Fix most of the linter's errors/warnings --- .../js/components/list/explorerOptions.js | 185 +++++++++--------- frontend/js/components/users/edit.js | 4 +- frontend/js/components/users/signup.js | 10 +- frontend/js/components/users/tokens.js | 52 +++-- frontend/js/reducers/show.js | 4 +- frontend/webpack.config.js | 8 +- 6 files changed, 136 insertions(+), 127 deletions(-) diff --git a/frontend/js/components/list/explorerOptions.js b/frontend/js/components/list/explorerOptions.js index 83193c1..bbb3afe 100644 --- a/frontend/js/components/list/explorerOptions.js +++ b/frontend/js/components/list/explorerOptions.js @@ -1,115 +1,108 @@ import React from "react"; +import PropTypes from "prop-types"; import { withRouter } from "react-router-dom"; import { Form, FormGroup, FormControl, FormLabel } from "react-bootstrap"; -class ExplorerOptions extends React.PureComponent { - constructor(props) { - super(props); - this.handleSourceChange = this.handleSourceChange.bind(this); - this.handleCategoryChange = this.handleCategoryChange.bind(this); +const ExplorerOptions = ({ display, params, options, type, history }) => { + // Should this componennt be displayed + if (!display) { + return null; } - handleSourceChange(event) { + + if ( + !params || + !params.source || + !params.category || + params.source === "" || + params.category === "" + ) { + return null; + } + + const handleSourceChange = event => { let source = event.target.value; - let category = this.props.options.get(event.target.value).first(); - this.props.history.push( - `/${this.props.type}/explore/${source}/${category}` - ); - } - handleCategoryChange(event) { - let source = this.props.params.source; + let category = options.get(event.target.value).first(); + history.push(`/${type}/explore/${source}/${category}`); + }; + + const handleCategoryChange = event => { + let source = params.source; let category = event.target.value; - this.props.history.push( - `/${this.props.type}/explore/${source}/${category}` - ); - } - propsValid(props) { - if ( - !props.params || - !props.params.source || - !props.params.category || - props.params.source === "" || - props.params.category === "" - ) { - return false; - } - return true; - } - prettyName(name) { + history.push(`/${type}/explore/${source}/${category}`); + }; + + const prettyName = name => { return name .replace("_", " ") .split(" ") .map(w => w[0].toUpperCase() + w.substr(1)) .join(" "); + }; + + // Options are not yet fetched + if (options.size === 0) { + return null; } - render() { - // Should this componennt be displayed - if (!this.props.display) { - return null; - } - // Options are not yet fetched - if (this.props.options.size === 0) { - return null; - } + let source = params.source; + let category = params.category; + let categories = options.get(params.source); - // Invalid props - if (!this.propsValid(this.props)) { - return; - } - - let source = this.props.params.source; - let category = this.props.params.category; - let categories = this.props.options.get(this.props.params.source); - - return ( -
-
-
-
-
- - Source - - {this.props.options.keySeq().map(function(source) { - return ( - - ); - }, this)} - - -
-
- - Category - - {categories.map(function(category) { - return ( - - ); - }, this)} - - -
+ return ( +
+
+ +
+
+ + Source + + {options.keySeq().map(function(source) { + return ( + + ); + })} + +
- -
+
+ + Category + + {categories.map(function(category) { + return ( + + ); + })} + + +
+
+
- ); - } -} +
+ ); +}; +ExplorerOptions.propTypes = { + params: PropTypes.object, + history: PropTypes.object, + type: PropTypes.string, + options: PropTypes.object, + display: PropTypes.bool +}; export default withRouter(ExplorerOptions); diff --git a/frontend/js/components/users/edit.js b/frontend/js/components/users/edit.js index e54e08a..e7331ba 100644 --- a/frontend/js/components/users/edit.js +++ b/frontend/js/components/users/edit.js @@ -48,8 +48,8 @@ const UserEditConnect = ({ ev.preventDefault(); updateUser({ password: password, - password_confirm: passwordConfirm, - polochon_id: id + password_confirm: passwordConfirm, // eslint-disable-line camelcase + polochon_id: id // eslint-disable-line camelcase }); }; diff --git a/frontend/js/components/users/signup.js b/frontend/js/components/users/signup.js index 748b580..aec82a9 100644 --- a/frontend/js/components/users/signup.js +++ b/frontend/js/components/users/signup.js @@ -13,20 +13,20 @@ const mapStateToProps = state => ({ const mapDispatchToProps = { userSignUp }; const UserSignUp = props => { - if (props.isLogged) { - return ; - } - const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [passwordConfirm, setPasswordConfirm] = useState(""); + if (props.isLogged) { + return ; + } + const handleSubmit = e => { e.preventDefault(); props.userSignUp({ username: username, password: password, - password_confirm: passwordConfirm + password_confirm: passwordConfirm // eslint-disable-line camelcase }); }; diff --git a/frontend/js/components/users/tokens.js b/frontend/js/components/users/tokens.js index f1a1257..82d8286 100644 --- a/frontend/js/components/users/tokens.js +++ b/frontend/js/components/users/tokens.js @@ -31,7 +31,7 @@ const UserTokens = props => { }; UserTokens.propTypes = { tokens: PropTypes.instanceOf(List), - isLoading: PropTypes.bool.isRequired, + isLoading: PropTypes.bool, getUserTokens: PropTypes.func.isRequired, deleteUserToken: PropTypes.func.isRequired }; @@ -89,14 +89,14 @@ Actions.propTypes = { deleteToken: PropTypes.func.isRequired }; -const Logo = props => { +const Logo = ({ ua, device, browser }) => { var className; - if (props.ua === "canape-cli") { + if (ua === "canape-cli") { className = "terminal"; - } else if (props.device.type == "mobile") { + } else if (device.type == "mobile") { className = "mobile"; } else { - switch (props.browser.name) { + switch (browser.name) { case "Chrome": case "chrome": className = "chrome"; @@ -117,42 +117,58 @@ const Logo = props => { return ; }; +Logo.propTypes = { + ua: PropTypes.string, + device: PropTypes.object, + browser: PropTypes.object +}; -const OS = props => { +const OS = ({ name, version }) => { var osName = "-"; - if (props.name !== undefined) { - osName = props.name; + if (name !== undefined) { + osName = name; - if (props.version !== undefined) { - osName += " " + props.version; + if (version !== undefined) { + osName += " " + version; } } return {osName}; }; +OS.propTypes = { + name: PropTypes.string, + version: PropTypes.string +}; -const Device = props => { +const Device = ({ model }) => { var deviceName = "-"; - if (props.model !== undefined) { - deviceName = props.model; + if (model !== undefined) { + deviceName = model; } return {deviceName}; }; +Device.propTypes = { + model: PropTypes.string +}; -const Browser = props => { +const Browser = ({ name, version }) => { var browserName = "-"; - if (props.name !== undefined) { - browserName = props.name; + if (name !== undefined) { + browserName = name; - if (props.version !== undefined) { - browserName += " - " + props.version; + if (version !== undefined) { + browserName += " - " + version; } } return {browserName}; }; +Browser.propTypes = { + name: PropTypes.string, + version: PropTypes.string +}; export default connect(mapStateToProps, mapDispatchToProps)(UserTokens); diff --git a/frontend/js/reducers/show.js b/frontend/js/reducers/show.js index 00149b9..321e644 100644 --- a/frontend/js/reducers/show.js +++ b/frontend/js/reducers/show.js @@ -15,8 +15,8 @@ const handlers = { return state.mergeDeep( fromJS({ show: { - tracked_season: action.payload.season, - tracked_episode: action.payload.episode + tracked_season: action.payload.season, // eslint-disable-line camelcase + tracked_episode: action.payload.episode // eslint-disable-line camelcase } }) ); diff --git a/frontend/webpack.config.js b/frontend/webpack.config.js index ffd0f54..bf4f462 100644 --- a/frontend/webpack.config.js +++ b/frontend/webpack.config.js @@ -82,13 +82,13 @@ const config = { "apple-mobile-web-app-title": "Canapé" }, name: "Canapé", - short_name: "Canapé", - background_color: "#4e5d6c", - theme_color: "#4e5d6c", + short_name: "Canapé", // eslint-disable-line camelcase + background_color: "#4e5d6c", // eslint-disable-line camelcase + theme_color: "#4e5d6c", // eslint-disable-line camelcase display: "standalone", orientation: "omit", scope: "/", - start_url: "/", + start_url: "/", // eslint-disable-line camelcase icons: [ { src: path.resolve(__dirname, "img/android-chrome-512x512.png"), -- 2.47.1