added sort for posts by date

This commit is contained in:
2024-06-13 09:54:10 +02:00
parent 9804bd196b
commit 5cb6ef0798

View File

@@ -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);