Commit 2cf78bd2 authored by Evan You's avatar Evan You

add comment collapse

parent f411fced
...@@ -3,9 +3,14 @@ ...@@ -3,9 +3,14 @@
<div class="by"> <div class="by">
<router-link :to="'/user/' + comment.by">{{ comment.by }}</router-link> <router-link :to="'/user/' + comment.by">{{ comment.by }}</router-link>
{{ comment.time | timeAgo }} ago {{ comment.time | timeAgo }} ago
<span v-if="comment.kids && comment.kids.length">
| <a class="expand" @click="open = !open">
{{ (open ? 'collapse ' : 'expand ') + pluralize(comment.kids.length) }}
</a>
</span>
</div> </div>
<div class="text" v-html="comment.text"></div> <div class="text" v-html="comment.text"></div>
<ul class="comment-children"> <ul class="comment-children" v-show="open">
<comment v-for="id in comment.kids" :id="id"></comment> <comment v-for="id in comment.kids" :id="id"></comment>
</ul> </ul>
</li> </li>
...@@ -15,6 +20,11 @@ ...@@ -15,6 +20,11 @@
export default { export default {
name: 'comment', name: 'comment',
props: ['id'], props: ['id'],
data () {
return {
open: true
}
},
computed: { computed: {
comment () { comment () {
return this.$store.state.items[this.id] return this.$store.state.items[this.id]
...@@ -24,6 +34,11 @@ export default { ...@@ -24,6 +34,11 @@ export default {
this.$store.dispatch('FETCH_ITEMS', { this.$store.dispatch('FETCH_ITEMS', {
ids: [this.id] ids: [this.id]
}) })
},
methods: {
pluralize (n) {
return n + (n === 1 ? ' reply' : ' replies')
}
} }
} }
</script> </script>
...@@ -35,6 +50,9 @@ export default { ...@@ -35,6 +50,9 @@ export default {
.comment .comment
border-top 1px solid #eee border-top 1px solid #eee
position relative
.expand
cursor pointer
.by, .text .by, .text
font-size .9em font-size .9em
padding 1em 0 padding 1em 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment