Skip to content

Commit

Permalink
Merge pull request #19 from dashuulka/master
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored Jun 17, 2024
2 parents 82873c0 + 534c735 commit ae48050
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
44 changes: 30 additions & 14 deletions src/presenter/trip-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default class TripPresenter {
#sortComponent = null;
#noPointsComponent = null;
#loadingComponent = new LoadingView();
#newPointButtonComponent = null;

#listContainer = null;

Expand All @@ -42,13 +41,12 @@ export default class TripPresenter {
#pointPresenters = new Map();
#newPointPresenter = null;

constructor({ listContainer, pointsModel, destinationsModel, offersModel, filterModel, onNewPointDestroy, newPointButtonComponent }) {
constructor({ listContainer, pointsModel, destinationsModel, offersModel, filterModel, onNewPointDestroy }) {
this.#listContainer = listContainer;
this.#pointsModel = pointsModel;
this.#destinationsModel = destinationsModel;
this.#offersModel = offersModel;
this.#filterModel = filterModel;
this.#newPointButtonComponent = newPointButtonComponent;
this.#onNewPointDestroy = onNewPointDestroy;

this.#newPointPresenter = new NewPointPresenter({
Expand Down Expand Up @@ -183,7 +181,7 @@ export default class TripPresenter {

switch(actionType) {
case UserAction.UPDATE_POINT:
if(update.point){
if (update.point) {
try {
this.#pointPresenters.get(update.point.id).setSaving();
await this.#pointsModel.updatePoint(updateType, update.point);
Expand All @@ -200,19 +198,37 @@ export default class TripPresenter {
}
break;
case UserAction.ADD_POINT:
try {
this.#newPointPresenter.setSaving();
await this.#pointsModel.addPoint(updateType, update);
} catch (err) {
this.#newPointPresenter.setAborting();
if (update.point) {
try {
this.#newPointPresenter.setSaving();
await this.#pointsModel.addPoint(updateType, update.point);
} catch (err) {
this.#newPointPresenter.setAborting();
}
} else {
try {
this.#newPointPresenter.setSaving();
await this.#pointsModel.addPoint(updateType, update);
} catch (err) {
this.#newPointPresenter.setAborting();
}
}
break;
case UserAction.DELETE_POINT:
try {
this.#pointPresenters.get(update.id).setDeleting();
await this.#pointsModel.deletePoint(updateType, update);
} catch (err) {
this.#pointPresenters.get(update.id).setAborting();
if (update.point) {
try {
this.#pointPresenters.get(update.point.id).setDeleting();
await this.#pointsModel.deletePoint(updateType, update.point);
} catch (err) {
this.#pointPresenters.get(update.point.id).setAborting();
}
} else {
try {
this.#pointPresenters.get(update.id).setDeleting();
await this.#pointsModel.deletePoint(updateType, update);
} catch (err) {
this.#pointPresenters.get(update.id).setAborting();
}
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/template/filter-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ function createFilterTemplate(filters, currentFilterType){
</div>`;
}

export {createFilterTemplate, createFilterItems};
export {createFilterTemplate};

0 comments on commit ae48050

Please sign in to comment.