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

Дополнительная функциональность #14

Merged
merged 1 commit into from
Oct 16, 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
6 changes: 3 additions & 3 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export const UpdateType = {
export const DEFAULT_POINT = {
id: 0,
basePrice: 0,
dateFrom: new Date().toISOString(),
dateTo: new Date().toISOString(),
dateFrom: '',
dateTo: '',
destination: 0,
isFavorite: false,
offers: [],
Expand All @@ -110,7 +110,7 @@ export const Method = {

export const END_POINT = 'https://24.objects.htmlacademy.pro/big-trip';

export const Authorization = 'Basic FE49wwUYuvTvhn9vBjwv4';
export const AUTHORIZATION = 'Basic FE49wwUYuvTvhn9vBjwv4';

export const LIMIT_DISPLAYED_DESTINATIONS = 3;

Expand Down
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import PointModel from './model/point-model.js';
import FilterModel from './model/filter-model.js';
import FilterPresenter from './presenter/filter-presenter.js';
import PointsApiService from './server/points-api-service.js';
import { END_POINT, Authorization } from './constants.js';
import { END_POINT, AUTHORIZATION } from './constants.js';
import TripInfoPresenter from './presenter/trip-info-presenter';

const tripMainElement = document.querySelector('.trip-main');
const tripEventsElement = document.querySelector('.trip-events');
const filtersElement = document.querySelector('.trip-controls__filters');

const pointsApiService = new PointsApiService(END_POINT, Authorization);
const pointsApiService = new PointsApiService(END_POINT, AUTHORIZATION);
const pointModel = new PointModel({ pointsApiService });
const filterModel = new FilterModel();

Expand Down
2 changes: 1 addition & 1 deletion src/model/point-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class PointModel extends Observable {
async updatePoint(updateType, point) {
const updatedPoint = await this.#pointsApiService.updatePoint(point);
this.#points = updateItem(this.#points, updatedPoint);
this._notify(updateType, updatedPoint.id);
this._notify(updateType, updatedPoint);
}

async addPoint(updateType, point) {
Expand Down
2 changes: 1 addition & 1 deletion src/presenter/main-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export default class MainPresenter {
try {
await this.#pointModel.addPoint(updateType, point);
} catch (err) {
this.#pointPresenters.setAborting();
this.#newPointPresenter.setAborting();
}
break;
case UserAction.DELETE_POINT:
Expand Down
4 changes: 2 additions & 2 deletions src/presenter/new-point-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class NewPointPresenter {
destinations: this.#pointModel.destinations,
onEditClick: this.#handleCloseClick,
onFormSubmit: this.#handleFormSubmit,
onDeleteClick: this.#handleCancelClick
onFormReset: this.#handleFormReset
});

render(this.#eventEditorComponent, this.#listComponent, RenderPosition.AFTERBEGIN);
Expand Down Expand Up @@ -75,7 +75,7 @@ export default class NewPointPresenter {
this.destroy();
};

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

Expand Down
6 changes: 3 additions & 3 deletions src/presenter/point-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class PointPresenter {
#eventComponent = null;
#eventEditorComponent = null;

#point = [];
#point = null;
#offers = [];
#destinations = [];

Expand Down Expand Up @@ -46,7 +46,7 @@ export default class PointPresenter {
destinations: this.#destinations,
onEditClick: this.#handleCloseClick,
onFormSubmit: this.#handleFormSubmit,
onDeleteClick: this.#handleDeleteClick
onFormReset: this.#handleFormReset
});

if (prevEventComponent === null || prevEventEditorComponent === null) {
Expand Down Expand Up @@ -160,7 +160,7 @@ export default class PointPresenter {
);
};

#handleDeleteClick = (point) => {
#handleFormReset = (point) => {
this.#handleDataChange(
UserAction.DELETE_POINT,
UpdateType.MINOR,
Expand Down
2 changes: 0 additions & 2 deletions src/utils/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { DateFormat } from '../constants.js';

export const getRandomInteger = (min = 1, max = 100) => Math.round(Math.random() * Math.abs(max - min)) + min;

export const getRandomArrayElement = (array) => array[getRandomInteger(0, array.length - 1)];

dayjs.extend(duration);
dayjs.extend(minMax);

Expand Down
32 changes: 16 additions & 16 deletions src/view/event-editor-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ const createEventEditorTemplate = (point, offers, destinations)=> {
<button
class="event__save-btn btn btn--blue"
type="submit"
${isDisabled ? 'disabled' : ''}>${isSaving ? 'Ssving...' : 'Save'}</button>
${isSaving ? 'disabled' : ''}>${isSaving ? 'Saving...' : 'Save'}</button>

<button
class="event__reset-btn"
type="reset" ${isDisabled ? 'disabled' : ''}>${setButtonValue()}</button>
type="reset">${setButtonValue()}</button>

${createRollupButtonTemplate(point.id)}
</header>
Expand All @@ -226,20 +226,20 @@ export default class EventEditorView extends AbstractStatefulView {

#handleFormSubmit = null;
#handleEditClick = null;
#handleDeleteClick = null;
#handleFormReset = null;

#dateFromPicker = null;
#dateToPicker = null;

constructor({ point, offers, destinations, onEditClick, onFormSubmit, onDeleteClick }) {
constructor({ point, offers, destinations, onEditClick, onFormSubmit, onFormReset }) {
super();
this._setState(EventEditorView.parsePointToState(point));
this.#offers = offers;
this.#destinations = destinations;

this.#handleEditClick = onEditClick;
this.#handleFormSubmit = onFormSubmit;
this.#handleDeleteClick = onDeleteClick;
this.#handleFormReset = onFormReset;

this._restoreHandlers();
}
Expand Down Expand Up @@ -274,11 +274,11 @@ export default class EventEditorView extends AbstractStatefulView {
_restoreHandlers() {
this.element.querySelector('.event__rollup-btn')?.addEventListener('click', this.#editClickHandler);
this.element.querySelector('form').addEventListener('submit', this.#formSubmitHandler);
this.element.querySelector('form').addEventListener('reset', this.#formDeleteClickHandler);
this.element.querySelector('.event__type-group').addEventListener('change', this.#changeTypeHandler);
this.element.querySelector('.event__input--destination').addEventListener('change', this.#changeDestinationHandler);
this.element.querySelector('.event__available-offers')?.addEventListener('change', this.#changeAvailableOffersHandler);
this.element.querySelector('.event__field-group--price').addEventListener('input', this.#changePriceHandler);
this.element.querySelector('form').addEventListener('reset', this.#formResetHandler);
this.element.querySelector('.event__type-group').addEventListener('change', this.#typeChangeHandler);
this.element.querySelector('.event__input--destination').addEventListener('change', this.#destinationChangeHandler);
this.element.querySelector('.event__available-offers')?.addEventListener('change', this.#availableOffersChangeHandler);
this.element.querySelector('.event__field-group--price').addEventListener('input', this.#priceInputHandler);

this.#setDatePicker();
}
Expand All @@ -303,13 +303,13 @@ export default class EventEditorView extends AbstractStatefulView {

#editClickHandler = () => this.#handleEditClick();

#changeTypeHandler = (event) => {
#typeChangeHandler = (event) => {
this.updateElement({
type: event.target.value
});
};

#changeDestinationHandler = (event) => {
#destinationChangeHandler = (event) => {
const newDestination = this.#destinations.find((destination) => destination.name === event.target.value);

if (newDestination) {
Expand All @@ -321,15 +321,15 @@ export default class EventEditorView extends AbstractStatefulView {
event.target.value = '';
};

#changeAvailableOffersHandler = () => {
#availableOffersChangeHandler = () => {
const selectedOffers = this.element.querySelectorAll('.event__offer-checkbox:checked');

this._setState({
offers: Array.from(selectedOffers).map((item) => item.dataset.offerId)
});
};

#changePriceHandler = (event) => {
#priceInputHandler = (event) => {
this._setState({
basePrice: parseInt(event.target.value, 10)
});
Expand Down Expand Up @@ -366,8 +366,8 @@ export default class EventEditorView extends AbstractStatefulView {
});
};

#formDeleteClickHandler = (event) => {
#formResetHandler = (event) => {
event.preventDefault();
this.#handleDeleteClick(EventEditorView.parseStateToPoint(this._state));
this.#handleFormReset(EventEditorView.parseStateToPoint(this._state));
};
}
2 changes: 1 addition & 1 deletion src/view/events-item-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const createEventItemTemplate = (point, offers, destinations) => {
};

export default class EventsItemView extends AbstractView {
#point = [];
#point = null;
#destinations = [];
#offers = [];

Expand Down
Loading