generated from tripleten-com/se_project_aroundtheus
-
Notifications
You must be signed in to change notification settings - Fork 0
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
kn8-codes
wants to merge
37
commits into
main
Choose a base branch
from
project-9
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 20 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
5330f37
update
0x0sec 2f2bf95
update
0x0sec b3f7395
update
0x0sec abe7754
update
0x0sec ad541cc
update
0x0sec 0e33162
update
0x0sec ee290a1
update
0x0sec 09726e1
update
0x0sec a6a629f
update
0x0sec a7d6a84
update
0x0sec db5142b
update
0x0sec 804eac8
update
0x0sec 587bad8
update
0x0sec 2fb0790
update
0x0sec 8ac15bb
update
0x0sec 0f7cc56
update
0x0sec a29a24b
update
0x0sec 764bacf
update
0x0sec e17103d
update
0x0sec 0121d6d
update
0x0sec 000c052
update
0x0sec 10c03b8
update
0x0sec a6c48fa
update
0x0sec 11690f3
update
0x0sec acccd50
update
0x0sec e74dc77
Rename popupWithConfirmation.js to PopupWithConfirmation.js
kn8-codes 31becbe
update
0x0sec bb37fcd
update
0x0sec 686a708
update
0x0sec 5558fb4
update
0x0sec 857ff95
update
0x0sec be1c9ff
update
0x0sec f423475
update
0x0sec 9038523
update
0x0sec 9db5d4c
update
0x0sec e2880f6
update
0x0sec c101722
update
0x0sec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
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 | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.