-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/store scraped article #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| eslint: | ||
| enabled: true | ||
| config_file: .eslintrc | ||
| config_file: .eslintrc.json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,23 @@ | ||
| import React, { Component } from 'react'; | ||
| import AlertContainer from 'react-alert'; | ||
| import { hashHistory } from 'react-router'; | ||
| import { Button, Container, Header, Segment, Divider, Dimmer, Loader } from 'semantic-ui-react'; | ||
| import { Button, Container, Dimmer, Divider, Header, Loader, Segment } from 'semantic-ui-react'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'Button' is defined but never used no-unused-vars |
||
|
|
||
| import ArticleStore from '../stores/ArticleStore.jsx'; | ||
| import getArticle from '../actions/ArticleActions.jsx'; | ||
| import { firebaseRef } from '../firebase/index.jsx'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unable to resolve path to module '../firebase/index.jsx' import/no-unresolved |
||
| import formatDate from '../helpers/DateFormatter.jsx'; | ||
| import AuthStore from '../stores/AuthStore.jsx'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected use of file extension "jsx" for "../stores/AuthStore.jsx" import/extensions |
||
| import ShareIcon from './ShareIcon.jsx'; | ||
|
|
||
| const alertOptions = { | ||
| offset: 14, | ||
| position: 'bottom left', | ||
| theme: 'dark', | ||
| time: 4000, | ||
| transition: 'scale' | ||
| }; | ||
|
|
||
| /** | ||
| * Article Component | ||
| * @class | ||
|
|
@@ -21,9 +32,12 @@ export default class Article extends Component { | |
|
|
||
| this.getArticle = this.getArticle.bind(this); | ||
| this.onClick = this.onClick.bind(this); | ||
| this.storeArticle = this.storeArticle.bind(this); | ||
|
|
||
| this.state = { | ||
| article: null, | ||
| userId: '', | ||
| disabled: false, | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -34,8 +48,11 @@ export default class Article extends Component { | |
| */ | ||
| componentDidMount() { | ||
| const url = localStorage.getItem('url'); | ||
| const user = Object.keys(AuthStore.user).length !== 0 ? | ||
| AuthStore.user : JSON.parse(localStorage.getItem('user')); | ||
| getArticle(url); | ||
|
|
||
| this.setUser(user); | ||
| ArticleStore.on('article_change', this.getArticle); | ||
| } | ||
|
|
||
|
|
@@ -60,6 +77,18 @@ export default class Article extends Component { | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * setUser sets the state for userId. | ||
| * @method | ||
| * @param {Object} user | ||
| * @returns {void} | ||
| */ | ||
| setUser(user) { | ||
| this.setState({ | ||
| userId: user.uid, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * handleClick method for returning to the headlines. | ||
| * @method | ||
|
|
@@ -69,21 +98,66 @@ export default class Article extends Component { | |
| hashHistory.push('/headlines'); | ||
| } | ||
|
|
||
| /** | ||
| * showAlert method for returning to the headlines. | ||
| * @method | ||
| * @returns {void} | ||
| */ | ||
| showAlert() { | ||
| this.msg.show('Article saved.'); | ||
| } | ||
|
|
||
| /** | ||
| * storeArticle saves scraped article to the DB. | ||
| * @method | ||
| * @returns {void} | ||
| */ | ||
| storeArticle() { | ||
| const { article, userId } = this.state; | ||
| const articleToSave = { | ||
| title: article.title, | ||
| content: article.content, | ||
| date_published: formatDate(article.date_published), | ||
| lead_image_url: article.lead_image_url, | ||
| dek: article.dek, | ||
| url: article.url, | ||
| domain: article.domain, | ||
| excerpt: article.excerpt, | ||
| word_count: article.word_count, | ||
| direction: article.direction, | ||
| total_pages: article.total_pages, | ||
| rendered_pages: article.rendered_pages, | ||
| }; | ||
|
|
||
| firebaseRef.child(`users/${userId}/articles`).push(articleToSave); | ||
| this.setState({ | ||
| disabled: true, | ||
| }); | ||
| this.showAlert(); | ||
| } | ||
|
|
||
| /** | ||
| * render | ||
| * @method | ||
| * @returns {span} span | ||
| */ | ||
| render() { | ||
| const { article } = this.state; | ||
| const { article, disabled } = this.state; | ||
|
|
||
| return ( | ||
| article ? ( | ||
| <span> | ||
| <Container text textAlign="justified"> | ||
| <AlertContainer ref={a => this.msg = a} {...alertOptions} /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arrow function should not return assignment no-return-assign |
||
| <Container text textAlign='justified'> | ||
| <Segment raised> | ||
| <Button circular icon="arrow left" onClick={this.onClick} /> | ||
| <Header as="h2">{article.title}</Header> | ||
| <Button circular icon='arrow left' onClick={this.onClick} /> | ||
| <Button circular | ||
| disabled={disabled} | ||
| positive | ||
| icon='save' | ||
| onClick={this.storeArticle} | ||
| /> | ||
| <Header as='h2'>{article.title}</Header> | ||
| <small>{formatDate(article.date_published)}</small> | ||
| <ShareIcon url={article.url} title={article.title} /> | ||
| <Divider hidden /> | ||
|
|
@@ -93,7 +167,7 @@ export default class Article extends Component { | |
| </span> | ||
| ) : ( | ||
| <Dimmer active inverted> | ||
| <Loader size="large" inline="centered">Loading</Loader> | ||
| <Loader size='large' inline='centered'>Loading</Loader> | ||
| </Dimmer> | ||
| ) | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import React, { Component } from 'react'; | ||
| import { Grid, Button, Icon, Segment, Header, Divider } from 'semantic-ui-react'; | ||
|
|
||
| import { startLogin } from '../actions/LoginActions.jsx'; | ||
| import { startLogin } from '../actions/AuthActions.jsx'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected use of file extension "jsx" for "../actions/AuthActions.jsx" import/extensions |
||
| import { githubProvider, googleProvider } from '../firebase/index.jsx'; | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import React, { Component } from 'react'; | ||
| import { Sidebar, Segment, Button, Menu, Grid, Icon, Dropdown, Dimmer, Loader } from 'semantic-ui-react'; | ||
|
|
||
| import { startLogout } from '../actions/LoginActions.jsx'; | ||
| import { startLogout } from '../actions/AuthActions.jsx'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unable to resolve path to module '../actions/AuthActions.jsx' import/no-unresolved |
||
| import capitalise from '../helpers/Capitalise.jsx'; | ||
| import createOptions from '../helpers/OptionsCreator.jsx'; | ||
| import Headline from './Headline.jsx'; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import AuthStore from '../../stores/AuthStore.jsx'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unable to resolve path to module '../../stores/AuthStore.jsx' import/no-unresolved |
||
| import dispatcher from '../../dispatcher.jsx'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unable to resolve path to module '../../dispatcher.jsx' import/no-unresolved |
||
|
|
||
| describe('Login Store', () => { | ||
| describe('successful login', () => { | ||
| beforeEach(() => { | ||
| dispatcher.dispatch({ | ||
| type: 'LOGIN_SUCCESS', | ||
| user: { | ||
| uid: '1520', | ||
| displayName: 'Kennedy', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should set user and userId on successful login', () => { | ||
| expect(AuthStore.userId).to.equal('1520'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'expect' is not defined no-undef |
||
| expect(typeof AuthStore.user).to.equal('object'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'expect' is not defined no-undef |
||
| }); | ||
| }); | ||
|
|
||
| describe('successful logout', () => { | ||
| beforeEach(() => { | ||
| dispatcher.dispatch({ | ||
| type: 'LOGOUT_SUCCESS', | ||
| }); | ||
| }); | ||
|
|
||
| it('should clear userId and localStorage on logout', () => { | ||
| expect(AuthStore.userId).to.equal(''); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'expect' is not defined no-undef |
||
| expect(localStorage.getItem('user')).to.equal(null); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'expect' is not defined no-undef |
||
| }); | ||
| }); | ||
| }); | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'AlertContainer' is defined but never used no-unused-vars
Missing file extension for "react-alert" import/extensions
Unable to resolve path to module 'react-alert' import/no-unresolved