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

hacktiv8 news #10

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
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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,573 changes: 1,572 additions & 1 deletion README.md

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "hacktiv8-news",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "15.4.2",
"react-dom": "15.4.2",
"react-router-dom": "^4.0.0-beta.6"
},
"devDependencies": {
"react-scripts": "0.9.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.
33 changes: 33 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!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">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/css/materialize.min.css">

<!--
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>
24 changes: 24 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.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;*/
}

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

const App = () => (
<Router>
<div>
<div className='App-header'>
<img src={logo} className='App-logo' alt='logo' />
<h2>Welcome to React</h2>
</div>
<br/>
<nav>
<div className='nav-wrapper grey darken-4'>
<ul id='nav-mobile' className='right hide-on-med-and-down'>
<li>
<Link to='/'> Home
</Link>
</li>
<li>
<Link to='/people'> People
</Link>
</li>
</ul>
</div>
</nav>
<Route exact path='/' component={Home} />
<Route path='/people' component={People} />
</div>
</Router>
)

const data_number1 = [1, 2, 3]
const data_number2 = [{
title: 'React',
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, Andrew Clark',
num_comments: 2,
points: 5,
objectID: 1
}]

class Home extends Component {

constructor () {
super()
this.state = {
data_number1: data_number1,
data_number2: data_number2,
data_API: [],
currentSearch: '',
currentApiSearch: ''
}
this.handleChange = this.handleChange.bind(this)
this.handleApiChange = this.handleApiChange.bind(this)
}
handleChange (event) {
this.setState({
currentSearch: event.target.value
})
}

handleApiChange (event) {
this.setState({
currentApiSearch: event.target.value
})

this.fetchNews(this.state.currentApiSearch)
}

componentDidMount () {
this.fetchNews('')
}

fetchNews (keyword) {
let url = `http://hn.algolia.com/api/v1/search?query=${keyword}`
const that = this
fetch(url)
.then(function (response) {
return response.json()
})
.then(function (data) {
console.log(data)
let temp = []
data.hits.map((hint) => {
return temp.push({
title: hint.title,
author: hint.author,
url: hint.url
})
})
that.setState({
data_API: temp
})
})
}
render () {
return (
<div className='App'>
<fieldset>
<legend>
Release #2:
</legend>
<Release2 datanumber2={this.state.data_number2} currentSearch={this.state.currentSearch} />
<SearchForm handleChange={this.handleChange} />
</fieldset>
<br/>
<fieldset>
<legend>
Release #5:
</legend>
<Release5 dataApi={this.state.data_API} currentApiSearch={this.state.currentApiSearch} />
<SearchApi handleApiChange={this.handleApiChange} />
</fieldset>
</div>
)
}
}

class People extends Component {
constructor () {
super()
this.state = {
people: []
}
}
componentWillMount () {
this.fetchNews()
}

fetchNews () {
let url = `http://swapi.co/api/people/`
const that = this
fetch(url)
.then(function (response) {
return response.json()
})
.then(function (data) {
let temp = []
data.results.map((people) => {
return temp.push({
name: people.name,
height: people.height,
gender: people.gender
})
})
that.setState({
people: temp
})
})
}

render () {
return (
<div className='People'>
<fieldset>
<legend>
#Starwars
</legend>
<Starwars dataApi={this.state.people} />
</fieldset>
</div>
)
}

}

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);
});
18 changes: 18 additions & 0 deletions src/Release1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'

export const Release1 = (props) => {

return (
<div className='release1'>
<ul>
{props.datanumber1.map((item, index) => {
return (
<li key={index}>
{item}
</li>
)
})}
</ul>
</div>
)
}
40 changes: 40 additions & 0 deletions src/Release2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react'

const doSearch = (props) => {
return props.datanumber2.filter((data) => {
return data.title === props.currentSearch
}).map((item) => {

return (
<li key={item.objectID}>
<a href={item.url} target='_blank'>
{item.title}
</a>
<small>{item.author}</small>
</li>
)
})
}
const showlist = (props) => {
return props.datanumber2.map((item) => {

return (
<li key={item.objectID}>
<a href={item.url} target='_blank'>
{item.title}
</a>
</li>
)
})
}

export const Release2 = (props) => {

return (
<div className='release2'>
<ul>
{props.currentSearch ? doSearch(props) : showlist(props)}
</ul>
</div>
)
}
31 changes: 31 additions & 0 deletions src/Release5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react'

const doSearchAPI = (props) => {
return props.dataApi.map((item, index) => {

return (
<li key={index}>
<a href={item.url} target='_blank'>
{item.title}
</a>
</li>
)
})
}
const showlistAPI = () => {
return (
<li>
</li>
)
}

export const Release5 = (props) => {

return (
<div className='release5'>
<ul>
{props.currentApiSearch ? doSearchAPI(props) : showlistAPI()}
</ul>
</div>
)
}
9 changes: 9 additions & 0 deletions src/SearchApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'

export const SearchApi = (props) => {
return (
<form>
<input type='text' onChange={props.handleApiChange} placeholder="Search via 'algolia API' " />
</form>
)
}
Loading