Skip to content

Commit

Permalink
Merge pull request htmlacademy-univer-js2#19 from DashaKukartseva/master
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored Jun 10, 2024
2 parents f8a467f + 396e2f8 commit 15f987e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const routePresenter = new TripPointsPresenter({
pointsModel,
filterModel,
onNewPointDestroy: handleNewPointFormClose,
onNewPointClick: handleNewPointClick,
onNewPointClick: handleNewPointButtonClick,
});

const filterPresenter = new FilterPresenter({
Expand All @@ -48,7 +48,7 @@ function handleNewPointFormClose() {

function handleNewPointButtonClick() {
routePresenter.createEvent();
handleNewPointClick();
handleNewPointButtonClick();
}

render(newPointButtonComponent, tripMainContainer, RenderPosition.BEFOREEND);
Expand Down
2 changes: 1 addition & 1 deletion src/presenters/trippresenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default class TripPointsPresenter {
}
catch(err) {
this.#pointPresenters.get(update.id).setAborting();
};
}
break;
}
this.#uiBlocker.unblock();
Expand Down
48 changes: 24 additions & 24 deletions src/presenters/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ function firstLetterToLowerCase(type) {
return type.toLowerCase();
}

const getPointDuration = (dateFrom, dateTo) => {
const timeDiff = dayjs(dateTo).diff(dayjs(dateFrom));

if (timeDiff >= MSEC_IN_DAY) {
return dayjs.duration(timeDiff).format('DD[D] HH[H] mm[M]');
} else if (timeDiff >= MSEC_IN_HOUR) {
return dayjs.duration(timeDiff).format('HH[H] mm[M]');
}
return dayjs.duration(timeDiff).format('mm[M]');
}

function isBigDifference(event1, event2) {
return event1.price !== event2.price
|| getPointDuration(event1.dateFrom, event1.dateTo) !== getPointDuration(event2.dateFrom, event2.dateTo);
Expand Down Expand Up @@ -74,6 +85,18 @@ function adaptToServer(event) {
return adaptedEvent;
}

const sort = {
[SortType.DAY]: (points) => points.sort(sortByDay),
[SortType.PRICE]: (points) => points.sort(sortByPrice),
[SortType.TIME]: (points) => points.sort(sortByTime),
[SortType.EVENT]: () => {
throw new Error(`Sort by ${SortType.EVENT} is not implemented`);
},
[SortType.OFFER]: () => {
throw new Error(`Sort by ${SortType.OFFER} is not implemented`);
}
};

function getTripTitle(events = [], destinations = []) {
const destinationNames = sort[SortType.DAY]([...events])
.map((event) => destinations.find((destination) => destination.id === event.destination).name);
Expand Down Expand Up @@ -110,17 +133,6 @@ const formatStringToDateTime = (dateF) => dayjs(dateF).format('DD/MM/YY HH:mm');
const formatStringToShortDate = (dateF) => dayjs(dateF).format('MMM DD');
const formatStringToTime = (dateF) => dayjs(dateF).format('HH:mm');

const getPointDuration = (dateFrom, dateTo) => {
const timeDiff = dayjs(dateTo).diff(dayjs(dateFrom));

if (timeDiff >= MSEC_IN_DAY) {
return dayjs.duration(timeDiff).format('DD[D] HH[H] mm[M]');
} else if (timeDiff >= MSEC_IN_HOUR) {
return dayjs.duration(timeDiff).format('HH[H] mm[M]');
}
return dayjs.duration(timeDiff).format('mm[M]');
};

const sortByTime = (event1, event2) => {
const time1 = dayjs(event1.dateTo).diff(dayjs(event1.dateFrom));
const time2 = dayjs(event2.dateTo).diff(dayjs(event2.dateFrom));
Expand All @@ -143,18 +155,6 @@ const NoEventsTextType = {
[FilterType.FUTURE]: 'There are no future events now',
};

const sort = {
[SortType.DAY]: (points) => points.sort(sortByDay),
[SortType.PRICE]: (points) => points.sort(sortByPrice),
[SortType.TIME]: (points) => points.sort(sortByTime),
[SortType.EVENT]: () => {
throw new Error(`Sort by ${SortType.EVENT} is not implemented`);
},
[SortType.OFFER]: () => {
throw new Error(`Sort by ${SortType.OFFER} is not implemented`);
}
};

export {
adaptToClient,
adaptToServer,
Expand All @@ -176,4 +176,4 @@ export {
getTripTitle,
getTripDuration,
getTripCost
};
};
4 changes: 2 additions & 2 deletions src/view/modpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function createModPointElement({point, pointDestination, pointOffers, pointType}
<input class="event__input event__input--price" id="event-price-1" type="text" name="event-price" value="${he.encode(String(price))}"${isDisabled ? 'disabled' : ''}>
</div>
<button class="event__save-btn btn btn--blue" type="submit" ${isDisabled ? 'disabled' : ''}>${isSaving ? ButtonLabel.SAVE_IN_PROGRESS : ButtonLabel.SAVE_DEFAULT}</button>
${createResetButtonTemplate(eventType, isDeleting, isDisabled)}
${createResetButtonTemplate(pointType, isDeleting, isDisabled)}
${(pointType === EditType.EDITING) ? '<button class="event__rollup-btn" type="button">' : ''}
</header>
<section class="event__details">
Expand All @@ -108,7 +108,7 @@ function createModPointElement({point, pointDestination, pointOffers, pointType}
</section>` : ''}
</section>
${(currentDestination) ? `${(currentDestination.description.length || currentDestination.pictures.length) ?
`<section class="event__section event__section--destination">
`<section class="event__section event__section--destination">
<h3 class="event__section-title event__section-title--destination">Destination</h3>
<p class="event__destination-description">${currentDestination.description}</p>
${createPointPhotoElement(currentDestination.pictures)}` : ''}
Expand Down
6 changes: 3 additions & 3 deletions src/view/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ function createPointViewTemplate({ point, pointDestination, pointOffers }) {
}

function createOffersTemplate({ offers, pointOffers }) {
const offerItem = offers.map((offers) => pointOffers.includes(offers.id) ? `
const offerItem = offers.map((offer) => pointOffers.includes(offer.id) ? `
<li class="event__offer">
<span class="event__offer-title">${offers.title}</span>
<span class="event__offer-title">${offer.title}</span>
&plus;&euro;&nbsp;
<span class="event__offer-price">${offers.price}</span>
<span class="event__offer-price">${offer.price}</span>
</li>` : '').join('');
return `<ul class="event__selected-offers">${offerItem}</ul>`;
}
Expand Down

0 comments on commit 15f987e

Please sign in to comment.