Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TeaWithSalt committed Jun 9, 2024
1 parent c825529 commit 1d34d47
Show file tree
Hide file tree
Showing 17 changed files with 252 additions and 292 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/Readme.md

This file was deleted.

36 changes: 11 additions & 25 deletions src/const.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
const API_SRC = 'https://23.objects.htmlacademy.pro/big-trip';
const AUTHORIZATION = 'Basic awdaf5g34123csdrh56w2r51';
export const API_SRC = 'https://23.objects.htmlacademy.pro/big-trip';
export const AUTHORIZATION = 'Basic awdaf5g34123csdrh56w2r51';

const ACTIONS = {
export const ACTIONS = {
UPDATE_POINT: 'update',
ADD_POINT: 'add',
DELETE_POINT: 'delete',
};

const UPDATE_TYPE = {
export const UPDATE_TYPE = {
INIT: 'INIT',
ERROR: 'ERROR',
PATCH: 'PATCH',
MINOR: 'MINOR',
MAJOR: 'MAJOR',
};

const DATE_FORMAT_EDIT = 'd/m/y H:i';
const DATE_FORMAT_DAY = 'MMM DD';
const DATE_FORMAT_HOURS = 'hh:mm';
export const DATE_FORMAT_EDIT = 'd/m/y H:i';
export const DATE_FORMAT_DAY = 'MMM DD';
export const DATE_FORMAT_HOURS = 'hh:mm';

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

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

const TIME_LIMITS = {
export const TIME_LIMITS = {
LOWER_LIMIT: 350,
UPPER_LIMIT: 1000,
};

const EVENTS_MESSAGE = {
export const EVENTS_MESSAGE = {
LOADING: 'Loading...',
ERROR: 'Failed to load latest route information'
};
Expand All @@ -50,17 +50,3 @@ export const FILTER_TYPE_MESSAGE = {
PRESENT: 'There are no present events now',
PAST: 'There are no past events now',
};

export {
API_SRC,
AUTHORIZATION,
DATE_FORMAT_EDIT,
DATE_FORMAT_DAY,
DATE_FORMAT_HOURS,
FILTER_TYPE,
SORTING_TYPES,
ACTIONS,
UPDATE_TYPE,
TIME_LIMITS,
EVENTS_MESSAGE
};
16 changes: 7 additions & 9 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import {render, RenderPosition} from './framework/render.js';
import WaypointsListPresenter from './presenter/waypoints-list-presenter.js';
import WaypointsModel from './model/waypoint-model.js';
import {getMockFilters} from './mock/filter.js';
import {getMockSorts} from './mock/sort.js';
import FilterPresenter from './presenter/filter-presenter';
import FilterModel from './model/filter-model';
import NewPointButtonView from './view/new-point-button-view';
import WaypointsService from './service/waypoints-service';
import {API_SRC, AUTHORIZATION} from './const';
import {getFilters, getSorts} from './utils';

const filters = getFilters();
const sorts = getSorts();

const mainContainer = document.querySelector('.trip-main');
const filterContainer = document.querySelector('.trip-controls__filters');
const eventContainer = document.querySelector('.trip-events');

const mockFilters = getMockFilters();
const mockSorts = getMockSorts();

const waypointsModel = new WaypointsModel({
waypointsService: new WaypointsService(API_SRC, AUTHORIZATION)
});
Expand All @@ -26,7 +25,7 @@ const filterPresenter = new FilterPresenter({
filterContainer,
filterModel,
waypointsModel,
filters: mockFilters
filters
});

const newPointButtonComponent = new NewPointButtonView({
Expand All @@ -42,12 +41,11 @@ const eventPresenter = new WaypointsListPresenter({
eventContainer,
waypointsModel,
filterModel,
sorts: mockSorts,
filters: mockFilters,
sorts,
filters,
onNewPointDestroy: handleNewPointFormClose
});


function handleNewPointButtonClick() {
eventPresenter.createWaypoint();
newPointButtonComponent.element.disabled = true;
Expand Down
8 changes: 0 additions & 8 deletions src/mock/filter.js

This file was deleted.

10 changes: 0 additions & 10 deletions src/mock/sort.js

This file was deleted.

12 changes: 0 additions & 12 deletions src/model/waypoint-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ export default class WaypointsModel extends Observable {
return this.offers;
}

getWaypoint(id) {
return this.waypoints.find((waypoint) => waypoint.id === id);
}

setWaypoints(waypoints) {
this.waypoints = waypoints;
}

setWaypoint(waypoint, id) {
this.waypoints = [...this.waypoints.filter((other) => other.id !== id), waypoint];
}

async init() {
try {
const waypoints = await this.#waypointsService.events;
Expand Down
12 changes: 5 additions & 7 deletions src/presenter/filter-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import FilterView from '../view/filter-view';
import {FILTER_TYPE} from '../const';

export default class FilterPresenter {
#filterContainer;
#filters;
#filterComponent = null;
#waypoints = null;
#filterModel;
#waypointsModel;
#waypoints = null;
#filterContainer;
#filters;

constructor({filterContainer, filterModel, waypointsModel, filters}) {
this.#filterContainer = filterContainer;
Expand All @@ -32,9 +32,7 @@ export default class FilterPresenter {
const prevFilterComponent = this.#filterComponent;

this.#filterComponent = new FilterView({
filters: this.filters,
type: this.#filterModel.filter,
onChange: this.#handleTypeChange
filters: this.filters, type: this.#filterModel.filter, onChange: this.#onChangeType
});

if (prevFilterComponent === null) {
Expand All @@ -48,7 +46,7 @@ export default class FilterPresenter {
render(this.#filterComponent, this.#filterContainer);
}

#handleTypeChange = (type) => {
#onChangeType = (type) => {
if (this.#filterModel.filter === type) {
return;
}
Expand Down
52 changes: 26 additions & 26 deletions src/presenter/new-waypoint-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import EditingFormView from '../view/editing-form-view';
import {isEscape} from '../utils';

export default class NewWaypointPresenter {
#newWaypointComponent = null;
#offers;
#destinations;
#pointListContainer;
#newWaypointComponent = null;
#handleDataChange;
#handleDestroy;
#closeAllEditForms;
Expand All @@ -21,6 +21,23 @@ export default class NewWaypointPresenter {
this.#closeAllEditForms = closeAllEditForms;
}

setSavingStatus() {
this.#newWaypointComponent.updateElement({
isSaving: true,
});
}

setAbortingStatus() {
const resetFormState = () => {
this.#newWaypointComponent.updateElement({
isSaving: false,
isDeleting: false,
});
};

this.#newWaypointComponent.shake(resetFormState);
}

init() {
if (this.#newWaypointComponent !== null) {
return;
Expand All @@ -32,13 +49,13 @@ export default class NewWaypointPresenter {
offers: this.#offers,
destinations: this.#destinations,
waypoint: {type: 'flight', destination: '', basePrice: 0, offers: [], isFavorite: false},
onFormSubmit: (newWaypoint) => this.#handleSaveClick(newWaypoint),
onClose: () => this.#handleCancelClick(),
onDelete: this.#handleCancelClick
onFormSubmit: (newWaypoint) => this.#onSave(newWaypoint),
onClose: () => this.#onCancel(),
onDelete: this.#onCancel
});

render(this.#newWaypointComponent, this.#pointListContainer, RenderPosition.AFTERBEGIN);
document.addEventListener('keydown', this.#escKeyDownHandler);
document.addEventListener('keydown', this.#onEscKeyDown);
}

destroy() {
Expand All @@ -51,38 +68,21 @@ export default class NewWaypointPresenter {
remove(this.#newWaypointComponent);
this.#newWaypointComponent = null;

document.removeEventListener('keydown', this.#escKeyDownHandler);
}

setSavingStatus() {
this.#newWaypointComponent.updateElement({
isSaving: true,
});
}

setAbortingStatus() {
const resetFormState = () => {
this.#newWaypointComponent.updateElement({
isSaving: false,
isDeleting: false,
});
};

this.#newWaypointComponent.shake(resetFormState);
document.removeEventListener('keydown', this.#onEscKeyDown);
}

#handleSaveClick = (waypoint) => {
#onSave = (waypoint) => {
this.#handleDataChange(USER_ACTION.ADD_POINT, UPDATE_TYPE.MAJOR, {
...waypoint,
isFavorite: false
});
};

#handleCancelClick = () => {
#onCancel = () => {
this.destroy();
};

#escKeyDownHandler = (evt) => {
#onEscKeyDown = (evt) => {
if (isEscape(evt.key)) {
evt.preventDefault();
this.destroy();
Expand Down
Loading

0 comments on commit 1d34d47

Please sign in to comment.