Skip to content

Commit

Permalink
Merge pull request #16 from PavelUd/master
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored Jun 6, 2024
2 parents 18db009 + 33d878d commit 84a76d5
Show file tree
Hide file tree
Showing 22 changed files with 259 additions and 272 deletions.
11 changes: 10 additions & 1 deletion src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export const DESTINATION_COUNT = 5;

export const POINT_COUNT = 5;

const DEFAULT_TYPE = 'flight';

export const Mode = {
DEFAULT: 'default',
EDITING: 'editing',
Expand Down Expand Up @@ -84,14 +86,21 @@ 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,
dateTo: null,
destination: null,
isFavorite: false,
offers: [],
type: null,
type: DEFAULT_TYPE,
};

const SEC_IN_MIN = 60;
Expand Down
23 changes: 13 additions & 10 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import TripInfoView from './view/trip-info-view.js';
import {render, RenderPosition} from '../src/framework/render.js';
import BoardPresenter from './presenter/board-presenter.js';
import DestinationsModel from './model/destinations-model.js';
import OffersModel from './model/offers-model.js';
import PointsModel from './model/point-model.js';
import TripInfoPresenter from './presenter/trip-info-presenter.js';
import PointsApiService from './service/points-api-service.js';
import FilterModel from './model/filter-model.js';
import FilterPresenter from './presenter/filter-presenter.js';
Expand All @@ -24,7 +23,14 @@ const pointsModel = new PointsModel({service : service, destinationsModel : dest
const filterModel = new FilterModel();

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

const tripInfoPresenter = new TripInfoPresenter({
container: siteMainContainer,
pointsModel,
destinationsModel,
offersModel,
});

const boardPresenter = new BoardPresenter({
Expand All @@ -42,13 +48,10 @@ const filterPresenter = new FilterPresenter({
filterModel,
});


render(new TripInfoView(), siteMainContainer, RenderPosition.AFTERBEGIN);

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
30 changes: 22 additions & 8 deletions src/presenter/board-presenter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import EventListView from '../view/event-list-view';
import EmptyView from '../view/empty-view';
import ErrorView from '../view/error-view.js';
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 All @@ -19,6 +20,7 @@ export default class BoardPresenter {
#emptyListElement = null;
#loadingElement = new LoadingView();
#eventListElement = new EventListView();
#errorElement = new ErrorView();
#pointPresenters = new Map();
#destinationsModel;
#offersModel;
Expand Down Expand Up @@ -68,16 +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 All @@ -96,6 +97,10 @@ export default class BoardPresenter {
render(this.#emptyListElement, this.#container);
};

#renderError = () => {
render(this.#errorElement, this.#container, RenderPosition.AFTERBEGIN);
};

#clearBoard = ({resetSortType = false} = {}) => {
this.#clearTaskList();
remove(this.#emptyListElement);
Expand Down Expand Up @@ -132,7 +137,7 @@ export default class BoardPresenter {
destinationsModel: this.#destinationsModel,
offersModel: this.#offersModel,
onPointsChange: this.#onPointChangeHandler,
handleModeChange: this.#modelEventHandler
handleModeChange: this.#handleModeChange
});
pointPresenter.init(point);
this.#pointPresenters.set(point.id, pointPresenter);
Expand Down Expand Up @@ -174,6 +179,7 @@ export default class BoardPresenter {
#clearTaskList = () => {
this.#pointPresenters.forEach((presenter) => presenter.destroy());
this.#pointPresenters.clear();
this.#newPointPresenter.destroy();
};

#handleSortChange = (sortType) => {
Expand All @@ -189,14 +195,17 @@ export default class BoardPresenter {
this.#isError = true;
} else {
this.#isLoading = false;
this.#isError = false;
remove(this.#loadingElement);
}
this.#renderBoard();
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 All @@ -207,6 +216,11 @@ export default class BoardPresenter {
}
};

#handleModeChange = () => {
this.#pointPresenters.forEach((presenter) => presenter.resetView());
this.#newPointPresenter.destroy();
};

handleNewPointClick = () => {
this.#isCreating = true;
this.#currentSortType = POINT_SORTS.DAY;
Expand Down
3 changes: 1 addition & 2 deletions 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 Expand Up @@ -35,7 +35,6 @@ export default class FilterPresenter {
const prevFilterElement = this.#filterElement;

const filters = this.filters;

this.#filterElement = new FilterView({
items: filters,
onItemChange: this.#onChangeFilter,
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
Loading

0 comments on commit 84a76d5

Please sign in to comment.