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

правки 2 #20

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 src/presenter/new-point-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ export default class NewPointPresenter {
#destinations = null;
#offers = null;
#isNewPoint = true;
constructor({pointListContainer, destinationsModel, offersModel, onFavoriteChange, onDestroy}) {
#onDataChange = null;
constructor({ pointListContainer, destinationsModel, offersModel, onFavoriteChange, onDestroy, onDataChange }) {
this.#pointListContainer = pointListContainer;
this.#destinationsModel = destinationsModel;
this.#offersModel = offersModel;
this.#handleFavoriteChange = onFavoriteChange;
this.#handleDestroy = onDestroy;
this.#onDataChange = onDataChange;
}

init() {
Expand Down Expand Up @@ -81,6 +83,7 @@ export default class NewPointPresenter {

#handleDeleteClick = () => {
this.destroy();
this.#onDataChange(UpdateType.MINOR);
};

#escKeyDownHandler = (evt) => {
Expand Down
6 changes: 3 additions & 3 deletions src/presenter/trip-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class TripPresenter {
onFavoriteChange: this.#handleViewAction,
onDestroy: onNewPointDestroy,
destinationsModel: this.#destinationsModel,
offersModel: this.#offersModel
offersModel: this.#offersModel,
onDataChange: this.#handleModelEvent,
});
this.#pointsModel.addObserver(this.#handleModelEvent);
this.#filtersModel.addObserver(this.#handleModelEvent);
Expand Down Expand Up @@ -75,7 +76,6 @@ class TripPresenter {
createPoint() {
this.#currentSortType = SortType.DEFAULT;
this.#filtersModel.setFilter(UpdateType.MAJOR, FilterType.EVERYTHING);
render(this.#component, this.#container);
this.#newPointPresenter.init();
}

Expand Down Expand Up @@ -115,7 +115,7 @@ class TripPresenter {
this.#uiBlocker.unblock();
};

#handleModelEvent = (updateType, data) => {
#handleModelEvent = (updateType, data = null) => {
switch (updateType) {
case UpdateType.PATCH:
this.#pointPresenter.get(data.id).init(data);
Expand Down
19 changes: 7 additions & 12 deletions src/view/edit-point-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,17 @@ export default class EditingPointView extends AbstractStatefulView{
#handleFormSubmit = null;
#handleEditClick = null;
#handleDeleteClick = null;
#handleRollUpClick = null;
#destinations = null;
#offers = null;
#datepicker = null;
#isNewPoint = null;
constructor({point = BLANK_POINT, onFormSubmit, onDeleteClick, destinations, offers, isNewPoint}){
constructor({ point = BLANK_POINT, onFormSubmit, onDeleteClick, destinations, offers, onRollUpClick, isNewPoint}){
super();
this.#point = point;
this.#handleFormSubmit = onFormSubmit;
this.#handleEditClick = onFormSubmit;
this.#handleRollUpClick = onRollUpClick;
this.#destinations = destinations;
this.#offers = offers;
this.#isNewPoint = isNewPoint;
Expand All @@ -191,9 +193,9 @@ export default class EditingPointView extends AbstractStatefulView{
this.#handleFormSubmit(EditingPointView.parseStateToPoint(this._state));
};

#editClickHandler = (event) => {
#rollUpClickHandler = (event) => {
event.preventDefault();
this.#handleEditClick(this.#point);
this.#handleRollUpClick(this.#point);
};

#deleteClickHandler = (event) => {
Expand Down Expand Up @@ -231,14 +233,7 @@ export default class EditingPointView extends AbstractStatefulView{

#changeDestinationHandler = (event) => {
event.preventDefault();
const inputDestinationName = event.target.value;
const destination = this.#destinations.find((dest) => dest.name === inputDestinationName);

if (!destination) {
event.target.value = this._state.destination.name;
return;
}

const destination = this.#destinations.find((dest) => dest.name === event.target.value);
this.updateElement({
destination: destination.id,
});
Expand Down Expand Up @@ -316,7 +311,7 @@ export default class EditingPointView extends AbstractStatefulView{
_restoreHandlers() {
this.element.querySelector('form').addEventListener('submit', this.#formSubmitHandler);
if (!this.#isNewPoint) {
this.element.querySelector('.event__rollup-btn').addEventListener('click', this.#editClickHandler);
this.element.querySelector('.event__rollup-btn').addEventListener('click', this.#rollUpClickHandler);
}
this.element.querySelector('.event__type-list').addEventListener('change', this.#changeTypeHandler);
this.element.querySelector('.event__available-offers').addEventListener('change', this.#changeOfferHandler);
Expand Down
Loading