diff --git a/src/main.js b/src/main.js index b7b689f..959ac16 100644 --- a/src/main.js +++ b/src/main.js @@ -13,7 +13,7 @@ let mainTrip = header.querySelector(".trip-main") console.log(filter) let events = body.querySelector(".trip-events") let destinationModel = new DestinationModel() -let destinations = destinationModel.getDestination() +let destinations = destinationModel.all //console.log(destinations) let offersModel = new OfferModel() let offers = offersModel.getOffers() diff --git a/src/mocks/consts.js b/src/mocks/consts.js index 03c7f3c..7e2b012 100644 --- a/src/mocks/consts.js +++ b/src/mocks/consts.js @@ -6,6 +6,7 @@ const CITIES = [ 'Saint Petersburg', 'Copenhagen' ]; +const CITIES_COUNT = 6 const DESCRIPTIONS = [ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', @@ -46,8 +47,8 @@ const POINT_OFFERS = [ 'Order Uber', ]; -const POINTS_COUNT = 5; -const DESTINATIONS_COUNT = 5; -const OFFERS_COUNT = 5; +const POINTS_COUNT = 10; +const DESTINATIONS_COUNT = 10; +const OFFERS_COUNT = 10; -export{CITIES, DESCRIPTIONS, PRICE, DURATION, TYPES, POINTS_COUNT, POINT_OFFERS, DESTINATIONS_COUNT, OFFERS_COUNT}; +export{CITIES, DESCRIPTIONS, PRICE, DURATION, TYPES, POINTS_COUNT, POINT_OFFERS, DESTINATIONS_COUNT, OFFERS_COUNT, CITIES_COUNT}; diff --git a/src/mocks/destination.js b/src/mocks/destination.js index 4eb7e66..287a7a6 100644 --- a/src/mocks/destination.js +++ b/src/mocks/destination.js @@ -1,13 +1,16 @@ import { getRandomNumber, getRandomValue } from '../utils.js'; -import { CITIES, DESCRIPTIONS } from './consts.js'; -export function generateDestination() +import { CITIES, DESCRIPTIONS, DESTINATIONS_COUNT, CITIES_COUNT } from './consts.js'; +export function generateDestinations() { - return { + let destinations = [] + for (let i=0; i ({ src: `https://loremflickr.com/248/152?random=${crypto.randomUUID()}`, description: getRandomValue(DESCRIPTIONS)})) - } + }) + return destinations } diff --git a/src/model/destination_model.js b/src/model/destination_model.js index 725fae9..a21a96d 100644 --- a/src/model/destination_model.js +++ b/src/model/destination_model.js @@ -1,11 +1,11 @@ import { DESTINATIONS_COUNT } from "../mocks/consts" -import { generateDestination } from "../mocks/destination" +import { generateDestinations } from "../mocks/destination" export class DestinationModel { constructor() { - this.destinations = Array.from({length: DESTINATIONS_COUNT}, generateDestination) + this.destinations = generateDestinations() } -getDestination() { +get all() { return this.destinations } getById(id) diff --git a/src/presenter/point-pesenter.js b/src/presenter/point-pesenter.js index 0f680d5..b4c8969 100644 --- a/src/presenter/point-pesenter.js +++ b/src/presenter/point-pesenter.js @@ -11,8 +11,9 @@ export default class PointPresenter { point = null pointComponent = null editComponent = null - constructor(destination, offer, container, handleDataChange, handleModeChange) { + constructor(destination, destinations, offer, container, handleDataChange, handleModeChange) { this.destination = destination; + this.destinations = destinations; this.offer = offer; this.container = container; this.#handleDataChange = handleDataChange; @@ -26,6 +27,7 @@ export default class PointPresenter { #renderPoint() { + console.log(this.point) const prevPointComponent = this.pointComponent; const prevPointEditComponent = this.editComponent; const escKeyDownHandler = (evt) => { @@ -37,7 +39,7 @@ export default class PointPresenter { }; this.pointComponent = new RoutePointView( this.point, - this.destination, + this.destinations.find(destination=>destination.id==this.point.destinationId), this.offer, () => { this.replaceCardToForm() @@ -49,18 +51,20 @@ export default class PointPresenter { this.editComponent = new EditPointView( this.point, this.destination, + this.destinations, this.offer, - this.#handleFormSubmit + this.#handleFormSubmit, + this.#handleFormClose ) //console.log(point) - if (prevPointComponent === null || prevPointEditComponent === null) { + if (prevPointComponent === null || prevPointEditComponent === null) { render( this.pointComponent, this.container.element ); return - } + } if (this.mode === Mode.DEFAULT) { replace(this.pointComponent, prevPointComponent); } @@ -95,5 +99,10 @@ export default class PointPresenter { this.#handleDataChange(point) this.replaceFormToCard() } + #handleFormClose = (evt) => + { + //evt.preventDefault() + this.replaceFormToCard() + } } diff --git a/src/presenter/trip-presenter.js b/src/presenter/trip-presenter.js index faeca98..08b9b86 100644 --- a/src/presenter/trip-presenter.js +++ b/src/presenter/trip-presenter.js @@ -24,6 +24,7 @@ export default class TripPresenter { render(this.eventListComponent, this.container); this.points.forEach((point) => { const presenter = new PointPresenter(this.destinationsModel.getById(point.destinationId), + this.destinationsModel.all, this.offersModel.getOfferByType(point.type), this.eventListComponent, this.#handlePointChange, this.#handleModeChange) this.pointPresenters.set(point.id, presenter) presenter.init(point) @@ -32,6 +33,7 @@ export default class TripPresenter { #handlePointChange = (updatedPoint) => { //console.log('изменено') this.points = updateItem(this.points, updatedPoint) + console.log(updatedPoint.id) this.pointPresenters.get(updatedPoint.id).init(updatedPoint) } #handleModeChange = () => { diff --git a/src/templates/edit-template.js b/src/templates/edit-template.js index 49c18d9..9e5b700 100644 --- a/src/templates/edit-template.js +++ b/src/templates/edit-template.js @@ -1,8 +1,9 @@ import { CITIES, TYPES } from "../mocks/consts"; export function createEditTemplate(point, destination, offers) { + console.log(point) const { type} = point; console.log('Данные формы') - //console.log(point) + //console.log(destination) console.log(offers) @@ -30,7 +31,7 @@ export function createEditTemplate(point, destination, offers) { - + ${createDestinationListTemplate()} @@ -61,7 +62,7 @@ export function createEditTemplate(point, destination, offers) {

Offers

- ${createPointOffer(offers)} + ${createPointOffer(offers, type)}
@@ -94,16 +95,16 @@ function createPointTypesListElement(currentType) { function createDestinationListTemplate() { return ` - ${CITIES.map((city)=>`` } -function createPointOffer(offers) +function createPointOffer(offers, type) { let result='' offers.forEach((offer, index) => { result+=`
- -