Skip to content

Commit b980373

Browse files
committed
move html into components
1 parent b64d216 commit b980373

File tree

7 files changed

+33
-255
lines changed

7 files changed

+33
-255
lines changed

2-react-router/src/js/client.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import React from "react";
22
import ReactDOM from "react-dom";
33
import { Router, Route, IndexRoute, hashHistory } from "react-router";
44

5-
import Bootstrap from "./vendor/bootstrap-without-jquery";
6-
75
import Archives from "./pages/Archives";
86
import Featured from "./pages/Featured";
97
import Layout from "./pages/Layout";

2-react-router/src/js/components/Article.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default class extends React.Component {
66

77
return (
88
<div class="col-md-4">
9-
<h2>{title}</h2>
9+
<h4>{title}</h4>
1010
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Saepe rem nisi accusamus error velit animi non ipsa placeat. Recusandae, suscipit, soluta quibusdam accusamus a veniam quaerat eveniet eligendi dolor consectetur.</p>
1111
<a class="btn btn-default" href="#">More Info</a>
1212
</div>

2-react-router/src/js/components/layout/nav.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,47 @@ import React from "react";
22
import { IndexLink, Link } from "react-router";
33

44
export default class Nav extends React.Component {
5+
constructor() {
6+
super()
7+
this.state = {
8+
collapsed: true,
9+
};
10+
}
11+
12+
toggleCollapse() {
13+
const collapsed = !this.state.collapsed;
14+
this.setState({collapsed});
15+
}
16+
517
render() {
618
const { location } = this.props;
19+
const { collapsed } = this.state;
720
const featuredClass = location.pathname === "/" ? "active" : "";
821
const archivesClass = location.pathname.match(/^\/archives/) ? "active" : "";
922
const settingsClass = location.pathname.match(/^\/settings/) ? "active" : "";
23+
const navClass = collapsed ? "collapse" : "";
1024

1125
return (
1226
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
1327
<div class="container">
1428
<div class="navbar-header">
15-
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
29+
<button type="button" class="navbar-toggle" onClick={this.toggleCollapse.bind(this)} >
1630
<span class="sr-only">Toggle navigation</span>
1731
<span class="icon-bar"></span>
1832
<span class="icon-bar"></span>
1933
<span class="icon-bar"></span>
2034
</button>
2135
</div>
22-
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
36+
<div class={"navbar-collapse " + navClass} id="bs-example-navbar-collapse-1">
2337
<ul class="nav navbar-nav">
2438
<li class={featuredClass}>
25-
<IndexLink to="/">Featured</IndexLink>
39+
<IndexLink to="/" onClick={this.toggleCollapse.bind(this)}>Featured</IndexLink>
2640
</li>
2741
<li class={archivesClass}>
28-
<Link to="archives">Archives</Link>
42+
<Link to="archives" onClick={this.toggleCollapse.bind(this)}>Archives</Link>
2943
</li>
3044
<li class={settingsClass}>
31-
<Link to="settings">Settings</Link>
45+
<Link to="settings" onClick={this.toggleCollapse.bind(this)}>Settings</Link>
3246
</li>
3347
</ul>
3448
</div>

2-react-router/src/js/pages/Featured.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ export default class Featured extends React.Component {
99
"Some Other Article",
1010
"Yet Another Article",
1111
"Still More",
12+
"Some Article",
13+
"Some Other Article",
14+
"Yet Another Article",
15+
"Still More",
16+
"Some Article",
17+
"Some Other Article",
18+
"Yet Another Article",
19+
"Still More",
1220
].map((title, i) => <Article key={i} title={title}/> );
1321

1422
const adText = [
@@ -20,7 +28,7 @@ export default class Featured extends React.Component {
2028
];
2129

2230
const randomAd = adText[Math.round( Math.random() * (adText.length-1) )];
23-
31+
console.log("featured");
2432
return (
2533
<div>
2634
<div class="row">

2-react-router/src/js/pages/Layout.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import Nav from "../components/layout/Nav";
66

77
export default class Layout extends React.Component {
88
render() {
9-
const { history, location } = this.props;
9+
const { location } = this.props;
1010
const containerStyle = {
1111
marginTop: "60px"
1212
};
13-
13+
console.log("layout");
1414
return (
1515
<div>
1616

17-
<Nav {...{history, location}} />
17+
<Nav location={location} />
1818

1919
<div class="container" style={containerStyle}>
2020
<div class="row">

2-react-router/src/js/pages/Settings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22

33
export default class Settings extends React.Component {
44
render() {
5+
console.log("settings");
56
return (
67
<h1>Settings</h1>
78
);

2-react-router/src/js/vendor/bootstrap-without-jquery.js

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

0 commit comments

Comments
 (0)