From 7f87e416965cae24e70c0ca6a024eec5815359d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chif=20Gerg=C5=91?= <chifgeri97@gmail.com> Date: Tue, 18 Dec 2018 21:17:14 +0100 Subject: [PATCH] Fix some eslint errors --> format code --- src/actions/auth.js | 14 +++-- src/actions/news.js | 38 +++++++------- src/actions/types.js | 2 +- src/components/forms/AddNewsForm.js | 79 +++++++++++++++-------------- src/components/pages/News.js | 60 ++++++++++------------ src/reducers/AddNewsReducer.js | 4 +- src/reducers/NewsReducer.js | 4 +- 7 files changed, 102 insertions(+), 99 deletions(-) diff --git a/src/actions/auth.js b/src/actions/auth.js index 6ad36fc..1b10cf8 100644 --- a/src/actions/auth.js +++ b/src/actions/auth.js @@ -28,7 +28,9 @@ export const getUserData = () => ( id, joinDate, nick, motivationAbout, motivationProfession, motivationExercise, signed, groups, }, }); - } catch (e) {} + } catch (e) { + console.log(e); + } } ); @@ -40,9 +42,9 @@ export const getNews = () => ( type: GET_NEWS, payload: response.data, }); - } catch(e) { + } catch (e) { + console.log(e); } - } ); @@ -59,7 +61,7 @@ export const groupChange = groups => ( export const submitRegistration = ({ nick, groups, signed, motivationAbout, motivationProfession, motivationExercise, id, }) => ( - async (dispatch) => { + async () => { try { const response = await axios.patch(`/api/v1/profiles/${id}/`, { nick, @@ -74,6 +76,8 @@ export const submitRegistration = ({ } else { alert('MentĂŠs nem sikerĂźlt!'); } - } catch(e) {} + } catch (e) { + console.log(e); + } } ); diff --git a/src/actions/news.js b/src/actions/news.js index 5d8c48b..9044567 100644 --- a/src/actions/news.js +++ b/src/actions/news.js @@ -1,5 +1,5 @@ -import { axios } from './auth' -import { GET_NEWS, WRITE_NEWS, ADD_NEWS, DELETE_NEWS, CLEAR_WRITE } from './types' +import { axios } from './auth'; +import { GET_NEWS, WRITE_NEWS, ADD_NEWS, DELETE_NEWS, CLEAR_WRITE } from './types'; export const getNews = () => ( async (dispatch) => { @@ -9,20 +9,20 @@ export const getNews = () => ( type: GET_NEWS, payload: response.data, }); - } catch(e) { + } catch (e) { + console.log(e); } - } ); -export const postNews = ({title, author, text}) =>( - async(dispatch) =>{ - try{ +export const postNews = ({ title, author, text }) => ( + async (dispatch) => { + try { const response = await axios.post('/api/v1/news/', { - "author": author, - "title": title, - "text": text, - }) + author, + title, + text, + }); if (response.data.id) { alert('Sikeres mentĂŠs!'); dispatch({ @@ -32,15 +32,15 @@ export const postNews = ({title, author, text}) =>( } else { alert('MentĂŠs nem sikerĂźlt!'); } - }catch(e){ - console.log(e); - } + } catch (e) { + console.log(e); } + } ); -export const deleteNews = (news) =>( - async(dispatch) =>{ - try{ +export const deleteNews = news => ( + async (dispatch) => { + try { const response = await axios.delete(`/api/v1/news/${news.id}/`); if (!response.data.id) { alert('Sikeres tĂśrlĂŠs!'); @@ -51,12 +51,12 @@ export const deleteNews = (news) =>( } else { alert('A tĂśrlĂŠs nem sikerĂźlt!'); } - }catch(e){ + } catch (e) { console.log(e); } }); -export const writeNews = ({target : {name, value}}) => ( +export const writeNews = ({ target: { name, value } }) => ( (dispatch) => { dispatch({ type: WRITE_NEWS, payload: value, target: name }); } diff --git a/src/actions/types.js b/src/actions/types.js index 54bb782..51fd06f 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -7,4 +7,4 @@ export const GROUP_CHANGE = 'group_change'; export const WRITE_NEWS = 'write_news'; export const CLEAR_WRITE = 'clear_write'; export const ADD_NEWS = 'add_news'; -export const DELETE_NEWS = 'delete_news' +export const DELETE_NEWS = 'delete_news'; diff --git a/src/components/forms/AddNewsForm.js b/src/components/forms/AddNewsForm.js index 1c28bef..70fe2f7 100644 --- a/src/components/forms/AddNewsForm.js +++ b/src/components/forms/AddNewsForm.js @@ -2,50 +2,55 @@ import React, { Component } from 'react'; import { Modal, Button, Form, Input, TextArea, Icon } from 'semantic-ui-react'; import { connect } from 'react-redux'; -import { postNews, writeNews, clearWrite } from '../../actions/news.js' +import { postNews, writeNews, clearWrite } from '../../actions/news'; class AddNewsForm extends Component { - - render(){ + render() { const { title, text } = this.props.newNews; const author = this.props.user.id; return ( - <Modal trigger={<Button >Add news</Button>}> - <Modal.Header>Ăj hĂr:</Modal.Header> - <Modal.Content> - <Form> - <Form.Field - control={Input} - label='Title' - name='title' - onChange={e => this.props.writeNews(e)} - value={title} - placeholder='Title' /> - <Form.Field - control={TextArea} - label='Text' - name='text' - onChange={e => this.props.writeNews(e)} - value={text} - placeholder='Tell us what you want...' /> - </Form> - </Modal.Content> - <Modal.Actions> - <Button inverted color='red' > - <Icon name='remove' /> Cancel - </Button> - <Button - inverted color='green' - onClick={() => {this.props.postNews({title, text, author}); - this.props.clearWrite()}}> - <Icon name='checkmark' /> Add - </Button> - </Modal.Actions> - </Modal> - ); + <Modal trigger={<Button >Add news</Button>}> + <Modal.Header>Ăj hĂr:</Modal.Header> + <Modal.Content> + <Form> + <Form.Field + control={Input} + label='Title' + name='title' + onChange={e => this.props.writeNews(e)} + value={title} + placeholder='Title' + /> + <Form.Field + control={TextArea} + label='Text' + name='text' + onChange={e => this.props.writeNews(e)} + value={text} + placeholder='Tell us what you want...' + /> + </Form> + </Modal.Content> + <Modal.Actions> + <Button inverted color='red' > + <Icon name='remove' /> Cancel + </Button> + <Button + inverted + color='green' + onClick={() => { + this.props.postNews({ title, text, author }); + this.props.clearWrite(); + }} + > + <Icon name='checkmark' /> Add + </Button> + </Modal.Actions> + </Modal> + ); } } const mapStateToProps = ({ newNews, user }) => ({ newNews, user }); -export default connect(mapStateToProps, { postNews, writeNews, clearWrite })(AddNewsForm); +export default connect(mapStateToProps, { postNews, writeNews, clearWrite })(AddNewsForm); diff --git a/src/components/pages/News.js b/src/components/pages/News.js index 6cea137..4a2a414 100644 --- a/src/components/pages/News.js +++ b/src/components/pages/News.js @@ -1,55 +1,49 @@ import React, { Component } from 'react'; -import { Container, Header, Segment, Divider, List, Modal, - Button, Image, Form, Input, TextArea, Checkbox, Icon } from 'semantic-ui-react'; +import { Container, Header, Segment, Divider, List, Button } from 'semantic-ui-react'; import { connect } from 'react-redux'; -import AddNewsForm from '../forms/AddNewsForm' +import AddNewsForm from '../forms/AddNewsForm'; -import { getNews, deleteNews } from '../../actions/news' +import { getNews, deleteNews } from '../../actions/news'; class News extends Component { - componentWillMount() { this.props.getNews(); } - render_news() { - const news = this.props.news; - - return news.map( (item, index) => ( - <div key={index} id={index}> + renderNews() { + return this.props.news.map((item, index) => ( + <div key={item.id} id={index}> { index > 0 ? <Divider /> : ''} <Header as='h3' style={{ fontSize: '2em' }}>{item.title}</Header> <p style={{ fontSize: '1.33em' }}>{item.text}</p> <Button color='red' size='mini' - onClick={() => this.props.deleteNews(item)} >Delete</Button> + onClick={() => this.props.deleteNews(item)} + > + Delete + </Button> </div> )); - } - render_sidebar() { - const news = this.props.news; - - return news.map( (item, index) => ( - <List.Item as='a' href={`#${index}`}> - <List.Icon name='align justify' verticalAlign={"middle"}/> - <List.Content> - <List.Header> - {item.title} - </List.Header> - </List.Content> - </List.Item> + renderSidebar() { + return this.props.news.map((item, index) => ( + <List.Item as='a' href={`#${index}`}> + <List.Icon name='align justify' verticalAlign='middle' /> + <List.Content> + <List.Header> + {item.title} + </List.Header> + </List.Content> + </List.Item> )); - } render() { - return ( <div> - {/* <Segment inverted textAlign='center' vertical> + {/* <Segment inverted textAlign='center' vertical> <Container> <Header as='h1' @@ -67,15 +61,15 @@ class News extends Component { </Segment> */} - <Segment floated={'left'} style={{ padding: '3em 3em' }} vertical> + <Segment floated='left' style={{ padding: '3em 3em' }} vertical> <AddNewsForm /> - <Container text textAlign = {'center'}> - {this.render_news()} + <Container text textAlign='center'> + {this.renderNews()} </Container> </Segment> - <Segment floated={'right'} style={{ padding: '1em 1em' }} vertical> - <List size={'big'} link divided> - {this.render_sidebar()} + <Segment floated='right' style={{ padding: '1em 1em' }} vertical> + <List size='big' link divided> + {this.renderSidebar()} </List> </Segment> </div> diff --git a/src/reducers/AddNewsReducer.js b/src/reducers/AddNewsReducer.js index 0010ea8..8b228db 100644 --- a/src/reducers/AddNewsReducer.js +++ b/src/reducers/AddNewsReducer.js @@ -1,11 +1,11 @@ import { WRITE_NEWS, CLEAR_WRITE } from '../actions/types'; -const INITIAL_STATE = { title: '', text: ''}; +const INITIAL_STATE = { title: '', text: '' }; export default (state = INITIAL_STATE, action) => { switch (action.type) { case WRITE_NEWS: - return {...state, [action.target]: action.payload} + return { ...state, [action.target]: action.payload }; case CLEAR_WRITE: return INITIAL_STATE; default: diff --git a/src/reducers/NewsReducer.js b/src/reducers/NewsReducer.js index db1d57c..e75e0ef 100644 --- a/src/reducers/NewsReducer.js +++ b/src/reducers/NewsReducer.js @@ -9,8 +9,8 @@ export default (state = INITIAL_STATE, action) => { case ADD_NEWS: return [action.payload, ...state]; case DELETE_NEWS: - let index = state.indexOf(action.payload); - let array = [...state]; + const index = state.indexOf(action.payload); + const array = [...state]; array.splice(index, 1); return [...array]; default: -- GitLab