Skip to content

Commit

Permalink
Merge pull request #17 from ssftvyn/master
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored May 31, 2024
2 parents d13b84b + cdd0248 commit 91f5f90
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
12 changes: 6 additions & 6 deletions src/presenter/filter-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ 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,
name: 'PRESENT',
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,
}
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/presenter/point-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default class PointPresenter{
UserAction.UPDATE_POINT,
UpdateType.MINOR,
update);
this.#editPointComponent.reset(update);
// this.#editPointComponent.reset(update);
};

#handleDeleteClick = (point) => {
Expand Down
11 changes: 1 addition & 10 deletions src/presenter/trip-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +21,6 @@ class TripPresenter {
#sortComponent = null;
#loadingComponent = new LoadingView();
#tripInfoComponent = null;
#menuComponent = new MenuView();
#noPoint = null;
#pointPresenter = new Map();
#newPointPresenter = null;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
20 changes: 8 additions & 12 deletions src/utils/filter.js
Original file line number Diff line number Diff line change
@@ -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));
})
};
5 changes: 3 additions & 2 deletions src/view/edit-point-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const BLANK_POINT = {
destination: 1,
startDate: dayjs(),
endDate: dayjs(),
price: 100,
price: null,
isFavorite: false,
offers: []
};
Expand Down Expand Up @@ -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
});
};

Expand Down
14 changes: 0 additions & 14 deletions src/view/menu-view.js

This file was deleted.

55 changes: 4 additions & 51 deletions src/view/new-point-view.js
Original file line number Diff line number Diff line change
@@ -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(`<div class="event__offer-selector">
<input class="event__offer-checkbox visually-hidden" id="event-offer-luggage-1" type="checkbox" name="event-offer-luggage" checked>
<label class="event__offer-label" for="event-offer-luggage-1">
<span class="event__offer-title">${offer.title}</span>
&plus;&euro;&nbsp;
<span class="event__offer-price">${offer.price}</span>
</label>
</div>`);
} else {
return(`<div class="event__offer-selector">
<input class="event__offer-checkbox visually-hidden" id="event-offer-luggage-1" type="checkbox" name="event-offer-luggage">
<label class="event__offer-label" for="event-offer-luggage-1">
<span class="event__offer-title">${offer.title}</span>
&plus;&euro;&nbsp;
<span class="event__offer-price">${offer.price}</span>
</label>
</div>`);
}
};
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) => (`<img class="event__photo" src="${photo}" alt="Event photo">`)).join('');
}
return photosTemplates;
};

return(`<li class="trip-events__item">
<form class="event event--edit" action="#" method="post">
<header class="event__header">
Expand Down Expand Up @@ -117,7 +72,7 @@ export const newPoint = (crNewPoint) => {
<label class="event__label event__type-output" for="event-destination-1">
${type}
</label>
<input class="event__input event__input--destination" id="event-destination-1" type="text" name="event-destination" value="${city}" list="destination-list-1">
<input class="event__input event__input--destination" id="event-destination-1" type="text" name="event-destination" value="" list="destination-list-1">
<datalist id="destination-list-1">
<option value="Amsterdam"></option>
<option value="Geneva"></option>
Expand Down Expand Up @@ -149,16 +104,14 @@ export const newPoint = (crNewPoint) => {
<h3 class="event__section-title event__section-title--offers">Offers</h3>
<div class="event__available-offers">
${createOffersTemplates()}
</div>
</section>
<section class="event__section event__section--destination">
<h3 class="event__section-title event__section-title--destination">Destination</h3>
<p class="event__destination-description">${description}</p>
<p class="event__destination-description"></p>
<div class="event__photos-container">
<div class="event__photos-tape">
${createPhotosTemplates()}
</div>
</div>
</section>
Expand Down
9 changes: 8 additions & 1 deletion src/view/trip-info-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')}&nbsp;&mdash;&nbsp;${humanizePointDate(endPoint.endDate, 'D')}`
: `${humanizePointDate(startPoint.startDate, 'MMM D')}&nbsp;&mdash;&nbsp;${humanizePointDate(endPoint.endDate, 'MMM D')}`;

return(
`<section class="trip-main__trip-info trip-info">
<div class="trip-info__main">
<h1 class="trip-info__title">${getTripTitle(points, destinations, startPoint, endPoint)}</h1>
<p class="trip-info__dates">${humanizePointDate(startPoint.startDate, 'MMM D')}&nbsp;&mdash;&nbsp;${humanizePointDate(endPoint.endDate, 'MMM D')}</p>
<p class="trip-info__dates">${formattedDates}</p>
</div>
<p class="trip-info__cost">
Total: &euro;&nbsp;<span class="trip-info__cost-value">${getTotalAmount(points, offers)}</span>
Expand Down

0 comments on commit 91f5f90

Please sign in to comment.