Skip to content

Commit

Permalink
Merge pull request #20 from egorarud/master
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored Jun 16, 2024
2 parents 5dd5c3b + bc090db commit 317dacb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
16 changes: 13 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ const newPointButtonComponent = new NewPointButtonView({
onClick: handleNewPointButtonClick
});

async function initPointsData() {
await Promise.all([
destinationsModel.init(),
offersModel.init(),
]);
}

async function initModels() {
await initPointsData();
pointsModel.init();
}

function handleNewPointFormClose() {
newPointButtonComponent.element.disabled = false;
}
Expand All @@ -60,8 +72,6 @@ function handleNewPointButtonClick() {

render(newPointButtonComponent, mainContainer);

destinationsModel.init();
offersModel.init();
pointsModel.init();
initModels();
filterPresenter.init();
tripEventsPresenter.init();
16 changes: 8 additions & 8 deletions src/presenter/trip-point-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isEscapeKey } from '../util.js';
import { UserAction, UpdateType } from '../const.js';


const VIEW = {
const View = {
DEFAULT: 'DEFAULT',
EDIT: 'EDIT'
};
Expand All @@ -25,7 +25,7 @@ export default class TripPointPresenter {
#offer = null;
#destination = null;

#view = VIEW.DEFAULT;
#view = View.DEFAULT;

constructor(pointContainer, onViewChange, onDataChange, offersModel, destinationsModel) {
this.#pointContainer = pointContainer;
Expand Down Expand Up @@ -71,7 +71,7 @@ export default class TripPointPresenter {
}

resetView() {
if (this.#view === VIEW.EDIT){
if (this.#view === View.EDIT){
this.#editPointComponent.reset(this.#point, this.#destination, this.#offer);
this.#replaceFormToPoint();
}
Expand All @@ -83,7 +83,7 @@ export default class TripPointPresenter {
}

setSaving() {
if (this.#view === VIEW.EDIT) {
if (this.#view === View.EDIT) {
this.#editPointComponent.updateElement({
isDisabled: true,
isSaving: true,
Expand All @@ -92,7 +92,7 @@ export default class TripPointPresenter {
}

setDeleting() {
if (this.#view === VIEW.EDIT) {
if (this.#view === View.EDIT) {
this.#editPointComponent.updateElement({
isDisabled: true,
isDeleting: true,
Expand All @@ -101,7 +101,7 @@ export default class TripPointPresenter {
}

setAborting() {
if (this.#view === VIEW.DEFAULT) {
if (this.#view === View.DEFAULT) {
this.#pointComponent.shake();
return;
}
Expand All @@ -120,12 +120,12 @@ export default class TripPointPresenter {
#replacePointToForm() {
this.#onViewChange();
replace(this.#editPointComponent, this.#pointComponent);
this.#view = VIEW.EDIT;
this.#view = View.EDIT;
}

#replaceFormToPoint() {
replace(this.#pointComponent, this.#editPointComponent);
this.#view = VIEW.DEFAULT;
this.#view = View.DEFAULT;
}

#pointRollupButtonClikHandler = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/view/editable-point-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function createEditablePointTemplate(state, isNew, CITIES) {
<label class="event__label event__type-output" for="event-destination-1">
${type[0].toUpperCase() + type.slice(1)}
</label>
<input class="event__input event__input--destination" id="event-destination-1" type="text" name="event-destination" ${state.name === undefined ? '' : `value="${state.name}"`} list="destination-list-1" autocomplete="off" ${isDisabled ? 'disabled' : ''}>
<input class="event__input event__input--destination" id="event-destination-1" type="text" required name="event-destination" ${state.name === undefined ? '' : `value="${state.name}"`} list="destination-list-1" autocomplete="off" ${isDisabled ? 'disabled' : ''}>
<datalist id="destination-list-1">
${createDestinationsList(CITIES)}
</datalist>
Expand All @@ -61,7 +61,7 @@ function createEditablePointTemplate(state, isNew, CITIES) {
<span class="visually-hidden">Price</span>
&euro;
</label>
<input class="event__input event__input--price" id="event-price-1" type="number" name="event-price" value="${state.basePrice}" ${isDisabled ? 'disabled' : ''}>
<input class="event__input event__input--price" id="event-price-1" type="number" min="1" name="event-price" value="${state.basePrice}" ${isDisabled ? 'disabled' : ''}>
</div>
<button class="event__save-btn btn btn--blue" type="submit" ${isDisabled ? 'disabled' : ''}>${state.isSaving ? 'Saving...' : 'Save'}</button>
Expand Down

0 comments on commit 317dacb

Please sign in to comment.