From 2ca4a1e32615bff2bf89015e4bd49cbb0dba25c4 Mon Sep 17 00:00:00 2001 From: ssftvyn Date: Fri, 31 May 2024 17:30:37 +0500 Subject: [PATCH 1/2] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BA=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/const.js | 2 +- src/presenter/filter-presenter.js | 12 +++---- src/presenter/point-presenter.js | 2 +- src/presenter/trip-presenter.js | 7 ---- src/view/edit-point-view.js | 5 +-- src/view/menu-view.js | 14 -------- src/view/new-point-view.js | 55 +++---------------------------- src/view/trip-info-view.js | 9 ++++- 8 files changed, 23 insertions(+), 83 deletions(-) delete mode 100644 src/view/menu-view.js diff --git a/src/const.js b/src/const.js index 25eced1..31e6f7d 100644 --- a/src/const.js +++ b/src/const.js @@ -89,9 +89,9 @@ export const SortType = { export const NoPointsTextType = { [FilterType.EVERYTHING]: 'click new event to create your first point', + [FilterType.FUTURE]: 'there are no future events now', [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/presenter/filter-presenter.js b/src/presenter/filter-presenter.js index ee1ae2f..7680538 100644 --- a/src/presenter/filter-presenter.js +++ b/src/presenter/filter-presenter.js @@ -47,9 +47,9 @@ export default class FilterPresenter { count: filterByType[FilterType.EVERYTHING](points).length, }, { - type: FilterType.PAST, - name: 'PAST', - count: filterByType[FilterType.PAST](points).length, + type: FilterType.FUTURE, + name: 'FUTURE', + count: filterByType[FilterType.FUTURE](points).length, }, { type: FilterType.PRESENT, @@ -57,9 +57,9 @@ export default class FilterPresenter { count: filterByType[FilterType.PRESENT](points).length, }, { - type: FilterType.FUTURE, - name: 'FUTURE', - count: filterByType[FilterType.FUTURE](points).length, + type: FilterType.PAST, + name: 'PAST', + count: filterByType[FilterType.PAST](points).length, } ]; } diff --git a/src/presenter/point-presenter.js b/src/presenter/point-presenter.js index e398ec6..b5bf03e 100644 --- a/src/presenter/point-presenter.js +++ b/src/presenter/point-presenter.js @@ -146,7 +146,7 @@ export default class PointPresenter{ UserAction.UPDATE_POINT, UpdateType.MINOR, update); - this.#editPointComponent.reset(update); + // this.#editPointComponent.reset(update); }; #handleDeleteClick = (point) => { diff --git a/src/presenter/trip-presenter.js b/src/presenter/trip-presenter.js index e02f986..c4b3e49 100644 --- a/src/presenter/trip-presenter.js +++ b/src/presenter/trip-presenter.js @@ -10,7 +10,6 @@ import NewPointPresenter from './new-point-presenter'; import LoadingView from '../view/loading-view'; import UiBlocker from '../framework/ui-blocker/ui-blocker'; import TripInfoView from '../view/trip-info-view'; -import MenuView from '../view/menu-view'; class TripPresenter { #container = null; @@ -22,7 +21,6 @@ class TripPresenter { #sortComponent = null; #loadingComponent = new LoadingView(); #tripInfoComponent = null; - #menuComponent = new MenuView(); #noPoint = null; #pointPresenter = new Map(); #newPointPresenter = null; @@ -191,10 +189,6 @@ class TripPresenter { render(this.#tripInfoComponent, this.#headerContainer, RenderPosition.AFTERBEGIN); } - #renderMenu() { - render(this.#menuComponent, this.#menuContainer); - } - #renderBoard() { const points = this.points; const pointsCount = points.length; @@ -209,7 +203,6 @@ class TripPresenter { if (this.#filterType === FilterType.EVERYTHING) { this.#renderTripInfo(); } - this.#renderMenu(); this.#renderSort(); render(this.#component, this.#container); this.#renderPoints(points); diff --git a/src/view/edit-point-view.js b/src/view/edit-point-view.js index 023e294..e92320e 100644 --- a/src/view/edit-point-view.js +++ b/src/view/edit-point-view.js @@ -12,7 +12,7 @@ const BLANK_POINT = { destination: 1, startDate: dayjs(), endDate: dayjs(), - price: 100, + price: null, isFavorite: false, offers: [] }; @@ -223,8 +223,9 @@ export default class EditingPointView extends AbstractStatefulView{ #ChangePriceHandler = (event) => { event.preventDefault(); + const inputPrice = Number(event.target.value); this.updateElement({ - price: Number(event.target.value) + price: inputPrice >= 0 ? inputPrice : 0 }); }; diff --git a/src/view/menu-view.js b/src/view/menu-view.js deleted file mode 100644 index 5db84d3..0000000 --- a/src/view/menu-view.js +++ /dev/null @@ -1,14 +0,0 @@ -import AbstractView from '../framework/view/abstract-view.js'; - -const createMenu = () => ( - `` -); - -export default class MenuView extends AbstractView { - get template() { - return createMenu(); - } -} diff --git a/src/view/new-point-view.js b/src/view/new-point-view.js index c88e4e7..05e4e81 100644 --- a/src/view/new-point-view.js +++ b/src/view/new-point-view.js @@ -1,56 +1,11 @@ import AbstractView from '../framework/view/abstract-view'; import {humanizePointDate} from '../utils/point'; -import {generateOffersByType} from '../mock/offer'; -import {generateDestination} from '../mock/destination'; export const newPoint = (crNewPoint) => { - const {type, destination, startDate, endDate, price, offers} = crNewPoint; + const {type, startDate, endDate, price} = crNewPoint; const dateFrom = startDate !== null ? humanizePointDate(startDate, 'DD/MM/YY HH:mm') : ''; const dateTo = endDate !== null ? humanizePointDate(endDate, 'DD/MM/YY HH:mm') : ''; - const getDestination = destination.length !== 0 ? generateDestination.find((x) => x.id === destination) : ''; - const city = getDestination !== '' ? getDestination.city : ''; - const description = getDestination !== '' ? getDestination.description : ''; - const destPhotos = getDestination !== '' ? getDestination.photos : ''; - const generateOffers = (offer) => { - if (offers.find((x) => x === offer.id)) { - return(`
- - -
`); - } else { - return(`
- - -
`); - } - }; - const createOffersTemplates = () => { - if (offers.length === 0) { - return ''; - } else { - let offersTemplates = ''; - const offersByType = generateOffersByType().find((x) => x.type === type); - for (let i = 0; i < offersByType.offers.length; i++) { - offersTemplates += generateOffers(offersByType.offers[i]); - } - return offersTemplates; - } - }; - const createPhotosTemplates = () => { - let photosTemplates = ''; - if (destPhotos !== ''){ - photosTemplates = destPhotos.map((photo) => (`Event photo`)).join(''); - } - return photosTemplates; - }; + return(`
  • @@ -117,7 +72,7 @@ export const newPoint = (crNewPoint) => { - + @@ -149,16 +104,14 @@ export const newPoint = (crNewPoint) => {

    Offers

    - ${createOffersTemplates()}

    Destination

    -

    ${description}

    +

    - ${createPhotosTemplates()}
    diff --git a/src/view/trip-info-view.js b/src/view/trip-info-view.js index 1150a39..6d6a537 100644 --- a/src/view/trip-info-view.js +++ b/src/view/trip-info-view.js @@ -47,11 +47,18 @@ const createTripInfoTemplate = (points, destinations, offers) => { const startPoint = getStartPoint(points); const endPoint = getEndPoint(points); + const startMonth = humanizePointDate(startPoint.startDate, 'MMM'); + const endMonth = humanizePointDate(endPoint.endDate, 'MMM'); + + const formattedDates = startMonth === endMonth + ? `${humanizePointDate(startPoint.startDate, 'MMM D')} — ${humanizePointDate(endPoint.endDate, 'D')}` + : `${humanizePointDate(startPoint.startDate, 'MMM D')} — ${humanizePointDate(endPoint.endDate, 'MMM D')}`; + return( `

    ${getTripTitle(points, destinations, startPoint, endPoint)}

    -

    ${humanizePointDate(startPoint.startDate, 'MMM D')} — ${humanizePointDate(endPoint.endDate, 'MMM D')}

    +

    ${formattedDates}

    Total: € ${getTotalAmount(points, offers)} From cdd02486132e2f574bc81d2b95ebf4409c51ce30 Mon Sep 17 00:00:00 2001 From: ssftvyn Date: Sat, 1 Jun 2024 00:50:39 +0500 Subject: [PATCH 2/2] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BA=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D0=B5=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 2 +- src/presenter/trip-presenter.js | 4 +--- src/utils/filter.js | 20 ++++++++------------ 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/main.js b/src/main.js index c0168b0..8f05315 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 hs0NCvhAEP'; +const AUTHORIZATION = 'Basic hs0NCvhAEPs'; const END_POINT = 'https://21.objects.htmlacademy.pro/big-trip'; const tripContainer = document.querySelector('.trip-events'); diff --git a/src/presenter/trip-presenter.js b/src/presenter/trip-presenter.js index c4b3e49..9bb5057 100644 --- a/src/presenter/trip-presenter.js +++ b/src/presenter/trip-presenter.js @@ -200,9 +200,7 @@ class TripPresenter { this.#renderLoading(); return; } - if (this.#filterType === FilterType.EVERYTHING) { - this.#renderTripInfo(); - } + this.#renderTripInfo(); this.#renderSort(); render(this.#component, this.#container); this.#renderPoints(points); diff --git a/src/utils/filter.js b/src/utils/filter.js index 2feaa3a..840d1c7 100644 --- a/src/utils/filter.js +++ b/src/utils/filter.js @@ -1,21 +1,17 @@ import dayjs from 'dayjs'; import {FilterType} from '../const'; -const filterByPast = (date, param) => dayjs().isAfter(dayjs(date), param); - -const filterByFuture = (date, param) => dayjs().isBefore(dayjs(date), param) || dayjs().isSame(dayjs(date), param); +const filterByPast = (date) => dayjs().isAfter(dayjs(date), 'day'); +const filterByFuture = (date) => dayjs(date).isAfter(dayjs(), 'day'); 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.FUTURE]: (points) => points.filter((point) => filterByFuture(point.startDate)), + [FilterType.PAST]: (points) => points.filter((point) => filterByPast(point.endDate)), [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; + const currentDate = dayjs().startOf('day'); + const startDate = dayjs(point.startDate).startOf('day'); + const endDate = dayjs(point.endDate).startOf('day'); + return startDate.isSame(currentDate) || (startDate.isBefore(currentDate) && endDate.isAfter(currentDate)); }) };