From 0cd9ed2f0dd40a1ca2537f627f575100394cdd4d Mon Sep 17 00:00:00 2001 From: ssftvyn Date: Wed, 22 May 2024 13:12:14 +0500 Subject: [PATCH 1/5] new event fixed --- src/view/edit-point-view.js | 6 +++--- src/view/point-view.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/view/edit-point-view.js b/src/view/edit-point-view.js index 9f17184..d70feb0 100644 --- a/src/view/edit-point-view.js +++ b/src/view/edit-point-view.js @@ -96,7 +96,7 @@ export const editingPointView = (point, destinations, offersIds, isNewPoint) => ${type} ${generateDestinations(destinations, isDisabled)} @@ -138,7 +138,7 @@ export const editingPointView = (point, destinations, offersIds, isNewPoint) => -
+ ${destinationData ? `

Destination

${destinationData.description}

@@ -146,7 +146,7 @@ export const editingPointView = (point, destinations, offersIds, isNewPoint) => ${createPhotosTemplates(destinationData.pictures)}
-
+
` : ''} ` diff --git a/src/view/point-view.js b/src/view/point-view.js index e058b30..4703809 100644 --- a/src/view/point-view.js +++ b/src/view/point-view.js @@ -13,9 +13,9 @@ const createOffersTemplates = (allOffers, checkedOffers) => { export const pointView = (point, destinations, offersIds) => { const {type, destination, startDate, endDate, price, isFavorite, offers} = point; - const dateFrom = startDate !== null ? humanizePointDate(startDate, 'DD/MM/YY HH:mm') : ''; - const dateTo = endDate !== null ? humanizePointDate(endDate, 'DD/MM/YY HH:mm') : ''; - const date = startDate !== null ? humanizePointDate(startDate, 'D MMMM') : ''; + const dateFrom = startDate !== null ? humanizePointDate(startDate, 'HH:mm') : ''; + const dateTo = endDate !== null ? humanizePointDate(endDate, 'HH:mm') : ''; + const date = startDate !== null ? humanizePointDate(startDate, 'MMM D') : ''; const allTypeOffers = offersIds.find((offer) => offer.type === type); const favoriteClass = isFavorite ? 'event__favorite-btn--active' : ''; const destinationData = destinations.find((dest) => dest.id === destination); From b3ac29fc5867d21fd2cf6ac83dac3dec86dd2475 Mon Sep 17 00:00:00 2001 From: ssftvyn Date: Wed, 22 May 2024 13:49:34 +0500 Subject: [PATCH 2/5] filter update --- src/const.js | 2 ++ src/main.js | 2 +- src/presenter/filter-presenter.js | 5 +++++ src/utils/filter.js | 11 ++++++++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/const.js b/src/const.js index 4915c92..1b5000f 100644 --- a/src/const.js +++ b/src/const.js @@ -77,6 +77,7 @@ export const TYPES = ['taxi', 'bus', 'train', 'ship', 'drive', 'flight', 'check- export const FilterType = { EVERYTHING: 'everything', FUTURE: 'future', + PRESENT: 'present', PAST: 'past' }; @@ -89,6 +90,7 @@ export const SortType = { export const NoPointsTextType = { [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' }; diff --git a/src/main.js b/src/main.js index 16def16..8f20a84 100644 --- a/src/main.js +++ b/src/main.js @@ -10,7 +10,7 @@ import PointsApiService from './api-service/points-api'; import DestinationsApiService from './api-service/destinations-api'; import OffersApiService from './api-service/offers-api'; -const AUTHORIZATION = 'Basic RsgQy3KcnM'; +const AUTHORIZATION = 'Basic 2PV6hj7Xi2'; const END_POINT = 'https://21.objects.htmlacademy.pro/big-trip'; const tripContainer = document.querySelector('.trip-events'); diff --git a/src/presenter/filter-presenter.js b/src/presenter/filter-presenter.js index 155c9d0..ee1ae2f 100644 --- a/src/presenter/filter-presenter.js +++ b/src/presenter/filter-presenter.js @@ -51,6 +51,11 @@ export default class FilterPresenter { name: 'PAST', count: filterByType[FilterType.PAST](points).length, }, + { + type: FilterType.PRESENT, + name: 'PRESENT', + count: filterByType[FilterType.PRESENT](points).length, + }, { type: FilterType.FUTURE, name: 'FUTURE', diff --git a/src/utils/filter.js b/src/utils/filter.js index cc83fc5..2feaa3a 100644 --- a/src/utils/filter.js +++ b/src/utils/filter.js @@ -8,5 +8,14 @@ const filterByFuture = (date, param) => dayjs().isBefore(dayjs(date), param) || export const filterByType = { [FilterType.EVERYTHING]: (points) => points, [FilterType.FUTURE]: (points) => points.filter((point) => filterByFuture(point.startDate, 'D') || filterByFuture(point.endDate, 'D')), - [FilterType.PAST]: (points) => points.filter((point) => filterByPast(point.endDate, 'D') || filterByPast(point.startDate, 'D')) + [FilterType.PAST]: (points) => points.filter((point) => filterByPast(point.endDate, 'D') || filterByPast(point.startDate, 'D')), + [FilterType.PRESENT]: (points) => points.filter((point) => { + const currentDate = new Date(); + currentDate.setHours(0, 0, 0, 0); + const startDate = new Date(point.startDate); + startDate.setHours(0, 0, 0, 0); + const endDate = new Date(point.endDate); + endDate.setHours(0, 0, 0, 0); + return startDate <= currentDate && endDate >= currentDate; + }) }; From 7a7e83f04e47864ff10dfd9060341b54c11cf756 Mon Sep 17 00:00:00 2001 From: ssftvyn Date: Wed, 22 May 2024 13:53:45 +0500 Subject: [PATCH 3/5] sort update max-->min --- src/utils/point.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/point.js b/src/utils/point.js index 3391c9d..309b3bb 100644 --- a/src/utils/point.js +++ b/src/utils/point.js @@ -23,12 +23,12 @@ export const calculateDuration = (startDate, endDate) => { return `${differenceMinutes}M`; }; -export const sortPointTime = (pointA, pointB) => dayjs(pointA.endDate).diff(dayjs(pointA.startDate)) - dayjs(pointB.endDate).diff(dayjs(pointB.startDate)); +export const sortPointTime = (pointA, pointB) => dayjs(pointB.endDate).diff(dayjs(pointB.startDate)) - dayjs(pointA.endDate).diff(dayjs(pointA.startDate)); export const sortPointDay = (pointA, pointB) => { const dateFromDifference = dayjs(pointA.startDate).diff(dayjs(pointB.startDate)); return dateFromDifference === 0 ? dayjs(pointB.endDate).diff(dayjs(pointA.endDate)) : dateFromDifference; }; -export const sortPointPrice = (pointA, pointB) => pointA.price - pointB.price; +export const sortPointPrice = (pointA, pointB) => pointB.price - pointA.price; From a25c51c592ab5e5684551ede63f8aa8b2c2a0ae2 Mon Sep 17 00:00:00 2001 From: ssftvyn Date: Wed, 22 May 2024 18:53:50 +0500 Subject: [PATCH 4/5] offers fix --- src/view/edit-point-view.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/view/edit-point-view.js b/src/view/edit-point-view.js index d70feb0..023e294 100644 --- a/src/view/edit-point-view.js +++ b/src/view/edit-point-view.js @@ -238,17 +238,18 @@ export default class EditingPointView extends AbstractStatefulView{ #changeOfferHandler = (event) => { event.preventDefault(); - const offerId = Number(event.target.id.slice(-1)); - const arrayOffersIds = this._state.offers.filter((n) => n !== offerId); - let currentOfferIds = [...this._state.offers]; - if (arrayOffersIds.length !== this._state.offers.length) { - currentOfferIds = arrayOffersIds; + const offerId = event.target.id.replace('event-offer-', ''); + const newOffers = [...this._state.offers]; + const offerIndex = newOffers.findIndex((id) => id === offerId); + if (offerIndex > -1) { + newOffers.splice(offerIndex, 1); } else { - currentOfferIds.push(offerId); + newOffers.push(offerId); } this._setState({ - offers: currentOfferIds, + offers: newOffers, }); + this.updateElement(this._state); }; #setStartDatepicker() { From f6ff85e4264513699cf43340fc96da95bca83490 Mon Sep 17 00:00:00 2001 From: ssftvyn Date: Wed, 22 May 2024 21:28:40 +0500 Subject: [PATCH 5/5] button fix --- src/const.js | 8 ++++---- src/main.js | 2 +- src/view/new-point-button-view.js | 8 ++++++++ src/view/no-point-view.js | 1 - 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/const.js b/src/const.js index 1b5000f..25eced1 100644 --- a/src/const.js +++ b/src/const.js @@ -88,10 +88,10 @@ export const SortType = { }; export const NoPointsTextType = { - [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.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' }; export const Mode = { diff --git a/src/main.js b/src/main.js index 8f20a84..c0168b0 100644 --- a/src/main.js +++ b/src/main.js @@ -10,7 +10,7 @@ import PointsApiService from './api-service/points-api'; import DestinationsApiService from './api-service/destinations-api'; import OffersApiService from './api-service/offers-api'; -const AUTHORIZATION = 'Basic 2PV6hj7Xi2'; +const AUTHORIZATION = 'Basic hs0NCvhAEP'; const END_POINT = 'https://21.objects.htmlacademy.pro/big-trip'; const tripContainer = document.querySelector('.trip-events'); diff --git a/src/view/new-point-button-view.js b/src/view/new-point-button-view.js index 643b13b..76ff26c 100644 --- a/src/view/new-point-button-view.js +++ b/src/view/new-point-button-view.js @@ -17,5 +17,13 @@ export default class NewPointButtonView extends AbstractView { #clickHandler = (event) => { event.preventDefault(); this.#handleClick(); + this.#hideNoPointsText(); + }; + + #hideNoPointsText = () => { + const noPointsTextElement = document.querySelector('.trip-events__msg'); + if (noPointsTextElement) { + noPointsTextElement.style.display = 'none'; + } }; } diff --git a/src/view/no-point-view.js b/src/view/no-point-view.js index 4a4dc61..6e12c69 100644 --- a/src/view/no-point-view.js +++ b/src/view/no-point-view.js @@ -19,4 +19,3 @@ export default class NoPointView extends AbstractView { } } -