Skip to content

Conversation

@JcarlosCabello1991
Copy link

Solution by Volha Afanasenka & Juan Carlos Cabello

Copy link

@Dejahar Dejahar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job

return (a.id.toString() - b.id.toString());
})
data.forEach(post =>{
const postElement = document.createElement("section");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps having a template would be better then creating each element

@@ -0,0 +1,100 @@
import {modifyingPost} from "./modifyPost.js";
import { deletingPost } from "./deletePost.js";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one function per javaScript? Is this optimal? Or could you have gathered more functions under one js, i.e postFunctions.js userFunctions.js commentFunctions.js . Calling many files may not be a great thing.

@@ -0,0 +1,19 @@
import { getPosts } from "./main.js";
export function modifyingPost(id, user){
const modalModify = document.getElementById("staticBackdrop-form");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const modalModify = document.getElementById("staticBackdrop-form");
const modalModifyButton = document.getElementById("modifyPostButton");

If variables are not used they should be removed, so that your code is easier to read

})
postsList.append(postElement);
})
}else{//if the user deleted some posts or modify some post, we delete all li and create all of them from the beggining
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be the other way, when you delete something you refresh the posts

const postTitle = post.title;
postElement.append(postTitle);
postElement.setAttribute("id", post.id);
postElement.setAttribute("userId", post.userId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: in order to use less code when setting atribute, perhaps you could create a function that assign values to keys and reuse it when needed.
Example:
const assignAttributes = (element, attributes) => { for (const key in attributes) { element.setAttribute(key, attributes[key]) } }

Screenshot 2022-05-17 at 11 53 33

Screenshot 2022-05-17 at 11 53 46

.then(response=>response.json())
.then(data=>{
const postsList = document.getElementById("listGroup");
Array.from(document.getElementById("listGroup").children).forEach(son=>{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We assume you guys creating an array because you want to iterate over a html collection?
it can be done with a for loop, or for in loop.

@averoli
Copy link

averoli commented May 17, 2022

Guys, thanks for the review, your comments are very useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants