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/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/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..9bb5057 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; @@ -206,10 +200,7 @@ class TripPresenter { this.#renderLoading(); return; } - if (this.#filterType === FilterType.EVERYTHING) { - this.#renderTripInfo(); - } - this.#renderMenu(); + 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)); }) }; 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(`