Commit ee378d2c authored by Pooya Parsa's avatar Pooya Parsa

add titles

parent a8947de1
...@@ -33,6 +33,11 @@ ...@@ -33,6 +33,11 @@
components: { components: {
Item Item
}, },
head() {
return {
title: camelize(this.$route.params.type)
}
},
data() { data() {
return { return {
transition: 'slide-right', transition: 'slide-right',
......
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
</span> </span>
<p class="meta"> <p class="meta">
{{ item.score }} points {{ item.score }} points
| by <router-link :to="'/user/' + item.by">{{ item.by }}</router-link> | by
<router-link :to="'/user/' + item.by">{{ item.by }}</router-link>
{{ item.time | timeAgo }} ago {{ item.time | timeAgo }} ago
</p> </p>
</div> </div>
...@@ -33,14 +34,20 @@ ...@@ -33,14 +34,20 @@
export default { export default {
name: 'item-view', name: 'item-view',
components: { Spinner, Comment }, components: {Spinner, Comment},
data: () => ({ data: () => ({
loading: true loading: true
}), }),
head() {
return {
title: this.item.title
}
},
computed: { computed: {
item () { item() {
return this.$store.state.items[this.$route.params.id] return this.$store.state.items[this.$route.params.id]
} }
}, },
...@@ -48,16 +55,12 @@ ...@@ -48,16 +55,12 @@
// We only fetch the item itself before entering the view, because // We only fetch the item itself before entering the view, because
// it might take a long time to load threads with hundreds of comments // it might take a long time to load threads with hundreds of comments
// due to how the HN Firebase API works. // due to how the HN Firebase API works.
asyncData ({ store, route: { params: { id }}}) { asyncData({store, route: {params: {id}}}) {
return store.dispatch('FETCH_ITEMS', { ids: [id] }) return store.dispatch('FETCH_ITEMS', {ids: [id]})
},
title () {
return this.item.title
}, },
// Fetch comments when mounted on the client // Fetch comments when mounted on the client
beforeMount () { beforeMount() {
this.fetchComments() this.fetchComments()
}, },
...@@ -67,7 +70,7 @@ ...@@ -67,7 +70,7 @@
}, },
methods: { methods: {
fetchComments () { fetchComments() {
this.loading = true this.loading = true
fetchComments(this.$store, this.item).then(() => { fetchComments(this.$store, this.item).then(() => {
this.loading = false this.loading = false
...@@ -77,7 +80,7 @@ ...@@ -77,7 +80,7 @@
} }
// recursively fetch all descendent comments // recursively fetch all descendent comments
function fetchComments (store, item) { function fetchComments(store, item) {
if (item && item.kids) { if (item && item.kids) {
return store.dispatch('FETCH_ITEMS', { return store.dispatch('FETCH_ITEMS', {
ids: item.kids ids: item.kids
...@@ -92,7 +95,7 @@ ...@@ -92,7 +95,7 @@
.item-view-header .item-view-header
background-color #fff background-color #fff
padding 1.8em 2em 1em padding 1.8em 2em 1em
box-shadow 0 1px 2px rgba(0,0,0,.1) box-shadow 0 1px 2px rgba(0, 0, 0, .1)
h1 h1
display inline display inline
font-size 1.5em font-size 1.5em
......
...@@ -20,29 +20,29 @@ ...@@ -20,29 +20,29 @@
<script> <script>
export default { export default {
name: 'user-view', name: 'user-view',
computed: { computed: {
user () { user() {
return this.$store.state.users[this.$route.params.id] return this.$store.state.users[this.$route.params.id]
} }
}, },
asyncData ({ store, route: { params: { id }}}) { head() {
return store.dispatch('FETCH_USER', { id }) return {
title: this.user.id || 'User not found'
}
}, },
title () { fetch({store, route: {params: {id}}}) {
return this.user return store.dispatch('FETCH_USER', {id})
? this.user.id },
: 'User not found'
} }
}
</script> </script>
<style lang="stylus"> <style lang="stylus">
.user-view .user-view
background-color #fff background-color #fff
box-sizing border-box box-sizing border-box
padding 2em 3em padding 2em 3em
......
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