Skip to content

Commit 4455356

Browse files
committed
Implement tweetIsCommentedByUser getter
1 parent f94f650 commit 4455356

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

frontend/src/components/common/TweetPreview.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
<nav class="level is-mobile">
3434
<div class="level-left">
3535
<a class="level-item">
36-
<span class="icon is-medium">
36+
<span class="icon is-medium has-text-info">
3737
<font-awesome-icon icon="comments" />
3838
</span>
3939
{{ tweet.commentsCount }}
4040
</a>
4141
<a class="level-item">
42-
<span class="icon is-medium">
42+
<span class="icon is-medium has-text-info">
4343
<font-awesome-icon icon="heart" />
4444
</span>
4545
{{ tweet.likes_count || 0 }}

frontend/src/components/view/tweet/TweetContainer.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
<nav class="level is-mobile">
3838
<div class="level-left">
3939
<a class="level-item">
40-
<span class="icon is-medium has-text-info">
40+
<span
41+
class="icon is-medium has-text-info"
42+
:class="{ 'has-text-danger': tweetIsCommentedByUser(tweet.id, user.id) }"
43+
>
4144
<font-awesome-icon icon="comments" />
4245
</span>
4346
{{ tweet.commentsCount }}
@@ -137,7 +140,8 @@ export default {
137140
]),
138141
139142
...mapGetters('comment', [
140-
'getCommentsByTweetId'
143+
'getCommentsByTweetId',
144+
'tweetIsCommentedByUser'
141145
]),
142146
143147
tweet() {
@@ -146,7 +150,7 @@ export default {
146150
147151
isTweetOwner() {
148152
return this.user.id === this.tweet.author.id;
149-
}
153+
},
150154
},
151155
152156
methods: {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export default {
22
getCommentsByTweetId: state => tweetId => state.comments[tweetId] || [],
3+
4+
tweetIsCommentedByUser: (state, getters) => (tweetId, userId) => getters
5+
.getCommentsByTweetId(tweetId)
6+
.find(comment => comment.authorId === userId),
37
};

0 commit comments

Comments
 (0)