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

Исправляет замечания наставника #17

Merged
merged 3 commits into from
Oct 23, 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
16 changes: 15 additions & 1 deletion src/const/const.js → src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,26 @@ const UpdateType = {

const DisabledSortType = [SortType.EVENT, SortType.OFFERS];

const AUTHORIZATION = 'Basic Student-24th-AcademicStream-323345-llSergey';
const END_POINT = 'https://24.objects.htmlacademy.pro/big-trip';

const MAX_DESTINATION_NAME_IN_TITLE = 3;

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

export {
EVENT_TYPES,
EMPTY_POINT,
FilterType,
SortType,
UserAction,
UpdateType,
DisabledSortType
DisabledSortType,
AUTHORIZATION,
END_POINT,
MAX_DESTINATION_NAME_IN_TITLE,
Mode,
};
8 changes: 0 additions & 8 deletions src/const/api-const.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/const/change-mode-const.js

This file was deleted.

6 changes: 0 additions & 6 deletions src/const/header-const.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import FiltersModel from './model/filters-model.js';
import PointsApiService from './api-service/points-api-service.js';
import OffersApiService from './api-service/offers-api-service.js';
import DestinationsApiService from './api-service/destinations-api-service.js';
import { AUTHORIZATION, END_POINT } from './const/api-const.js';
import { AUTHORIZATION, END_POINT } from './const.js';

import ButtonAddNewEventView from './view/button-add-new-event-view.js';
import FailedLoadView from './view/failed-load-view.js';
Expand Down
2 changes: 1 addition & 1 deletion src/model/destinations-trip-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class DestinationsTripModel {
}

getDestinationById(points) {
return this.#destinations.find((dest) => dest.id === points);
return this.#destinations.find((destination) => destination.id === points);
}

getDestinationByName(destinationName) {
Expand Down
2 changes: 1 addition & 1 deletion src/model/filters-model.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Observable from '../framework/observable.js';
import { FilterType } from '../const/const.js';
import { FilterType } from '../const.js';

export default class FiltersModel extends Observable {
#filter = FilterType.EVERYTHING;
Expand Down
2 changes: 1 addition & 1 deletion src/model/points-trip-model.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UpdateType } from '../const/const.js';
import { UpdateType } from '../const.js';
import Observable from '../framework/observable.js';
import { getUtcTimeFromLocal } from '../utils/time.js';
export default class PointsTripModel extends Observable {
Expand Down
6 changes: 1 addition & 5 deletions src/presenter/filters-presenter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, replace, remove } from '../framework/render.js';
import FiltersEventsView from '../view/filters-events-view.js';
import { FilterType, UpdateType } from '../const/const.js';
import {FilterType, UpdateType} from '../const.js';
import { filter } from '../utils/filter.js';


Expand All @@ -26,22 +26,18 @@ export default class FiltersPresenter {
return [
{
type: FilterType.EVERYTHING,
name: 'EVERYTHING',
count: filter[FilterType.EVERYTHING](points).length,
},
{
type: FilterType.FUTURE,
name: 'FUTURE',
count: filter[FilterType.FUTURE](points).length,
},
{
type: FilterType.PRESENT,
name: 'PRESENT',
count: filter[FilterType.PRESENT](points).length,
},
{
type: FilterType.PAST,
name: 'PAST',
count: filter[FilterType.PAST](points).length,
},
];
Expand Down
5 changes: 2 additions & 3 deletions src/presenter/header-presenter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, remove, replace, RenderPosition } from '../framework/render.js';
import { humanizeEventDate } from '../utils/time.js';
import { MAX_DESTINATION_NAME_IN_TITLE } from '../const/header-const.js';
import { MAX_DESTINATION_NAME_IN_TITLE } from '../const.js';

import HeaderTripInfoView from '../view/header-trip-info-view.js';

Expand Down Expand Up @@ -50,8 +50,6 @@ export default class HeaderPresenter {
}
}


/** Создание шапки сайта */
#renderTripHeader() {
const prevHeaderTripComponent = this.#headerTripComponent;

Expand Down Expand Up @@ -98,6 +96,7 @@ export default class HeaderPresenter {
eventDateStart = this.#pointsTrip.at(0).date_from;
eventDateEnd = this.#pointsTrip.at(-1).date_to;
}

const date = {
eventDateStart: humanizeEventDate(eventDateStart, 'headerDate'),
eventDateEnd: humanizeEventDate(eventDateEnd, 'headerDate')
Expand Down
30 changes: 6 additions & 24 deletions src/presenter/list-presenter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, remove, RenderPosition } from '../framework/render.js';
import { SortType, FilterType, UpdateType, UserAction } from '../const/const.js';
import { SortType, FilterType, UpdateType, UserAction } from '../const.js';
import { sortEventsByDay, sortEventsByTime, sortEventsByPrice } from '../utils/sort.js';
import { filter } from '../utils/filter.js';

Expand Down Expand Up @@ -65,7 +65,7 @@ export default class ListPresenter {
onDestroy: onNewTripPointClose,
});

/** Подписываемся на изменение данных модели и прокидываем callback */

this.#pointsTripModel.addObserver(this.#handleModelEvent);
this.#filtersModel.addObserver(this.#handleModelEvent);
}
Expand All @@ -81,12 +81,11 @@ export default class ListPresenter {
case SortType.PRICE:
return filteredTripPoints.sort(sortEventsByPrice);
}

return filteredTripPoints;
}

init(failedLoadViewComonent) {
/** Отрисовка всех компонентов путешествия */

render(this.#listComponent, this.#listContainer);
this.#renderList(failedLoadViewComonent);
}
Expand All @@ -112,26 +111,23 @@ export default class ListPresenter {

if (this.#isLoading) {
this.#renderMessageLoadingComponent();

if (failedLoadViewComonent) {
remove(this.#tripLoadingComponent);
}

return;
}

if (this.#pointsTripModel.points.length === 0) {
/** Если список событий пуст, то отрисовываем сообщение */
this.#renderNoTripEventsComponent();
return;
}

this.#renderSort();
/** Рендерим список событий */
this.#renderAllTripEvents();

}


/** Обновление компонента с событиями путешествия */
#handleModeChange = () => {
this.#newTripPointPresenter.destroy();
this.#tripPointsPresentersId.forEach((presenter) => presenter.resetView());
Expand All @@ -150,7 +146,6 @@ export default class ListPresenter {

switch (actionType) {
case UserAction.UPDATE_POINT:

this.#tripPointsPresentersId.get(update.id).setSaving();
try {
await this.#pointsTripModel.updatePoint(updateType, update);
Expand All @@ -160,7 +155,6 @@ export default class ListPresenter {
break;

case UserAction.ADD_POINT:

this.#newTripPointPresenter.setSaving();
try {
await this.#pointsTripModel.addPoint(updateType, update);
Expand All @@ -170,7 +164,6 @@ export default class ListPresenter {
break;

case UserAction.DELETE_POINT:

this.#tripPointsPresentersId.get(update.id).setDeleting();
try {
await this.#pointsTripModel.deletePoint(updateType, update);
Expand Down Expand Up @@ -210,31 +203,24 @@ export default class ListPresenter {
}
};

/** Отрисовка кнопок cортировки событий путешествия */
#renderSort() {
this.#sortComponent = new SortEventsView({
onSortTypeChange: this.#handleSortTypeChange,
currentSortType: this.#currentSortType,
});

render(this.#sortComponent, this.#listContainer, RenderPosition.AFTERBEGIN);
}

/** Перерисовывает события согласно типу сортировки
* @param {string} sortType - тип сортировки
* @run Отрисовку всех событий путешествия согласно типу сортировки
*/
#handleSortTypeChange = (sortType) => {
if (this.#currentSortType === sortType) {
return;
}

this.#currentSortType = sortType;
this.#clearTripPointList();
this.#renderList();
};


/** Создание события путешествия - презентер */
#renderTripPoint(tripPoint) {
if (this.#noTripEventsComponent) {
remove(this.#noTripEventsComponent);
Expand All @@ -249,7 +235,6 @@ export default class ListPresenter {
});

tripPointsPresenter.init(tripPoint);

this.#tripPointsPresentersId.set(tripPoint.id, tripPointsPresenter);
}

Expand All @@ -264,14 +249,11 @@ export default class ListPresenter {
render(this.#noTripEventsComponent, this.#listComponent.element);
}


/** Создание списка событий путешествия */
#renderAllTripEvents() {
this.#renderNoTripEventsComponent();
this.tripPoints.forEach((tripPoint) => this.#renderTripPoint(tripPoint));
}

/** Очистка компонента с событиями путешествия */
#clearTripPointList({ resetSortType = false } = {}) {

this.#newTripPointPresenter.destroy();
Expand Down
5 changes: 1 addition & 4 deletions src/presenter/new-trip-points-presenter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, remove, RenderPosition } from '../framework/render.js';
import { UserAction, UpdateType, EMPTY_POINT } from '../const/const.js';
import { UserAction, UpdateType, EMPTY_POINT } from '../const.js';
import EditItemListEventsView from '../view/edit-item-list-events-view.js';


Expand Down Expand Up @@ -42,7 +42,6 @@ export default class NewTripPointPresenter {
onCloseFormClick: this.#handleFormCloseClick,
isNewPoint: true,
});

render(this.#tripPointEditComponent, this.#pointComponentContainer, RenderPosition.AFTERBEGIN);

document.addEventListener('keydown', this.#escKeyDownHandler);
Expand Down Expand Up @@ -76,12 +75,10 @@ export default class NewTripPointPresenter {
isDeleting: false,
});
};

this.#tripPointEditComponent.shake(resetFormState);
}

#handleFormSubmit = (tripPoint) => {

this.#handleDataChange(
UserAction.ADD_POINT,
UpdateType.MINOR,
Expand Down
26 changes: 3 additions & 23 deletions src/presenter/trip-points-presenter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, replace, remove } from '../framework/render.js';
import { UserAction, UpdateType } from '../const/const.js';
import { Mode } from '../const/change-mode-const.js';
import { UserAction, UpdateType } from '../const.js';
import { Mode } from '../const.js';

import ItemListEventsView from '../view/item-list-events-view.js';
import EditItemListEventsView from '../view/edit-item-list-events-view.js';
Expand Down Expand Up @@ -35,12 +35,12 @@ export default class TripPointsPresenter {
if (this.#offersModel.offers.length === 0) {
await this.#offersModel.init();
}

if (this.#destinationsModel.destinations.length === 0) {
await this.#destinationsModel.init();
}

this.#tripPoint = tripPoint;

this.#createTripPointComponent(tripPoint);
}

Expand All @@ -56,7 +56,6 @@ export default class TripPointsPresenter {
onFavoriteClick: this.#handleFavoriteClick,
});

/** Инициализируем компонент для редактирования события */
this.#createTripPointEditComponent(tripPoint);

if (prevTripPointComponent === null || prevTripPointEditComponent === null) {
Expand All @@ -76,9 +75,6 @@ export default class TripPointsPresenter {
remove(prevTripPointEditComponent);
}

/**
* Создает компонент для редактирования события
*/
#createTripPointEditComponent(tripPoint) {
this.#tripPointEditComponent = new EditItemListEventsView({
tripPoint,
Expand All @@ -97,9 +93,6 @@ export default class TripPointsPresenter {
remove(this.#tripPointEditComponent);
}

/**
* Метод для сброса компонента в начальное состояние
*/
resetView() {
if (this.#mode !== Mode.DEFAULT) {
this.#tripPointEditComponent.reset(this.#tripPoint);
Expand Down Expand Up @@ -142,10 +135,6 @@ export default class TripPointsPresenter {
this.#tripPointEditComponent.shake(resetFormState);
}

/**
* Регулирует поведение при нажатии на кнопку Esc
* @param {evt} event событие на кнопку Esc
*/
#escKeyDownHandler = (evt) => {
if (evt.key === 'Escape') {
evt.preventDefault();
Expand All @@ -154,11 +143,6 @@ export default class TripPointsPresenter {
}
};

/**
* Метод для редактирования события
* Записывает стейт редактируемого компонента
* в начальные данные (сохраняет изменения)
*/
#replaceCardToForm() {
replace(this.#tripPointEditComponent, this.#tripPointComponent);
this.#tripPointEditComponent.reset(this.#tripPoint);
Expand All @@ -168,10 +152,6 @@ export default class TripPointsPresenter {
this.#mode = Mode.EDITING;
}

/**
* Метод для редактирования события
* Сбрасывает стейт редактируемого компонента
*/
#replaceFormToCard() {
replace(this.#tripPointComponent, this.#tripPointEditComponent);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/filter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FilterType } from '../const/const.js';
import { FilterType } from '../const.js';

const filter = {
[FilterType.EVERYTHING]: (pointsTrip) => pointsTrip,
Expand Down
Loading
Loading