Skip to content

Commit

Permalink
исправленны замечания
Browse files Browse the repository at this point in the history
  • Loading branch information
Borysodessa committed Jan 17, 2025
1 parent 3429394 commit 8d99c10
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
11 changes: 3 additions & 8 deletions src/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ export default class PointModel {
}

updateEvent(updatedEvent) {
const index = this.#events.findIndex((event) => event.id === updatedEvent.id);
if (index !== -1) {
this.#events = [
...this.#events.slice(0, index),
updatedEvent,
...this.#events.slice(index + 1)
];
}
this.#events = this.#events.map((event) =>
event.id === updatedEvent.id ? ({...updatedEvent}) : ({...event})
);
}
}
20 changes: 10 additions & 10 deletions src/presenter/event-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ export default class EventPresenter {
#eventListView = null;
#onKeyDownHandler = null;
#onEventUpdate = null;
#destinations = null;
#offers = null;

constructor({ eventsContainer, model, onEventUpdate }) {
this.#eventsContainer = eventsContainer;
this.#model = model;
this.#eventListView = new EventListView();
this.#onEventUpdate = onEventUpdate;
this.#destinations = model.destinations;
this.#offers = model.offers;
}

init() {
Expand All @@ -27,12 +31,10 @@ export default class EventPresenter {
}

#renderTripEvent(event) {
const { destinations, offers } = this.#model;

const tripEventView = new EventItemView({
event,
destinations,
offers,
destinations: this.#destinations,
offers: this.#offers,
onClick: () => this.#switchToEditMode(tripEventView, event),
onFavoriteClick: () => this.#handleFavoriteClick(event, tripEventView)
});
Expand All @@ -43,8 +45,8 @@ export default class EventPresenter {
const eventEditView = new EditingForm({
event,
events: this.#model.events,
destinations: this.#model.destinations,
offers: this.#model.offers,
destinations: this.#destinations,
offers: this.#offers,
onSubmit: () => this.#switchToViewMode(tripEventView, eventEditView),
onClick: () => this.#switchToViewMode(tripEventView, eventEditView)
});
Expand Down Expand Up @@ -79,12 +81,10 @@ export default class EventPresenter {
}

#rerenderEvent(updatedEvent, tripEventView) {

const { destinations, offers } = this.#model;
const newTripEventView = new EventItemView({
event: updatedEvent,
destinations,
offers,
destinations: this.#destinations,
offers: this.#offers,
onClick: () => this.#switchToEditMode(newTripEventView, updatedEvent),
onFavoriteClick: () => this.#handleFavoriteClick(updatedEvent, newTripEventView)
});
Expand Down
11 changes: 4 additions & 7 deletions src/presenter/general-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,13 @@ export default class GeneralPresenter {
render(new FiltersView(), this.#filtersContainer, RenderPosition.BEFOREEND);
if (this.#model.events.length === 0) {
render(new NoEventItemView(), this.#eventsContainer);
} else {
render(new SortView(), this.#eventsContainer);
this.#eventPresenter.init();
return;
}
render(new SortView(), this.#eventsContainer);
this.#eventPresenter.init();
}

#handleEventUpdate = (updatedEvent) => {
const eventIndex = this.#model.events.findIndex((event) => event.id === updatedEvent.id);
if (eventIndex !== -1) {
this.#model.events[eventIndex] = updatedEvent;
}
this.#model.updateEvent(updatedEvent);
};
}

0 comments on commit 8d99c10

Please sign in to comment.