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

Changes after autotest check #15

Merged
merged 12 commits into from
Oct 21, 2024
14 changes: 10 additions & 4 deletions src/const.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const TYPES = ['taxi', 'bus', 'train', 'ship', 'drive', 'flight', 'check-in', 'sightseeing', 'restaurant'];

const DATE_FORMAT = 'D MMM';
const DATE_FORMAT = 'MMM D';
const TRIP_INFO_DATE_FORMAT = 'D MMM';
const TIME_FORMAT = 'HH:mm';
const DATE_WITH_TIME_FORMAT = 'DD/MM/YY HH:mm';

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

const SortType = {
Expand All @@ -34,9 +35,9 @@ const UpdateType = {

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

const BLANK_POINT = {
Expand Down Expand Up @@ -67,4 +68,9 @@ const TimeLimit = {
UPPER_LIMIT: 1000,
};

export { TYPES, DATE_FORMAT, TIME_FORMAT, DATE_WITH_TIME_FORMAT, FilterType, SortType, UserAction, UpdateType, ListEmptyText, BLANK_POINT, Method, URL, TimeLimit };
const Mode = {
DEFAULT: 'DEFAULT',
EDIT: 'EDIT'
};

export { TYPES, DATE_FORMAT, TRIP_INFO_DATE_FORMAT, TIME_FORMAT, DATE_WITH_TIME_FORMAT, FilterType, SortType, UserAction, UpdateType, ListEmptyText, BLANK_POINT, Method, URL, TimeLimit, Mode };
29 changes: 6 additions & 23 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { render } from './framework/render';
import MainPresenter from './presenter/main-presenter';
import PointModel from './model/point-model';
import FiltersModel from './model/filters-model';
import FiltersPresenter from './presenter/filters-presenter';
import AddNewPointButtonView from './view/add-new-point-button-view';
import PointsApiService from './points-api-service';
import TripInfoPresenter from './presenter/trip-info-presenter';

const AUTHORIZATION = 'Basic fjr3598kro54883dl';
const AUTHORIZATION = 'Basic fjr3598kro5483dl';
const END_POINT = 'https://24.objects.htmlacademy.pro/big-trip';

const mainContainer = document.querySelector('.trip-main');
Expand All @@ -16,20 +14,15 @@ const pointsContainer = document.querySelector('.trip-events');

const pointModel = new PointModel({
pointsApiService: new PointsApiService(END_POINT, AUTHORIZATION),
pointsContainer: pointsContainer,
});

const filtersModel = new FiltersModel();

const addNewPointButton = new AddNewPointButtonView({
onClick: onNewPointButtonClick,
});

const mainPresenter = new MainPresenter({
pointsContainer: pointsContainer,
pointsContainer,
mainContainer,
pointModel,
filtersModel,
onNewPointCancel: cancelNewPoint,
});

const filtersPresenter = new FiltersPresenter({
Expand All @@ -39,26 +32,16 @@ const filtersPresenter = new FiltersPresenter({
});

const tripInfoPresenter = new TripInfoPresenter({
pointModel: pointModel,
mainContainer: mainContainer,
pointModel,
mainContainer,
});

function onNewPointButtonClick() {
mainPresenter.createPoint();
addNewPointButton.element.disabled = true;
}

function cancelNewPoint() {
addNewPointButton.element.disabled = false;
}

mainPresenter.init();

pointModel.init()
.finally(() => {
render(addNewPointButton, mainContainer);
tripInfoPresenter.init();
filtersPresenter.init();
tripInfoPresenter.init();
});


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

This file was deleted.

35 changes: 16 additions & 19 deletions src/model/point-model.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import Observable from '../framework/observable';
import { UpdateType } from '../const';
import FailedToLoadView from '../view/failed-to-load-view';
import { render } from '../framework/render';

export default class PointModel extends Observable {
#points = [];
#allDestinations = [];
#allOffers = [];
#pointsApiService = null;
#failedToLoadComponent = new FailedToLoadView();
#pointsContainer = null;
#isFailedToLoadPoints = false;

constructor({ pointsApiService, pointsContainer }) {
constructor({ pointsApiService }) {
super();
this.#pointsApiService = pointsApiService;
this.#pointsContainer = pointsContainer;
}

get points() {
Expand All @@ -29,6 +25,10 @@ export default class PointModel extends Observable {
return this.#allOffers;
}

get failedToLoadPoints() {
return this.#isFailedToLoadPoints;
}

#adaptToClient(point) {
const adaptedPoint = {
...point,
Expand All @@ -50,12 +50,13 @@ export default class PointModel extends Observable {
try {
const points = await this.#pointsApiService.points;
this.#points = points.map(this.#adaptToClient);

this.#allDestinations = await this.#pointsApiService.allDestinations;

this.#allOffers = await this.#pointsApiService.allOffers;
} catch (err) {
render(this.#failedToLoadComponent, this.#pointsContainer);
this.#points = [];
this.#allOffers = [];
this.#allDestinations = [];
this.#isFailedToLoadPoints = true;
}

this._notify(UpdateType.INIT);
Expand All @@ -69,8 +70,8 @@ export default class PointModel extends Observable {
}

try {
const responce = await this.#pointsApiService.updatePoint(update);
const updatedPoint = this.#adaptToClient(responce);
const response = await this.#pointsApiService.updatePoint(update);
const updatedPoint = this.#adaptToClient(response);

this.#points = [
...this.#points.slice(0, pointIndex),
Expand All @@ -86,8 +87,8 @@ export default class PointModel extends Observable {

async addPoint(updateType, update) {
try {
const responce = await this.#pointsApiService.addPoint(update);
const addedPoint = this.#adaptToClient(responce);
const response = await this.#pointsApiService.addPoint(update);
const addedPoint = this.#adaptToClient(response);
this.#points = [addedPoint, ...this.#points];

this._notify(updateType, addedPoint);
Expand All @@ -97,14 +98,10 @@ export default class PointModel extends Observable {
}

async deletePoint(updateType, update) {
const pointIndex = this.#points.findIndex((point) => point.id === update.id);

try {
await this.#pointsApiService.deletePoint(update);
this.#points = [
...this.#points.slice(0, pointIndex),
...this.#points.slice(pointIndex + 1),
];

this.#points = this.#points.filter((point) => point.id !== update.id);

this._notify(updateType);
} catch (err) {
Expand Down
5 changes: 3 additions & 2 deletions src/presenter/filters-presenter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, replace, remove } from '../framework/render';
import FiltersView from '../view/filters-view';
import { render, replace, remove } from '../framework/render';
import { UpdateType } from '../const';
import { filter } from '../utils/filter-utils';

Expand Down Expand Up @@ -34,7 +34,8 @@ export default class FiltersPresenter {

this.#filtersComponent = new FiltersView({
filters: this.filters,
onFiltersChange: this.#handleFiltersChange
onFiltersChange: this.#handleFiltersChange,
currentFilter: this.#filtersModel.filter,
});

if(prevFiltersComponent === null){
Expand Down
Loading
Loading