Skip to content
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

Add Newslist component #17

Merged
merged 7 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11,293 changes: 11,293 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"react-redux": "^5.0.7",
"redux": "^4.0.0"
}
}
}
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import NewsListTable from './components/NewsListTable';
import logo from './logo.svg';
import './App.css';

Expand All @@ -13,6 +14,7 @@ class App extends Component {
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
<NewsListTable/>
</div>
);
}
Expand Down
14 changes: 14 additions & 0 deletions src/components/NewsListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, { Component } from 'react';

function NewsListItem(props) {
return (
<div className="news-list-item">
<a className="title" href={props.item.url} target="__blank">{props.item.title}</a>
<div className="info">
{props.item.points} points by {props.item.user} | {props.item.timeAgo} ago | {props.item.numberOfComments} comments
</div>
</div>
);
}

export default NewsListItem;
23 changes: 23 additions & 0 deletions src/components/NewsListTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import NewsListItem from './NewsListItem';
import SearchParameter from './SearchParameter';

const mapStateToProps = state => {
return {news: state.news }
};

const ConnectedNewsListTable = ({ news }) => (
<div>
<SearchParameter />
<h1>News List</h1>
{news.length ? "" : "no news found"}
{news.map((item, index) => (
<NewsListItem item={item} />
))}
</div>
);

const NewsListTable = connect(mapStateToProps)(ConnectedNewsListTable);

export default NewsListTable;
13 changes: 13 additions & 0 deletions src/components/SearchParameter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";
import { connect } from "react-redux";

const mapStateToProps = state => {
return { searchParameters: state.searchParameters };
};
const ConnectedList = ({ searchParameters }) => (
<div>
{searchParameters ? 'Search results for: \"' + searchParameters + '\"' : ''}
</div>
);
const SearchParameter = connect(mapStateToProps)(ConnectedList);
export default SearchParameter;
11 changes: 10 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import store from './store/index'
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>
, document.getElementById('root')
);
registerServiceWorker();


25 changes: 25 additions & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const initialState = {
searchParameters: "bananaMonkeyCarberator",
news: [
{
url: 'www.example.com',
user: 'tdurden',
title: 'Tesla Asks Suppliers for Cash Back to Help Turn a Profit',
timeAgo: '1 day',
points: '42',
numberOfComments: '22'
},
{
url: 'www.example.com',
user: 'jhabdas',
title: 'BPG Image format ',
timeAgo: '9 hours',
points: '185',
numberOfComments: '60'
}
]
};

const rootReducer = (state = initialState, action) => state;

export default rootReducer;
7 changes: 7 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createStore } from "redux";
import rootReducer from "../reducers/index";

const store = createStore(rootReducer);
window.store = store;

export default store;