Skip to content

Commit

Permalink
Правит код после замечаний наставника
Browse files Browse the repository at this point in the history
  • Loading branch information
AlucardOpp committed Sep 25, 2024
1 parent 8bc500d commit 7c5975d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
22 changes: 7 additions & 15 deletions src/presenter/event-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ export default class EventPresenter {
event: this.#event,
allDestinations: this.#destinations,
allOffers: this.#offers,
onEditClick: this.#handleEditClick,
onOpenFormClick: () => this.#replaceEventToForm(),
onFavoriteClick: this.#handleFavoriteClick
});

this.#eventEditComponent = new EditEventView({
event: this.#event,
allDestinations: this.#destinations,
allOffers: this.#offers,
onEditClick: this.#handleEditClick,
onCloseFormClick: () => this.#replaceFormToEvent(),
onFormSubmit: this.#handleFormSubmit
});

Expand Down Expand Up @@ -75,18 +75,18 @@ export default class EventPresenter {

resetView() {
if (this.#mode !== Mode.DEFAULT) {
this.#replaceFormToCard();
this.#replaceFormToEvent();
}
}

#replaceCardToForm() {
#replaceEventToForm() {
replace(this.#eventEditComponent, this.#eventComponent);
document.addEventListener('keydown', this.#escKeyDownHandler);
this.#handleModeChange();
this.#mode = Mode.EDITING;
}

#replaceFormToCard() {
#replaceFormToEvent() {
replace(this.#eventComponent, this.#eventEditComponent);
document.removeEventListener('keydown', this.#escKeyDownHandler);
this.#mode = Mode.DEFAULT;
Expand All @@ -95,21 +95,13 @@ export default class EventPresenter {
#escKeyDownHandler = (evt) => {
if (evt.key === 'Escape') {
evt.preventDefault();
this.#replaceFormToCard();
}
};

#handleEditClick = (evt) => {
if (evt.target.closest('.event').classList.contains(EDIT_CLASS)) {
this.#replaceFormToCard();
} else {
this.#replaceCardToForm();
this.#replaceFormToEvent();
}
};

#handleFormSubmit = (event) => {
this.#handleDataChange(event);
this.#replaceFormToCard();
this.#replaceFormToEvent();
};

#handleFavoriteClick = () => {
Expand Down
8 changes: 4 additions & 4 deletions src/view/edit-event-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,18 @@ export default class EditEventView extends AbstractView {
#allDestinations = [];
#allOffers = [];
#isCreate = false;
#handleEditClick = null;
#handleCloseFormClick = null;
#handleFormSubmit = null;

constructor({event, allDestinations, allOffers, onEditClick, onFormSubmit}) {
constructor({event, allDestinations, allOffers, onCloseFormClick, onFormSubmit}) {
super();
this.#event = event;
this.#allDestinations = allDestinations;
this.#allOffers = allOffers;
this.#isCreate = !this.#event.id;
this.#destination = (this.#isCreate) ? BLANK_EVENT.destination : getDestinationById(this.#allDestinations, this.#event.destination);
this.#offersByType = getOffersByType(this.#allOffers, this.#event.type);
this.#handleEditClick = onEditClick;
this.#handleCloseFormClick = onCloseFormClick;
this.#handleFormSubmit = onFormSubmit;

this.element.querySelector('.event__rollup-btn').addEventListener('click', this.#editClickHandler);
Expand All @@ -214,7 +214,7 @@ export default class EditEventView extends AbstractView {

#editClickHandler = (evt) => {
evt.preventDefault();
this.#handleEditClick(evt);
this.#handleCloseFormClick(evt);
};

#formSubmitHandler = (evt) => {
Expand Down
8 changes: 4 additions & 4 deletions src/view/events-item-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ export default class EventsItemView extends AbstractView {
#offersByType = null;
#allDestinations = [];
#allOffers = [];
#handleEditClick = null;
#handleOpenFormClick = null;
#handleFavoriteClick = null;

constructor({event, allDestinations, allOffers, onEditClick, onFavoriteClick}) {
constructor({event, allDestinations, allOffers, onOpenFormClick, onFavoriteClick}) {
super();
this.#event = event;
this.#allDestinations = allDestinations;
this.#allOffers = allOffers;
this.#destination = getDestinationById(this.#allDestinations, this.#event.destination);
this.#offersByType = getOffersByType(this.#allOffers, this.#event.type);
this.#handleEditClick = onEditClick;
this.#handleOpenFormClick = onOpenFormClick;
this.#handleFavoriteClick = onFavoriteClick;

this.element.querySelector('.event__rollup-btn').addEventListener('click', this.#editClickHandler);
Expand All @@ -76,7 +76,7 @@ export default class EventsItemView extends AbstractView {

#editClickHandler = (evt) => {
evt.preventDefault();
this.#handleEditClick(evt);
this.#handleOpenFormClick(evt);
};

#favoriteClickHandler = (evt) => {
Expand Down

0 comments on commit 7c5975d

Please sign in to comment.