Skip to content

Commit 9239b36

Browse files
authored
Merge pull request #4 from alivenotions/component-structure
Component structure
2 parents 2e9034c + f8656bb commit 9239b36

File tree

7 files changed

+108
-36
lines changed

7 files changed

+108
-36
lines changed

package-lock.json

Lines changed: 30 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"homepage": "https://alivenotions.github.io/pidpod/",
66
"scripts": {
77
"precommit": "lint-staged",
8-
"test:staged": "cross-env CI=true react-scripts test --findRelatedTests",
98
"start": "react-scripts start",
109
"build": "react-scripts build",
1110
"test": "cross-env CI=true react-scripts test",
@@ -15,15 +14,13 @@
1514
"src/**/*.{js,jsx,json,css}": [
1615
"prettier --single-quote --no-semi --trailing-comma es5 --write",
1716
"git add"
18-
],
19-
"*.js": [
20-
"npm run test:staged -- "
2117
]
2218
},
2319
"dependencies": {
2420
"react": "^16.4.1",
2521
"react-dom": "^16.4.1",
26-
"react-scripts": "1.1.4"
22+
"react-scripts": "1.1.4",
23+
"rss-parser": "^3.4.2"
2724
},
2825
"devDependencies": {
2926
"cross-env": "^5.2.0",

src/App.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/components/App.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React, { Component } from 'react'
2+
3+
import Library from './Library/Library'
4+
5+
class App extends Component {
6+
render() {
7+
return (
8+
<div className="App">
9+
<Library />
10+
</div>
11+
)
12+
}
13+
}
14+
15+
export default App
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react'
2+
3+
class Header extends React.Component {
4+
addPodcast = event => {
5+
event.preventDefault()
6+
// FIXME: Create a modal instead of an input type
7+
const rssUrl = this.rssUrlField.value
8+
this.props.addPodcast(rssUrl)
9+
}
10+
11+
render() {
12+
return (
13+
<header>
14+
<h1>{this.props.heading}</h1>
15+
{/* TODO: Abstract this into a button component */}
16+
<input type="text" ref={input => (this.rssUrlField = input)} />
17+
<button onClick={this.addPodcast}>Add Podcast</button>
18+
</header>
19+
)
20+
}
21+
}
22+
23+
export default Header

src/components/Library/Library.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* global RSSParser */
2+
import 'rss-parser/dist/rss-parser.min.js'
3+
import React from 'react'
4+
5+
import Header from './Header/Header'
6+
7+
class Library extends React.Component {
8+
constructor(props) {
9+
super(props)
10+
this.state = {
11+
podcastFeeds: [],
12+
libraryHeading: 'Your Podcasts',
13+
}
14+
this.rssParser = new RSSParser()
15+
}
16+
17+
addPodcastRSSFeedFromUrl = rssUrl => {
18+
this.rssParser
19+
.parseURL(rssUrl)
20+
.then(feed => {
21+
this.setState({ podcastFeeds: [...this.state.podcastFeeds, feed] })
22+
})
23+
// FIXME: Handle error cases
24+
.catch()
25+
}
26+
27+
render() {
28+
return (
29+
<Header
30+
addPodcast={this.addPodcastRSSFeedFromUrl}
31+
heading={this.state.libraryHeading}
32+
/>
33+
)
34+
}
35+
}
36+
37+
export default Library

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom'
33

4-
import App from './App'
4+
import App from './components/App'
55
import registerServiceWorker from './registerServiceWorker'
66

77
ReactDOM.render(<App />, document.getElementById('root'))

0 commit comments

Comments
 (0)