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

Yoni Setiawan #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
#.nvm
.npm
.npmrc
pids
logs
results
npm-debug.log
node_modules
bower_components
yarn.lock
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env
npm-debug.log*
yarn-debug.log*
yarn-error.log*
1,575 changes: 1,574 additions & 1 deletion README.md

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "reduxify-hacktiv8-news",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "15.4.2",
"react-dom": "15.4.2",
"react-redux": "^5.0.3",
"react-router-dom": "^4.0.0-beta.6",
"redux": "^3.6.0"
},
"devDependencies": {
"react-scripts": "0.9.3",
"redux-devtools": "^3.3.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Binary file added public/favicon.ico
Binary file not shown.
31 changes: 31 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tag above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start`.
To create a production bundle, use `npm run build`.
-->
</body>
</html>
45 changes: 45 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.App {
text-align: center;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
}

.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
}

.App-intro {
font-size: large;
}

.App-list {
margin-left: 20px;
text-align: left;
}

ul {
list-style: none;
margin-left: -35px;
display: inline-block;
}

.menu-list {
display: inline-block;
margin: 15px;
}

.style-text {
font-family: 'crimson text';
font-size: 26px;
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
16 changes: 16 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import { BrowserRouter as Router, Route } from 'react-router-dom'

import News from './components/News/Main.js'
import Author from './components/People/Main.js'

const App = () => (
<Router>
<div>
<Route exact path='/' component={News} />
<Route exact path='/author' component={Author} />
</div>
</Router>
)

export default App
8 changes: 8 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});
9 changes: 9 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const searchNews = (text, news) => {
return {
type: 'SEARCH_NEWS',
payload: {
text: text,
news: news
}
}
}
17 changes: 17 additions & 0 deletions src/components/Header/Header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import logo from '../../logo.svg'
import '../../App.css'

import { Menu } from './Menu'

export const Header = (props) => {
return (
<div>
<div className='App-header'>
<img src={logo} className='App-logo' alt='logo' />
<h2>Welcome to React</h2>
</div>
<Menu />
</div>
)
}
17 changes: 17 additions & 0 deletions src/components/Header/Menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import { Link } from 'react-router-dom'

export const Menu = () => {
return (
<ul>
<li className='menu-list'>
<Link to='/'> News
</Link>
</li>
<li className='menu-list'>
<Link to='/author'> Author
</Link>
</li>
</ul>
)
}
38 changes: 38 additions & 0 deletions src/components/News/Main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { Component } from 'react'
import '../../App.css'
import { connect } from 'react-redux'

import Search from './Search.js'
import { Header } from '../Header/Header.js'

class Main extends Component {
render () {
return (
<div className='App'>
<Header />
<h1>Hacktiv8 News</h1>
<Search />
<ul className='center'>
{this.props.news
.map((item, index) => {
return (
<li key={index}>
<a href={item.url} className='style-text' target='_blank'>
{item.title}
</a>
</li>
)
})}
</ul>
</div>
)
}
}

const mapStateToProps = (state) => {
return {
news: state.searchKeyword
}
}

export default connect(mapStateToProps)(Main)
27 changes: 27 additions & 0 deletions src/components/News/Search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { searchNews } from '../../actions'

const Search = (props) => {
return (
<div className='search-news'>
<form>
<input type='text' onChange={e => props.searchNews(e.target.value, props.news, props.keyword)} />
</form>
</div>
)
}

const mapStateToProps = (state) => {
return {
news: state.news,
keyword: state.searchKeyword
}
}

const mapDispatchToProps = (dispatch) => {
return bindActionCreators({searchNews}, dispatch)
}

export default connect(mapStateToProps, mapDispatchToProps)(Search)
36 changes: 36 additions & 0 deletions src/components/People/Main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { Component } from 'react'
import '../../App.css'
import { connect } from 'react-redux'

import { Header } from '../Header/Header'

class People extends Component {
render () {
return (
<div className='App'>
<Header />
<h1>Hacktiv8 Author</h1>
<ul className='center'>
{this.props.people
.map((item, index) => {
return (
<p key={index}>
<a>
{item.author}
</a>
</p>
)
})}
</ul>
</div>
)
}
}

const mapStateToProps = (state) => {
return {
people: state.news
}
}

export default connect(mapStateToProps)(People)
5 changes: 5 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
16 changes: 16 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import './index.css'
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import rootReducers from './reducers'

const store = createStore(rootReducers)

ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
)
7 changes: 7 additions & 0 deletions src/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { combineReducers } from 'redux'
import { newsListsReducer, searchKeywordReducer } from './reducerNews'

const rootReducers = combineReducers({
news: newsListsReducer,
searchKeyword: searchKeywordReducer
})

export default rootReducers
32 changes: 32 additions & 0 deletions src/reducers/reducerNews.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const data = [{
title: 'React JS',
url: 'https://facebook.github.io/react',
author: 'Jordan Walke',
num_comments: 3,
points: 4,
objectID: 0
}, {
title: 'Redux',
url: 'https://github.com/reactjs/redux',
author: 'Dan Abramov',
num_comments: 2,
points: 5,
objectID: 1
}]

export const newsListsReducer = () => {
return data
}

export const searchKeywordReducer = (state = data, action) => {
switch (action.type) {
case 'SEARCH_NEWS':
var searchNewsLists = action.payload.news.filter((data) => {
return data.title.toLowerCase().match(`${action.payload.text}`.toLowerCase())
})
return searchNewsLists
break
default:
return state
}
}