This repository has been archived by the owner on Jun 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
/
comment.vue
107 lines (99 loc) · 2.51 KB
/
comment.vue
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
<template>
<div :class="className" v-if="comment">
<text class="small-text comment-btn" @click="toggle(false)" v-if="collapsed">[+]</text>
<text class="small-text comment-btn" @click="toggle(true)" v-else>[-]</text>
<div class="text-group" :style="{ marginLeft: indent }">
<text class="text-cell small-text">by </text>
<div class="text-cell" @click="jump(`/user/${comment.by}`)">
<text class="small-text link">{{comment.by}}</text>
</div>
<text class="text-cell small-text"> | {{ comment.time | timeAgo }} ago</text>
<text class="text-cell small-text">{{ collapsed ? ' (collapsed)' : '' }}</text>
</div>
<div class="comment-inner" :style="{ marginLeft: indent }" v-if="!collapsed">
<text class="comment-title">{{comment.text | unescape }}</text>
<div class="comment-list">
<comment v-for="id in comment.kids" :id="id" :key="id" :depth="depth + 1"></comment>
</div>
</div>
</div>
</template>
<script>
import store from '../store'
export default {
name: 'comment',
props: {
id: {
type: [Number, String],
required: true,
default: '13230551'
},
depth: {
type: [Number, String],
default: 1
}
},
data () {
return {
collapsed: false
}
},
computed: {
className () {
return Number(this.depth) > 1 ? ['deep-comment'] : ['comment']
},
indent () {
return Number(this.depth) > 4 ? 0 : '50px'
},
comment () {
return store.state.items[this.id]
}
},
methods: {
toggle (state) {
this.collapsed = (state === undefined) ? !this.collapsed : state
}
}
}
</script>
<style scoped>
.comment {
padding-bottom: 25px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #DDDDDD;
margin-bottom: 35px;
position: relative;
}
.deep-comment {
margin-top: 25px;
position: relative;
}
.text-group {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
}
.text-cell {
flex-grow: 0;
}
.small-text {
color: #BBB;
font-size: 22px;
line-height: 22px;
margin-bottom: 10px;
font-family: Verdana, Geneva, sans-serif;
}
.link {
text-decoration: underline;
}
.comment-btn {
position: absolute;
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
}
.comment-title {
font-size: 26px;
color: #404040;
}
</style>