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 () => {
|
const reload = async () => {
|
||||||
await loadPosts().then(data => {
|
await loadPosts().then(posts => {
|
||||||
setPosts(data);
|
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 loadPosts = async () => {
|
||||||
const location = await locationUtils.getCurrentLocation();
|
const location = await locationUtils.getCurrentLocation();
|
||||||
return await postApi.getPostsByCoords(location.lon, location.lat);
|
return await postApi.getPostsByCoords(location.lon, location.lat);
|
||||||
|
|||||||
Reference in New Issue
Block a user