Skip to content

Commit 0908e09

Browse files
committed
Fix add comment tweet store not updated bug
1 parent 8713501 commit 0908e09

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

frontend/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = {
4444
tabWidth: 4
4545
}],
4646
'no-trailing-spaces': 'off',
47+
'no-plusplus': 'off'
4748
},
4849
parserOptions: {
4950
parser: 'babel-eslint',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export default {
6868
tweetId: this.tweetId,
6969
text: this.text,
7070
});
71+
7172
this.clearInput();
7273
},
7374
},

frontend/src/store/modules/comment/actions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import api from '@/api/Api';
22
import { SET_LOADING } from '../../mutationTypes';
33
import { SET_COMMENTS, ADD_COMMENT } from './mutationTypes';
4+
import { INCREMENT_COMMENTS_COUNT } from '../tweet/mutationTypes';
45
import { commentMapper } from '@/services/Normalizer';
56

67
export default {
@@ -30,6 +31,7 @@ export default {
3031
const comment = await api.post('/comments', { tweet_id: tweetId, body: text });
3132

3233
commit(ADD_COMMENT, { tweetId, comment });
34+
commit(`tweet/${INCREMENT_COMMENTS_COUNT}`, tweetId, { root: true });
3335
commit(SET_LOADING, false, { root: true });
3436

3537
return Promise.resolve(commentMapper(comment));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export const SET_TWEETS = 'setTweets';
22
export const SET_TWEET_IMAGE = 'setTweetImage';
33
export const SET_TWEET = 'editTweet';
44
export const DELETE_TWEET = 'deleteTweet';
5+
export const INCREMENT_COMMENTS_COUNT = 'incrementCommentsCount';

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {
22
SET_TWEETS,
33
SET_TWEET_IMAGE,
44
SET_TWEET,
5-
DELETE_TWEET
5+
DELETE_TWEET,
6+
INCREMENT_COMMENTS_COUNT
67
} from './mutationTypes';
78
import { tweetMapper } from '@/services/Normalizer';
89

@@ -29,5 +30,9 @@ export default {
2930

3031
[DELETE_TWEET]: (state, id) => {
3132
delete state.tweets[id];
33+
},
34+
35+
[INCREMENT_COMMENTS_COUNT]: (state, id) => {
36+
state.tweets[id].commentsCount++;
3237
}
3338
};

0 commit comments

Comments
 (0)