Skip to content

Commit 8713501

Browse files
committed
Implement isTweetOwner getter
1 parent 4455356 commit 8713501

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
</div>
6565
</div>
6666

67-
<div v-if="isTweetOwner" class="column is-narrow is-12-mobile">
67+
<div v-if="isTweetOwner(tweet.id, user.id)" class="column is-narrow is-12-mobile">
6868
<div class="buttons">
6969
<b-button type="is-warning" @click="onEditTweet">Edit</b-button>
7070
<b-button type="is-danger" @click="onDeleteTweet">Delete</b-button>
@@ -136,7 +136,8 @@ export default {
136136
}),
137137
138138
...mapGetters('tweet', [
139-
'getTweetById'
139+
'getTweetById',
140+
'isTweetOwner'
140141
]),
141142
142143
...mapGetters('comment', [
@@ -147,10 +148,6 @@ export default {
147148
tweet() {
148149
return this.getTweetById(this.$route.params.id);
149150
},
150-
151-
isTweetOwner() {
152-
return this.user.id === this.tweet.author.id;
153-
},
154151
},
155152
156153
methods: {

frontend/src/store/modules/tweet/getters.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ export default {
66
moment(a.created).isBefore(moment(b.created)) ? 1 : -1
77
)
88
),
9-
getTweetById: state => id => state.tweets[id]
9+
10+
getTweetById: state => id => state.tweets[id],
11+
12+
isTweetOwner: (state, getters) => (tweetId, userId) => getters.getTweetById(tweetId).author.id === userId,
1013
};

0 commit comments

Comments
 (0)