Skip to content

Commit 69a0db5

Browse files
committed
step12 - ReactJS talks to your API
1 parent af479dd commit 69a0db5

File tree

3 files changed

+138
-36
lines changed

3 files changed

+138
-36
lines changed

.idea/workspace.xml

+94-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/Resources/views/genus/show.html.twig

+42-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<h2 class="genus-name">{{ name }}</h2>
88

9-
<a href="{{ path('genus_show_notes', {'genusName': name}) }}">Json Notes</a>
9+
{# <a href="{{ path('genus_show_notes', {'genusName': name}) }}">Json Notes</a> #}
1010

1111
<div class="sea-creature-container">
1212
<div class="genus-photo"></div>
@@ -21,28 +21,51 @@
2121
</dl>
2222
</div>
2323
</div>
24-
<div class="notes-container">
25-
<h2 class="notes-header">Notes</h2>
26-
<div><i class="fa fa-plus plus-btn"></i></div>
27-
</div>
28-
<section id="cd-timeline">
2924

30-
{#{% for note in notes %}#}
3125

32-
{#<div class="cd-timeline-block">#}
33-
{#<div class="cd-timeline-img">#}
34-
{#<img src="{{ asset('images/leanna.jpeg') }}" class="img-circle" alt="Leanna!">#}
35-
{#</div>#}
36-
{#<div class="cd-timeline-content">#}
37-
{#<h2><a href="#">AquaPelham</a></h2>#}
26+
{#<div class="notes-container">#}
27+
{#<h2 class="notes-header">Notes</h2>#}
28+
{#<div><i class="fa fa-plus plus-btn"></i></div>#}
29+
{#</div>#}
30+
{#<section id="cd-timeline">#}
31+
32+
{#&#123;&#35;{% for note in notes %}&#35;&#125;#}
33+
34+
{#&#123;&#35;<div class="cd-timeline-block">&#35;&#125;#}
35+
{#&#123;&#35;<div class="cd-timeline-img">&#35;&#125;#}
36+
{#&#123;&#35;<img src="{{ asset('images/leanna.jpeg') }}" class="img-circle" alt="Leanna!">&#35;&#125;#}
37+
{#&#123;&#35;</div>&#35;&#125;#}
38+
{#&#123;&#35;<div class="cd-timeline-content">&#35;&#125;#}
39+
{#&#123;&#35;<h2><a href="#">AquaPelham</a></h2>&#35;&#125;#}
3840

39-
{#<p>{{ note }}</p>#}
41+
{#&#123;&#35;<p>{{ note }}</p>&#35;&#125;#}
4042

41-
{#<span class="cd-date">Dec. 10, 2015</span>#}
42-
{#</div>#}
43-
{#</div>#}
43+
{#&#123;&#35;<span class="cd-date">Dec. 10, 2015</span>&#35;&#125;#}
44+
{#&#123;&#35;</div>&#35;&#125;#}
45+
{#&#123;&#35;</div>&#35;&#125;#}
4446

45-
{#{% endfor %}#}
47+
{#&#123;&#35;{% endfor %}&#35;&#125;#}
48+
49+
{#</section>#}
50+
<div id="js-notes-wrapper"></div>
4651

47-
</section>
4852
{% endblock %}
53+
{% block javascripts %}
54+
{{ parent() }}
55+
56+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react.js"></script>
57+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react-dom.js"></script>
58+
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
59+
60+
<script type="text/babel" src="{{ asset('js/notes.react.js') }}"></script>
61+
<script type="text/babel">
62+
63+
var notesUrl = '{{ path('genus_show_notes', {'genusName': name}) }}';
64+
65+
ReactDOM.render(
66+
<NoteSection url={notesUrl}/>,
67+
document.getElementById('js-notes-wrapper')
68+
);
69+
</script>
70+
71+
{% endblock %}

web/js/notes.react.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ var NoteSection = React.createClass({
1212

1313
loadNotesFromServer: function() {
1414
$.ajax({
15-
url: '/genus/octopus/notes',
15+
//url: '/app_dev.php/genus/octopus/notes',
16+
url: this.props.url,
1617
success: function (data) {
1718
this.setState({notes: data.notes});
1819
}.bind(this)

0 commit comments

Comments
 (0)