Skip to content

Commit

Permalink
feat: adding like, dislike to api.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ShimiEstudia authored and ShimiEstudia committed May 4, 2023
1 parent cd55c8b commit 07a4015
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 31 deletions.
Binary file removed .DS_Store
Binary file not shown.
Binary file removed src/.DS_Store
Binary file not shown.
Binary file removed src/blocks/.DS_Store
Binary file not shown.
Binary file removed src/blocks/button/.DS_Store
Binary file not shown.
Binary file removed src/blocks/card/.DS_Store
Binary file not shown.
Binary file removed src/blocks/container/.DS_Store
Binary file not shown.
Binary file removed src/blocks/edit-profile/.DS_Store
Binary file not shown.
Binary file removed src/blocks/header/.DS_Store
Binary file not shown.
Binary file removed src/blocks/header/__logo/.DS_Store
Binary file not shown.
Binary file removed src/blocks/main-text/.DS_Store
Binary file not shown.
Binary file removed src/blocks/main/.DS_Store
Binary file not shown.
Binary file removed src/blocks/modal/.DS_Store
Binary file not shown.
Binary file removed src/blocks/owner/.DS_Store
Binary file not shown.
Binary file removed src/blocks/photo-popup/.DS_Store
Binary file not shown.
Binary file removed src/blocks/upload/.DS_Store
Binary file not shown.
50 changes: 43 additions & 7 deletions src/components/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ export default class Api {
return profileAvatar;
}

/* async editProfileInfoAvatar(name, about, avatar) {
async editProfileInfoAvatar(name, about, avatar) {
const profileInfoAvatar = await this._useFetch(
`${this.originURL}/users/me`,
"PATCH",
{ name: name, about: about, avatar: avatar }
);
console.log("API profileInfoAvatar", profileInfoAvatar);
return profileInfoAvatar;
} */
}

async addNewCard(name, link) {
const newCard = await this._useFetch(`${this.originURL}/cards`, "POST", {
Expand All @@ -75,17 +75,53 @@ export default class Api {
return newCard;
}

async deleteCard(cardId) {
async deleteCard(cardId, userId) {
let deletingCard;

//si el creador de la card es igual al userId, que aparezca el botón borrar
//(el basurero), sino, no me muestra el basurero.
if (userId === cardId) {
try {
deletingCard = await this._useFetch(
`${this.originURL}/cards/${cardId}`,
"DELETE"
);
console.log("deleteCard", deletingCard);
} catch (err) {
console.log(err);
}
console.log("MUESTRO BASURERO")
return deletingCard;
} else {
console.log("ESCONDO BASURERO")
}
}

async likeCard(cardId) {
let likesCard;
try {
likesCard = await this._useFetch(
`${this.originURL}/cards/likes/${cardId}`,
"PUT"
);
console.log("likeCard", likesCard);
} catch (err) {
console.log(err);
}
return likesCard;
}

async dislikeCard(cardId) {
let dislikesCard;
try {
deletingCard = await this._useFetch(
`${this.originURL}/cards/${cardId}`,
dislikesCard = await this._useFetch(
`${this.originURL}/cards/likes/${cardId}`,
"DELETE"
);
console.log("deleteCard", deletingCard);
console.log("dislikeCard", dislikesCard);
} catch (err) {
console.log(err);
}
return deletingCard;
return dislikesCard;
}
}
17 changes: 1 addition & 16 deletions src/components/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ export default class Card {
cardTitle.textContent = this._name;
cardLikes.textContent = this.likeCountNumber();

const deleteButton = this._element.querySelector(".card__delete-button");
deleteButton.addEventListener("click", (evt) => {
evt.stopPropagation();
handleDeleteCard(this._element, this._id);
});

return this._element;
}

Expand All @@ -53,7 +47,6 @@ export default class Card {
}

async _handleDeleteCard(e) {
e.preventDefault();
e.target.closest(".card").remove();
console.log("id", this._id);
const result = await this._api.deleteCard(this._id);
Expand All @@ -80,15 +73,7 @@ export default class Card {
.addEventListener("submit", (e) => {
this._handleDeleteCard(e);
//popupWithFormsDeleteCard.close(e);
});
*/
this._deleteButton.addEventListener("click", () => {
handleDeleteCard(this._element);
});
}); */

this._element
.querySelector(".card__image")
Expand Down
6 changes: 1 addition & 5 deletions src/components/PopupWithForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ export class PopupWithForms extends Popup {
}
}

_resetForm() {
this._form.reset();
}

setEventListeners() {
super.setEventListeners();

Expand All @@ -53,4 +49,4 @@ export class PopupWithForms extends Popup {
}

export const popupWithFormsDeleteCard = new PopupWithForms(openDeleteCardPopUp);
/* export const popupWithFormsEditAvatar = new PopupWithForms(openEditAvatarPopUp); */
/* export const popupWithFormsEditAvatar = new PopupWithForms(openEditAvatarPopUp); */
1 change: 0 additions & 1 deletion src/components/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const openAddPlaceButton = document.querySelector(".button-add");
export const openEditProfilePopUp = document.querySelector(".edit-profile");
export const openEditAvatarPopUp = document.querySelector(".edit-avatar");
export const openDeleteCardPopUp = document.querySelector(".delete-card");
export const deleteCardForm = document.querySelector(".delete-card__form");
export const openAddPlacePopUp = document.querySelector(".add-place");
export const openPhotoPopUp = document.querySelector(".photo-popup");
export const addPlaceName = document.querySelector(".add-place__name");
Expand Down
Binary file removed src/pages/.DS_Store
Binary file not shown.
3 changes: 1 addition & 2 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
openAddPlaceButton,
//openDeleteCardPopUp,
//openEditAvatarPopUp,
deleteCardForm,
config,
textName,
textAbout,
Expand All @@ -39,7 +38,7 @@ async function main() {

const PopUpEditProfile = new PopupWithForms(openEditProfilePopUp);
//en popupWithForms
const PopUpDeleteCard = new PopupWithForms(openDeleteCardPopUp);
//const PopUpDeleteCard = new PopupWithForms(openDeleteCardPopUp); -> card
const PopUpEditAvatar = new PopupWithForms(openEditAvatarPopUp);
const PopUpAddPhoto = new PopupWithForms(openAddPlacePopUp);
const AddUserInfo = new UserInfo(textName, textAbout, avatar);
Expand Down

0 comments on commit 07a4015

Please sign in to comment.