-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
ArticleMeta.vue
executable file
·78 lines (76 loc) · 1.93 KB
/
ArticleMeta.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
<template>
<div class="article-meta">
<router-link
:to="{ name: 'profile', params: { username: article.author.username } }"
>
<img :src="article.author.image" />
</router-link>
<div class="info">
<router-link
:to="{ name: 'profile', params: { username: article.author.username } }"
class="author"
>
{{ article.author.username }}
</router-link>
<span class="date">{{ article.createdAt | date }}</span>
</div>
<rwv-article-actions
v-if="actions"
:article="article"
:canModify="isCurrentUser()"
></rwv-article-actions>
<button
v-else
class="btn btn-sm pull-xs-right"
@click="toggleFavorite"
:class="{
'btn-primary': article.favorited,
'btn-outline-primary': !article.favorited
}"
>
<i class="ion-heart"></i>
<span class="counter"> {{ article.favoritesCount }} </span>
</button>
</div>
</template>
<script>
import { mapGetters } from "vuex";
import RwvArticleActions from "@/components/ArticleActions";
import { FAVORITE_ADD, FAVORITE_REMOVE } from "@/store/actions.type";
export default {
name: "RwvArticleMeta",
components: {
RwvArticleActions
},
props: {
article: {
type: Object,
required: true
},
actions: {
type: Boolean,
required: false,
default: false
}
},
computed: {
...mapGetters(["currentUser", "isAuthenticated"])
},
methods: {
isCurrentUser() {
if (this.currentUser.username && this.article.author.username) {
return this.currentUser.username === this.article.author.username;
}
return false;
},
toggleFavorite() {
if (!this.isAuthenticated) {
this.$router.push({ name: "login" });
return;
}
const action = this.article.favorited ? FAVORITE_REMOVE : FAVORITE_ADD;
this.$store.dispatch(action, this.article.slug);
}
}
};
</script>