Skip to content

Commit

Permalink
Большие перемены (часть 1)2
Browse files Browse the repository at this point in the history
  • Loading branch information
lunianka committed May 27, 2024
1 parent c946d06 commit 24a5fb6
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 314 deletions.
100 changes: 50 additions & 50 deletions src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,79 +18,79 @@ const CITIES = [
];

const OFFERS = [
'Order Uber',
'Add luggage',
'Switch to comfort',
'Rent a car',
'Add breakfast',
'Book tickets',
'Lunch in city',
'Upgrade to a business class'
'Order Uber',
'Add luggage',
'Switch to comfort',
'Rent a car',
'Add breakfast',
'Book tickets',
'Lunch in city',
'Upgrade to a business class'
];

const DESCRIPTION = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras aliquet varius magna, non porta ligula feugiat eget. Fusce tristique felis at fermentum pharetra. Aliquam id orci ut lectus varius viverra.';

const Price = {
MIN: 1,
MAX: 1000
MIN: 1,
MAX: 1000
};

const TYPES = [
'taxi',
'bus',
'train',
'ship',
'drive',
'flight',
'check-in',
'sightseeing',
'restaurant'
'taxi',
'bus',
'train',
'ship',
'drive',
'flight',
'check-in',
'sightseeing',
'restaurant'
];

const DEFAULT_TYPE = 'flight';

const POINT_EMPTY = {
basePrice: 0,
dateFrom: null,
dateTo: null,
destination: null,
isFavorite: false,
offers: [],
type: DEFAULT_TYPE
basePrice: 0,
dateFrom: null,
dateTo: null,
destination: null,
isFavorite: false,
offers: [],
type: DEFAULT_TYPE
};

const FilterType = {
EVERYTHING: 'everything',
FUTURE: 'future',
PRESENT: 'present',
PAST: 'past'
EVERYTHING: 'everything',
FUTURE: 'future',
PRESENT: 'present',
PAST: 'past'
}

Check failure on line 67 in src/const.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

Check failure on line 67 in src/const.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

const Mode = {
DEFAULT: 'default',
EDITING: 'editing',
DEFAULT: 'default',
EDITING: 'editing',
};

const SortType = {
DAY: 'day',
EVENT: 'event',
TIME: 'time',
PRICE: 'price',
OFFERS: 'offers'
DAY: 'day',
EVENT: 'event',
TIME: 'time',
PRICE: 'price',
OFFERS: 'offers'
};

export {
OFFER_COUNT,
DESTINATION_COUNT,
POINT_COUNT,
CITIES,
OFFERS,
DESCRIPTION,
Price,
TYPES,
DEFAULT_TYPE,
POINT_EMPTY,
FilterType,
Mode,
SortType
OFFER_COUNT,
DESTINATION_COUNT,
POINT_COUNT,
CITIES,
OFFERS,
DESCRIPTION,
Price,
TYPES,
DEFAULT_TYPE,
POINT_EMPTY,
FilterType,
Mode,
SortType
}

Check failure on line 96 in src/const.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

Check failure on line 96 in src/const.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
204 changes: 102 additions & 102 deletions src/presenter/point-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,114 +4,114 @@ import { remove, render, replace } from '../framework/render.js';
import { Mode } from '../const.js';

export default class PointPresenter {
#container = null;

#destinationsModel = null;
#offersModel = null;

#handleDataChange = null;
#handleModeChange = null;

#pointComponent = null;
#editPointComponent = null;
#point = null;
#mode = Mode.DEFAULT;

constructor({container, destinationsModel, offersModel, onDataChange, onModeChange}) {
this.#container = container;
this.#destinationsModel = destinationsModel;
this.#offersModel = offersModel;
this.#handleDataChange = onDataChange;
this.#handleModeChange = onModeChange;
#container = null;

#destinationsModel = null;
#offersModel = null;

#handleDataChange = null;
#handleModeChange = null;

#pointComponent = null;
#editPointComponent = null;
#point = null;
#mode = Mode.DEFAULT;

constructor({ container, destinationsModel, offersModel, onDataChange, onModeChange }) {
this.#container = container;
this.#destinationsModel = destinationsModel;
this.#offersModel = offersModel;
this.#handleDataChange = onDataChange;
this.#handleModeChange = onModeChange;
}

init(point) {
this.#point = point;

const prevPointComponent = this.#pointComponent;
const prevEditPointComponent = this.#editPointComponent;

this.#pointComponent = new PointView({
point: this.#point,
pointDestination: this.#destinationsModel.getById(point.destination),
pointOffers: this.#offersModel.getByType(point.type),
onEditClick: this.#pointEditClickHandler,
onFavoriteClick: this.#favoriteClickHandler
});

this.#editPointComponent = new EditPointView({
point: this.#point,
pointDestination: this.#destinationsModel.getById(point.destination),
pointOffers: this.#offersModel.getByType(point.type),
onSubmitClick: this.#formSubmitHandler,
onResetClick: this.#resetButtonClickHandler
})

Check failure on line 48 in src/presenter/point-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

Check failure on line 48 in src/presenter/point-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

if (prevPointComponent === null || prevEditPointComponent === null) {
render(this.#pointComponent, this.#container);
return;
}

init(point) {
this.#point = point;

const prevPointComponent = this.#pointComponent;
const prevEditPointComponent = this.#editPointComponent;

this.#pointComponent = new PointView({
point: this.#point,
pointDestination: this.#destinationsModel.getById(point.destination),
pointOffers: this.#offersModel.getByType(point.type),
onEditClick: this.#pointEditClickHandler,
onFavoriteClick: this.#favoriteClickHandler
});

this.#editPointComponent = new EditPointView({
point: this.#point,
pointDestination: this.#destinationsModel.getById(point.destination),
pointOffers: this.#offersModel.getByType(point.type),
onSubmitClick: this.#formSubmitHandler,
onResetClick: this.#resetButtonClickHandler
})

if (prevPointComponent === null || prevEditPointComponent === null) {
render(this.#pointComponent, this.#container);
return;
}

if (this.#mode === Mode.DEFAULT) {
replace(this.#pointComponent, prevPointComponent);
}

if (this.#mode === Mode.EDITING) {
replace(this.#pointComponent, prevEditPointComponent);
}

remove(prevPointComponent);
remove(prevEditPointComponent);
if (this.#mode === Mode.DEFAULT) {
replace(this.#pointComponent, prevPointComponent);
}

resetView = () => {
if (this.#mode !== Mode.DEFAULT) {
this.#replaceFormToPoint();
}
};

destroy = () => {
remove(this.#pointComponent);
remove(this.#editPointComponent);
if (this.#mode === Mode.EDITING) {
replace(this.#pointComponent, prevEditPointComponent);
}

#replacePointToForm = () => {
replace(this.#editPointComponent, this.#pointComponent);
document.addEventListener('keydown', this.#escKeyDownHandler);
this.#handleModeChange();
this.#mode = Mode.EDITING;
};

#replaceFormToPoint = () => {
replace(this.#pointComponent, this.#editPointComponent);
document.removeEventListener('keydown', this.#escKeyDownHandler);
this.#mode = Mode.DEFAULT;
};

#escKeyDownHandler = (evt) => {
if (evt.key === 'Escape') {
evt.preventDefault();
this.#replaceFormToPoint();
}
};

#pointEditClickHandler = () => {
this.#replacePointToForm();
};

#favoriteClickHandler = () => {
this.#handleDataChange({
...this.#point,
isFavorite: !this.#point.isFavorite
});
};

#formSubmitHandler = (point) => {
this.#handleDataChange(point);
this.#replaceFormToPoint();
}
remove(prevPointComponent);
remove(prevEditPointComponent);
}

#resetButtonClickHandler = () => {
this.#replaceFormToPoint();
resetView = () => {
if (this.#mode !== Mode.DEFAULT) {
this.#replaceFormToPoint();
}
};

destroy = () => {
remove(this.#pointComponent);
remove(this.#editPointComponent);
}

Check failure on line 76 in src/presenter/point-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

Check failure on line 76 in src/presenter/point-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

#replacePointToForm = () => {
replace(this.#editPointComponent, this.#pointComponent);
document.addEventListener('keydown', this.#escKeyDownHandler);
this.#handleModeChange();
this.#mode = Mode.EDITING;
};

#replaceFormToPoint = () => {
replace(this.#pointComponent, this.#editPointComponent);
document.removeEventListener('keydown', this.#escKeyDownHandler);
this.#mode = Mode.DEFAULT;
};

#escKeyDownHandler = (evt) => {
if (evt.key === 'Escape') {
evt.preventDefault();
this.#replaceFormToPoint();
}
};

#pointEditClickHandler = () => {
this.#replacePointToForm();
};

#favoriteClickHandler = () => {
this.#handleDataChange({
...this.#point,
isFavorite: !this.#point.isFavorite
});
};

#formSubmitHandler = (point) => {
this.#handleDataChange(point);
this.#replaceFormToPoint();
}

Check failure on line 112 in src/presenter/point-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

Check failure on line 112 in src/presenter/point-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

#resetButtonClickHandler = () => {
this.#replaceFormToPoint();
}

Check failure on line 116 in src/presenter/point-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

Check failure on line 116 in src/presenter/point-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
}
Loading

0 comments on commit 24a5fb6

Please sign in to comment.