added sort for posts by date
This commit is contained in:
11
src/App.js
11
src/App.js
@@ -27,11 +27,18 @@ const App = () => {
|
||||
|
||||
|
||||
const reload = async () => {
|
||||
await loadPosts().then(data => {
|
||||
setPosts(data);
|
||||
await loadPosts().then(posts => {
|
||||
posts = recursiveSort(posts);
|
||||
setPosts(posts);
|
||||
});
|
||||
}
|
||||
|
||||
const recursiveSort = (posts) => {
|
||||
posts.forEach((post, index) => {posts[index].comments = recursiveSort(post.comments)});
|
||||
posts.sort((a, b) => a.date < b.date);
|
||||
return posts;
|
||||
}
|
||||
|
||||
const loadPosts = async () => {
|
||||
const location = await locationUtils.getCurrentLocation();
|
||||
return await postApi.getPostsByCoords(location.lon, location.lat);
|
||||
|
||||
Reference in New Issue
Block a user