Skip to content

Commit c8c4a55

Browse files
authored
Merge pull request #52 from BinaryStudioAcademy/bug/tweet-sorting
Fix tweets sorting on feed page
2 parents d87a3b5 + 3b143d7 commit c8c4a55

File tree

5 files changed

+11
-13
lines changed

5 files changed

+11
-13
lines changed

frontend/src/components/view/feed/FeedContainer.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ export default {
4444
},
4545
4646
computed: {
47-
...mapGetters('tweet', [
48-
'tweets'
49-
]),
47+
...mapGetters('tweet', {
48+
tweets: 'tweetsSortedByCreatedDate'
49+
}),
5050
},
5151
5252
methods: {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
SET_TWEETS,
3-
NEW_TWEET,
43
SET_TWEET_IMAGE,
54
SET_TWEET,
65
DELETE_TWEET
@@ -68,7 +67,7 @@ export default {
6867
try {
6968
const tweet = await api.post('/tweets', { text });
7069

71-
commit(NEW_TWEET, tweet);
70+
commit(SET_TWEET, tweet);
7271
commit(SET_LOADING, false, { root: true });
7372

7473
return Promise.resolve(tweetMapper(tweet));
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import moment from 'moment';
2+
13
export default {
2-
// @todo sort data by created date
3-
tweets: state => Object.values(state.tweets),
4+
tweetsSortedByCreatedDate: state => Object.values(state.tweets).sort(
5+
(a, b) => (
6+
moment(a.created).isBefore(moment(b.created)) ? 1 : -1
7+
)
8+
),
49
getTweetById: state => id => state.tweets[id]
510
};
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export const SET_TWEETS = 'setTweets';
2-
export const NEW_TWEET = 'newTweet';
32
export const SET_TWEET_IMAGE = 'setTweetImage';
43
export const SET_TWEET = 'editTweet';
54
export const DELETE_TWEET = 'deleteTweet';

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
SET_TWEETS,
3-
NEW_TWEET,
43
SET_TWEET_IMAGE,
54
SET_TWEET,
65
DELETE_TWEET
@@ -17,10 +16,6 @@ export default {
1716
});
1817
},
1918

20-
[NEW_TWEET]: (state, tweet) => {
21-
state.tweets[tweet.id] = tweetMapper(tweet);
22-
},
23-
2419
[SET_TWEET_IMAGE]: (state, { id, imageUrl }) => {
2520
state.tweets[id].imageUrl = imageUrl;
2621
},

0 commit comments

Comments
 (0)