Skip to content

Commit 5f6d6b9

Browse files
author
Evan You
committed
deal with polls
1 parent 539596a commit 5f6d6b9

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

css/style.css

+10
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ a {
9090
.story .subtext a:hover {
9191
text-decoration: underline;
9292
}
93+
.story .poll-options {
94+
padding-left: 30px;
95+
list-style-type: disc;
96+
}
97+
.story .poll-options li {
98+
margin: 12px 0;
99+
}
100+
.story .poll-options li p {
101+
margin: 8px 0;
102+
}
93103
.story.current {
94104
background-color: #ededdf;
95105
}

css/style.styl

+8-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ a
7777
a
7878
color $gray
7979
.subtext a:hover
80-
text-decoration underline
80+
text-decoration underline
81+
.poll-options
82+
padding-left 30px
83+
list-style-type disc
84+
li
85+
margin 12px 0
86+
p
87+
margin 8px 0
8188
&.current
8289
background-color darken($bg, 5%)
8390

index.html

+11-4
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,26 @@
1515
<span class="index">{{index}}.</span>
1616
<p>
1717
<a class="title" href="{{href}}" target="_blank">{{title}}</a>
18-
<span class="domain" v-show="!isJob">
18+
<span class="domain" v-show="showDomain">
1919
({{url | domain}})
2020
</span>
2121
</p>
2222
<p class="subtext">
23-
<span v-show="!isJob">
23+
<span v-show="showInfo">
2424
{{score}} points by
2525
<a v-on="click:$root.openUser(by)">{{by}}</a>
2626
</span>
2727
{{time | fromNow}} ago
28-
<span class="comments-link" v-show="!isJob">
28+
<span class="comments-link" v-show="showInfo">
2929
| <a v-on="click:$root.openComments($data)">comments</a>
3030
</span>
3131
</p>
32+
<ul class="poll-options" v-if="pollOptions">
33+
<li v-repeat="pollOptions">
34+
<p>{{text}}</p>
35+
<p class="subtext">{{score}} points</p>
36+
</li>
37+
</ul>
3238
</script>
3339

3440
<!-- comment component template -->
@@ -81,7 +87,7 @@ <h1><a href="#1">Hacker News</a></h1>
8187

8288
<!-- comments sidebar -->
8389
<div class="sidebar comments" v-if="inspectedStory" v-transition>
84-
<div class="story" v-component="story" v-with="inspectedStory"></div>
90+
<div class="story inspected" v-component="story" v-with="inspectedStory"></div>
8591
<p v-show="!inspectedComments.length">No comments yet.</p>
8692
<ul>
8793
<li class="comment" v-repeat="inspectedComments" v-component="comment"></li>
@@ -110,5 +116,6 @@ <h1><a href="#1">Hacker News</a></h1>
110116
</div>
111117
<script src="js/store.js"></script>
112118
<script src="js/app.js"></script>
119+
<script src="js/router.js"></script>
113120
</body>
114121
</html>

js/app.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,23 @@ Vue.component('story', {
1111
href: function () {
1212
return this.url || ('http://news.ycombinator.com/item?id=' + this.id)
1313
},
14-
isJob: function () {
15-
return this.type === 'job'
14+
showInfo: function () {
15+
return this.type === 'story' || this.type === 'poll'
16+
},
17+
showDomain: function () {
18+
return this.type === 'story'
1619
},
1720
highlighted: function () {
1821
return this.$root.inspectedStory.id === this.id
1922
}
23+
},
24+
compiled: function () {
25+
// render poll options
26+
if (this.type === 'poll' && this.$el.classList.contains('inspected')) {
27+
store.fetchItems(this.parts, function (options) {
28+
this.$add('pollOptions', options)
29+
}.bind(this))
30+
}
2031
}
2132
})
2233

0 commit comments

Comments
 (0)