Skip to content

Commit

Permalink
время пришло
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelUd committed Jun 6, 2024
1 parent 53cde1c commit 7994fc5
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 247 deletions.
7 changes: 7 additions & 0 deletions src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ export const EnabledSortType = {
[POINT_SORTS.OFFERS]: false
};

export const EmptyListMessage = {
[FILTER_TYPES.EVERYTHING]: 'Click New Event to create your first point',
[FILTER_TYPES.FUTURE]: 'There are no future events now',
[FILTER_TYPES.PRESENT]: 'There are no present events now',
[FILTER_TYPES.PAST]: 'There are no past events now'
};

export const POINT_EMPTY = {
basePrice: 0,
dateFrom: null,
Expand Down
10 changes: 4 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const pointsModel = new PointsModel({service : service, destinationsModel : dest
const filterModel = new FilterModel();

const newPointButtonPresenter = new NewPointButtonPresenter({
container: tripEventsContainer
container: siteMainContainer
});

const tripInfoPresenter = new TripInfoPresenter({
Expand All @@ -48,12 +48,10 @@ const filterPresenter = new FilterPresenter({
filterModel,
});


newPointButtonPresenter.init({
onButtonClick:boardPresenter.handleNewPointClick
});

pointsModel.init();
filterPresenter.init();
boardPresenter.init();
newPointButtonPresenter.init({
onButtonClick:boardPresenter.handleNewPointClick
});
tripInfoPresenter.init();
49 changes: 0 additions & 49 deletions src/mock/const.js

This file was deleted.

19 changes: 0 additions & 19 deletions src/mock/destination.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/mock/filter.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/mock/offer.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/mock/point.js

This file was deleted.

32 changes: 0 additions & 32 deletions src/mock/util.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/model/point-model.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Observable from '../framework/observable';
import { updateItem } from '../mock/util.js';
import { updateItem } from '../utils/common.js';
import {UpdateType} from '../const.js';
import { adaptToClient, adaptToServer } from '../utils/adapter.js';

Expand Down
15 changes: 8 additions & 7 deletions src/presenter/board-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PointPresenter from './point-presenter';
import NewPointPresenter from './new-point-presenter';
import SortPresenter from './sort-presenter';
import {remove, render, RenderPosition} from '../framework/render';
import { filter, sort } from '../utils/utils';
import { filter, sort } from '../utils/common.js';
import LoadingView from '../view/load-view.js';
import UiBlocker from '../framework/ui-blocker/ui-blocker.js';
import {FILTER_TYPES, POINT_SORTS, UpdateType, UserAction} from '../const.js';
Expand Down Expand Up @@ -70,17 +70,15 @@ export default class BoardPresenter {
}

#renderBoard = () =>{

if (this.#isLoading) {
this.#renderLoader();
return;
}

if (this.#isError) {
this.#renderError();
this.#clearBoard({ resetSortType: true });
return;
}
if (this.#isLoading) {
this.#renderLoader();
return;
}

if (!this.points.length && !this.#isCreating) {
this.#renderEmptyList();
Expand Down Expand Up @@ -181,6 +179,7 @@ export default class BoardPresenter {
#clearTaskList = () => {
this.#pointPresenters.forEach((presenter) => presenter.destroy());
this.#pointPresenters.clear();
this.#newPointPresenter.destroy();
};

#handleSortChange = (sortType) => {
Expand All @@ -203,8 +202,10 @@ export default class BoardPresenter {
break;
case UpdateType.PATCH:
this.#pointPresenters.get(data.id).init(data);
this.#pointPresenters.get(data.id).resetView();
break;
case UpdateType.MINOR:

this.#clearBoard();
this.#renderBoard();
break;
Expand Down
2 changes: 1 addition & 1 deletion src/presenter/filter-presenter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UpdateType } from '../const';
import { render, replace, remove } from '../framework/render';
import { filter } from '../utils/utils.js';
import { filter } from '../utils/common.js';
import FilterView from '../view/filter-view';

export default class FilterPresenter {
Expand Down
22 changes: 10 additions & 12 deletions src/presenter/new-point-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ export default class NewPointPresenter {
UpdateType.MINOR,
point
);

this.destroy({ isCanceled: false });
};

setSaving = () => {
Expand All @@ -70,17 +68,17 @@ export default class NewPointPresenter {
});
};

setAborting = () => {
this.#newPointElement.shake(this.#resetFormState);
};
setAborting() {
const resetFormState = () => {
this.#newPointElement.updateElement({
isDisabled: false,
isSaving: false,
isDeleting: false,
});
};

#resetFormState = () => {
this.#newPointElement.updateElement({
isDisabled: false,
isSaving: false,
isDeleting: false,
});
};
this.#newPointElement.shake(resetFormState);
}

#onCloseForm = () => {
this.destroy();
Expand Down
29 changes: 23 additions & 6 deletions src/presenter/point-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PointEditView from '../view/point-edit-view';
import PointView from '../view/point-view';
import {render,replace,remove } from '../framework/render';
import { Mode, EditType } from '../const';
import { isBigDifference } from '../utils/utils.js';
import { isMinorUpdate } from '../utils/common.js';
import {UpdateType, UserAction} from '../const.js';


Expand Down Expand Up @@ -78,7 +78,12 @@ export default class PointPresenter {
this.#replaceToForm();
};

#onCloseEditClick = () => this.#replaceToPoint();
#onCloseEditClick = () => {
if (!this.#editPointElement.isDisabled) {
this.#editPointElement.reset(this.#point);
this.#replaceToPoint();
}
};

#escKeydown = (evt) => {
if (evt.keyCode === 27 || evt.key === 'Escape') {
Expand All @@ -101,7 +106,7 @@ export default class PointPresenter {
};

setSaving = () => {
if(this.#mode === Mode.DEFAULT){
if(this.#mode === Mode.EDITING){
this.#editPointElement.updateElement({
isDisabled: true,
isSaving: true,
Expand All @@ -113,6 +118,9 @@ export default class PointPresenter {
if(this.#mode === Mode.DEFAULT){
this.#editPointElement.shake();
}
else {
this.#editPointElement.shake(this.#resetFormState);
}
};

resetView = () =>{
Expand All @@ -129,6 +137,14 @@ export default class PointPresenter {
});
};

#resetFormState = () => {
this.#editPointElement.updateElement({
isDisabled: false,
isSaving: false,
isDeleting: false
});
};

destroy = () => {
remove(this.#editPointElement);
remove(this.#pointElement);
Expand All @@ -145,14 +161,15 @@ export default class PointPresenter {
};

#formSubmitHandler = (point) => {
const isMinor = isBigDifference(point, this.#point);
const isMinor = isMinorUpdate(point, this.#point);
this.#onPointsChangeHandler(
UserAction.UPDATE_POINT,
isMinor ? UpdateType.MINOR : UpdateType.PATCH,
point
);

this.#replaceToPoint();
if (!this.#editPointElement._state.isDisabled) {
this.#replaceToPoint();
}
};

#onEditPointDelete = (point) =>{
Expand Down
Loading

0 comments on commit 7994fc5

Please sign in to comment.