/
_id.vue
82 lines (70 loc) · 1.59 KB
/
_id.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
<template>
<div class="user-view view">
<template v-if="user">
<h1>User : {{ user.id }}</h1>
<lazy-wrapper :loading="user.loading">
<ul class="meta">
<li>
<span class="label">Created:</span> {{ user.created_time | timeAgo }} ago
</li>
<li>
<span class="label">Karma:</span> {{ user.karma || '-' }}
</li>
<li v-if="user.about" class="about" v-text="user.about" />
</ul>
</lazy-wrapper>
<p class="links">
<a :href="'https://news.ycombinator.com/submitted?id=' + user.id">submissions</a> |
<a :href="'https://news.ycombinator.com/threads?id=' + user.id">comments</a>
</p>
</template>
<template v-else>
<h1>User not found.</h1>
</template>
</div>
</template>
<script>
import LazyWrapper from '~/components/LazyWrapper'
export default {
name: 'UserView',
components: { LazyWrapper },
computed: {
user() {
return this.$store.state.users[this.$route.params.id]
}
},
head() {
return {
title: this.user ? this.user.id : 'User not found'
}
},
fetch({ store, route: { params: { id } } }) {
return store.dispatch('FETCH_USER', { id })
}
}
</script>
<style lang="stylus">
.user-view {
background-color: #fff;
box-sizing: border-box;
padding: 2em 3em;
h1 {
margin: 0;
font-size: 1.5em;
}
.meta {
list-style-type: none;
padding: 0;
}
.label {
display: inline-block;
min-width: 4em;
}
.about {
margin: 1em 0;
}
.links a {
text-decoration: underline;
}
}
</style>