This repository has been archived by the owner on Feb 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy path010.1-params.html
141 lines (135 loc) · 3.44 KB
/
010.1-params.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.12.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.12.2/JSXTransformer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-router/0.11.6/react-router.js"></script>
<script type="text/javascript">
var data = [
{
_id: "QQQ",
title: "Stuffed Chard",
instructions: "Stuff the chard...",
detailsRendered: "FOO CHARD DETAILS"
},
{
_id: "YYY",
title: "Eggplant and Polenta",
instructions: "Put the eggplant in the oven...",
detailsRendered: "BAR EGGPLANT DETAILS"
}
];
</script>
</head>
<body>
<div id="app-container"></div>
<script type="text/jsx">
var RecipeDetails = React.createClass({
getInitialState: function () {
console.log(this.props)
/* grab the correct recipe, set it to state */
return _.find(this.props.data, {_id: this.props.params._id});
},
render: function(){
return (
<div>
<h3> {this.state.title} </h3>
<p> {this.state.instructions} </p>
<p> {this.state.detailsRendered} id: {this.props.params._id} </p>
<RouteHandler {...this.props}/>
</div>
)
}
})
var Recipe = React.createClass({
render: function() {
return (
<div>
<h2> {this.props.title} </h2>
<p> {this.props.instructions} </p>
<Link to="recipeDetails" params={{_id: this.props._id}}> See more </Link>
<RouteHandler/>
</div>
);
}
});
var RecipeList = React.createClass({
getInitialState: function () {
return {data: data}
},
render: function() {
var recipeNodes = this.state.data.map(function(recipe, index){
return (
<Recipe
key={index}
_id={recipe._id}
title={recipe.title}
instructions={recipe.instructions} />
)
})
return (
<div>
**RecipeList.**
{recipeNodes}
<RouteHandler {...this.props}/>
</div>
);
}
});
var RecipeForm = React.createClass({
render: function() {
return (
<div >
**RecipeForm.**
</div>
);
}
});
var Home = React.createClass({
render: function () {
return (
<div>
**Home rendered, welcome text, etc**
</div>
)
}
})
var RecipeBook = React.createClass({
render: function() {
return (
<div>
<div>
<Link to="/">Home</Link>
<Link to="recipes"> Recipes </Link>
<Link to="create"> Create </Link>
</div>
**Hello, world! I am a RecipeBook.**
<RouteHandler {...this.props}/>
</div>
);
}
});
var Router = ReactRouter;
var Route = Router.Route;
var DefaultRoute = Router.DefaultRoute;
var Link = Router.Link
var RouteHandler = Router.RouteHandler;
var routes = (
<Route name="RecipeBook" path="/" handler={RecipeBook}>
<DefaultRoute handler={Home}/>
<Route name="recipeDetails" path="/recipeDetails/:_id" handler={RecipeDetails}/>
<Route name="recipes" handler={RecipeList}/>
<Route name="recipe" path="recipe" handler={Recipe}/>
<Route name="create" handler={RecipeForm}/>
</Route>
);
Router.run(routes, function (Handler, state) {
var params = state.params;
React.render(<Handler params={params} data={data}/>, document.body);
});
</script>
</body>
</html>