Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project 9 - First Submission #1

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Project 8: Around The U.S.
# Project 9: Around The U.S.

Choose a reason for hiding this comment

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

According to the task you need to change submit buttons text (Saving…) while waiting for the server response. And the user should see it.

### Overview

Expand All @@ -20,6 +20,9 @@
* Classes
* Modules
* OOP
* Promises
* Error Handling
* APIs


**Intro**
Expand Down
3 changes: 2 additions & 1 deletion src/blocks/card.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

.card__like-button:hover {
opacity: 50%;
transition: all 0.9s ease-in;
transition: all 0.3s ease-in-out;
}

.card__delete-button {
Expand All @@ -67,4 +67,5 @@

.card__delete-button:hover {
opacity: 0.5;
transition: all 0.3s ease-in-out;
}
50 changes: 44 additions & 6 deletions src/blocks/modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,43 @@
pointer-events: all;
transition: visibility 0s, opacity 0.5s linear;
}


.modal__close-button {
position: absolute;
top: -45px;
right: -45px;
background: transparent url(../images/close-icon.svg) no-repeat center;
border: none;
width: 45px;
height: 45px;
padding: 0;
transition: ease-in-out 0.4s;
}

.modal__close-button:hover {
opacity: 0.6;
cursor: pointer;
}

.modal__submit-button_delete {
margin: 36px;
padding: 14px 124px;
width: 358px;
background-color: #000000;
color: #ffffff;
}

.modal__submit-button {
background-color: #000000;
color: #ffffff;
padding-top: 10px;
padding-bottom: 10px;
}

.modal__submit-button_delete:hover {
cursor: pointer;
}

.modal__close {
position: absolute;
margin: 0;
Expand All @@ -59,7 +95,6 @@
.modal__container {
background-color: white;
width: 430px;
/* height: 330px; */
align-content: center;
justify-content: center;
border-radius: 10px;
Expand Down Expand Up @@ -194,19 +229,22 @@
margin: 0 0 29px;
width: 100%;
}

.modal__input_type_error{
margin: 0;
}

.modal__button {
height: 46px;
width: 100%;
/* margin: 45px 22px 25px; */
/* padding-left: 10px; */
/* padding-right: 10px; */
margin: unset;
padding: unset;
}

.modal__submit-button {
width: 70%;
}

.modal__button_disabled:hover {
opacity: 0.2;
cursor: default;
Expand Down
41 changes: 41 additions & 0 deletions src/blocks/profile.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,39 @@
border-radius: 50%;
}

.profile__avatar {
width: 120px;
height: 120px;
object-fit: cover;
border-radius: 50%;
position: relative;
}

.profile__avatar-edit {
position: absolute;
top: 0;
left: 0;
padding: 0;
border: 0;
height: 100%;
width: 100%;
background-size: 26px;
background-image: url("../images/edit-b.svg");
background-repeat: no-repeat;
background-position: center;
background-color: rgba(0, 0, 0, 0.8);
border-radius: 50%;
opacity: 0;
outline: none;
transition: all 0.3s;
}

.profile__avatar-edit:hover {
opacity: 1;
cursor: pointer;
}


.profile__info {
margin-left: 19px;
display: grid;
Expand Down Expand Up @@ -84,6 +117,14 @@
transition: all 0.3s ease-in-out;
opacity: 0.6;
}

.profile__avatar-container {
width: 120px;
height: 120px;
position: relative;
margin-right: 30px;

}

@media screen and (min-width:320px) and (max-width:880px){

Expand Down
90 changes: 90 additions & 0 deletions src/components/Api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
export default class Api {
constructor(options) {
this._url = options.url;
this._headers = options.headers;
}
_getResponse(res) {
return res.ok ? res.json() : Promise.reject(`Error: ${res.status}`);
}

getUserInfo() {
return fetch(this._url + "users/me", {
headers: this._headers,
}).then(this._getResponse);

Choose a reason for hiding this comment

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

Could be improved

You can make a special method for fetching and checking responses not to duplicate it in every request:

  _request(url, options) {
    return fetch(url, options).then(this._getResponse)
  }

And now you can safely replace fetch with this._request and remove repeated checking. And you don’t need to change anything else.

}

getInitialCards() {
return fetch(this._url + "cards", {
headers: {
authorization: "0d8f734d-caf1-45e3-b9d3-764b4099955a"
kn8-codes marked this conversation as resolved.
Show resolved Hide resolved
}
})
.then(res => {
if (res.ok) {
return res.json();
}
// if the server returns an error, reject the promise
return Promise.reject(`Error: ${res.status}`);
});
kn8-codes marked this conversation as resolved.
Show resolved Hide resolved
}
updateProfile(name, profession) {
return fetch(this._url + "users/me", {
method: "PATCH",
headers: this._headers,
body: JSON.stringify({
name: name,
about: profession,
}),
}).then(this._getResponse);
}

uploadCard({ name, link }) {
return fetch(this._url + "cards", {
method: "POST",
headers: this._headers,
body: JSON.stringify({
name,
link,
}),
}).then(this._getResponse);
}

deleteCard(cardId) {
return fetch(this._url + `cards/${cardId}`, {
method: "DELETE",
headers: this._headers,
}).then(this._getResponse);
}

updateAvatar(data) {
return fetch(this._url + "users/me/avatar", {
method: "PATCH",
headers: this._headers,
body: JSON.stringify({
avatar: data.link,
}),
}).then(this._getResponse);
}

// getLikes(cardId) {
// return fetch(`${this._url}cards/likes/${cardId}`, {
// headers: this._headers,
// }).then(this._getResponse);
// }

addLike(cardId) {
return fetch(this._url + `cards/${cardId}/likes`, {
headers: this._headers,
method: "PUT",
}).then(this._getResponse);
}

removeLike(cardId) {
return fetch(this._url + `cards/${cardId}/likes`, {
headers: this._headers,
method: "DELETE",
}).then(this._getResponse);
}
// other methods for working with the API
};

114 changes: 83 additions & 31 deletions src/components/Card.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,100 @@
export default class Card{
constructor({name , link}, cardSelector, handleImageClick){
this._name = name;
this._link = link;
this._cardSelector = cardSelector;
export default class Card {
constructor({ data, handleImageClick, handleDeleteClick, handleLikeClick, userId },
cardSelector) {
this._name = data.name;
this._link = data.link;
this._cardId = data._id;
this._isLiked = data.isLiked;
this._userId = userId;
this._ownerId = data.owner._id;

this._handleImageClick = handleImageClick;

this._handleDeleteClick = handleDeleteClick;
this._handleLikeClick = handleLikeClick;
this._cardSelector = cardSelector;

}
_getTemplate() {
const cardElement = document
.querySelector(this._cardSelector)
.content.querySelector(".card")
.cloneNode(true);
.querySelector(this._cardSelector)
.content.querySelector(".card")
.cloneNode(true);
return cardElement;
}

_setEventListeners(){
this._cardElement.querySelector(".card__like-button").addEventListener('click',()=>{
this._handleLikeIcon();
}

_addDeleteIcon() {
this._deleteButton.classList.remove("card__delete-button_hidden");
this._deleteButton.addEventListener("click", () =>
this._handleDeleteClick()
);
}


_setEventListeners() {
this._cardElement.querySelector(".card__like-button").addEventListener('click', () => {
kn8-codes marked this conversation as resolved.
Show resolved Hide resolved
this._handleLikeClick();
})
this._cardElement.querySelector(".card__delete-button").addEventListener('click',()=>{
this._handleDeleteCard();

this._cardElement.querySelector(".card__delete-button").addEventListener('click', () => {
this._handleDeleteClick();
})
this._cardElement.querySelector(".card__image").addEventListener('click', () =>{
this._handleImageClick({name:this._name,link:this._link});

this._cardElement.querySelector(".card__image").addEventListener('click', () => {
kn8-codes marked this conversation as resolved.
Show resolved Hide resolved
this._handleImageClick({ name: this._name, link: this._link });
});

}
_handleLikeIcon(){
_handleLikeIcon() {
this._cardElement.querySelector('.card__like-button').classList.toggle('card__like-active')
kn8-codes marked this conversation as resolved.
Show resolved Hide resolved
}

_handleDeleteCard(){
removeCard() {
this._cardElement.remove();
this._cardElement = null;
}

getView(){
this._cardElement = this._getTemplate();
this._setEventListeners();
this._cardElement.querySelector('.card__image').src = this._link
this._cardElement.querySelector('.card__label-title').textContent = this._name
this._cardElement.querySelector('.card__image').alt = this._name
return this._cardElement;
setLikes(isLiked) {
console.log(isLiked)
this._isLiked = isLiked;
//this._cardElement.querySelector(".card__like-button").classList.add("card__like-active");
this._renderlikes();
}

_renderlikes() {
if (this._isLiked) {
this._cardElement.querySelector(".card__like-button").classList.add("card__like-active");
kn8-codes marked this conversation as resolved.
Show resolved Hide resolved
} else {
this._cardElement.querySelector(".card__like-button").classList.remove("card__like-active");
kn8-codes marked this conversation as resolved.
Show resolved Hide resolved
}
}

isLiked() {
return this._isLiked;
}

getView() {
// this._cardElement = this._getTemplate();
// this._setEventListeners();
// this._cardElement.querySelector('.card__image').src = this._link
// this._cardElement.querySelector('.card__label-title').textContent = this._name
// this._cardElement.querySelector('.card__image').alt = this._name
// return this._cardElement;
this._cardElement = this._getTemplate();

this._likeButton = this._cardElement.querySelector(".card__like-button");
this._deleteButton = this._cardElement.querySelector(".card__delete-button");
this._imageElement = this._cardElement.querySelector(".card__image");
kn8-codes marked this conversation as resolved.
Show resolved Hide resolved
this._cardname = this._cardElement.querySelector(".card__label-title");

this._imageElement.src = this._link;
this._imageElement.alt = this._name;
this._cardname.textContent = this._name;

if (this._ownerId === this._userId) {
this._addDeleteIcon();
}
this._renderlikes();
this._setEventListeners();
return this._cardElement;
}
}
Loading