diff --git a/src/App.js b/src/App.js index ab15b29..d03979a 100644 --- a/src/App.js +++ b/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);