Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Обновление века (часть 1) #19

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/const.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const OFFER_COUNT = 5;
const DESTINATION_COUNT = 5;

const POINT_COUNT = 5;

const CITIES = [
Expand All @@ -14,9 +14,11 @@
'Saint Petersburg',
'Moscow',
'Sochi',
'Tokio',
'Tokyo',
];

const DESTINATION_COUNT = CITIES.length;

const OFFERS = [
'Order Uber',
'Add luggage',
Expand Down Expand Up @@ -64,7 +66,7 @@
FUTURE: 'future',
PRESENT: 'present',
PAST: 'past'
}

Check failure on line 69 in src/const.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

const Mode = {
DEFAULT: 'default',
Expand Down Expand Up @@ -102,4 +104,4 @@
Mode,
SortType,
EnabledSortType
}

Check failure on line 107 in src/const.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
15 changes: 10 additions & 5 deletions src/mock/destination.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { getRandomValue, getRandomInteger } from '../utils.js';
import { CITIES, DESCRIPTION } from '../const.js';
import { getRandomInteger } from "../utils.js";

Check failure on line 1 in src/mock/destination.js

View workflow job for this annotation

GitHub Actions / Check

Strings must use singlequote
import { CITIES, DESCRIPTION } from "../const.js";

Check failure on line 2 in src/mock/destination.js

View workflow job for this annotation

GitHub Actions / Check

Strings must use singlequote

function generateDestination () {
const city = getRandomValue(CITIES);
const remainingCities = [...CITIES];

const generateDestination = () => {
const randomIndex = getRandomInteger(0, remainingCities.length - 1);
const city = remainingCities[randomIndex];

remainingCities.splice(randomIndex, 1);

return {
id: crypto.randomUUID(),
description: DESCRIPTION,
name: city,
pictures: Array.from({ length: getRandomInteger(1, 5) }, () => ({
pictures: Array.from({ length: getRandomInteger(0, 5) }, () => ({
'src': `https://loremflickr.com/248/152?random=${crypto.randomUUID()}`,
'description': `${city} description`
}))
};
}

Check failure on line 21 in src/mock/destination.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

export { generateDestination };
11 changes: 7 additions & 4 deletions src/presenter/point-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@

this.#editPointComponent = new EditPointView({
point: this.#point,
pointDestination: this.#destinationsModel.getById(point.destination),
pointOffers: this.#offersModel.getByType(point.type),
pointDestination: this.#destinationsModel.get(),
pointOffers: this.#offersModel.get(),
onSubmitClick: this.#formSubmitHandler,
onResetClick: this.#resetButtonClickHandler
})

Check failure on line 48 in src/presenter/point-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

if (prevPointComponent === null || prevEditPointComponent === null) {
if (!prevPointComponent || !prevEditPointComponent) {
render(this.#pointComponent, this.#container);
return;
}
Expand All @@ -57,7 +57,7 @@
}

if (this.#mode === Mode.EDITING) {
replace(this.#pointComponent, prevEditPointComponent);
replace(this.#editPointComponent, prevEditPointComponent);
}

remove(prevPointComponent);
Expand All @@ -66,6 +66,7 @@

resetView = () => {
if (this.#mode !== Mode.DEFAULT) {
this.#editPointComponent.reset(this.#point);
this.#replaceFormToPoint();
}
};
Expand All @@ -73,7 +74,7 @@
destroy = () => {
remove(this.#pointComponent);
remove(this.#editPointComponent);
}

Check failure on line 77 in src/presenter/point-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

#replacePointToForm = () => {
replace(this.#editPointComponent, this.#pointComponent);
Expand All @@ -91,6 +92,7 @@
#escKeyDownHandler = (evt) => {
if (evt.key === 'Escape') {
evt.preventDefault();
this.#editPointComponent.reset(this.#point);
this.#replaceFormToPoint();
}
};
Expand All @@ -109,9 +111,10 @@
#formSubmitHandler = (point) => {
this.#handleDataChange(point);
this.#replaceFormToPoint();
}

Check failure on line 114 in src/presenter/point-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

#resetButtonClickHandler = () => {
this.#editPointComponent.reset(this.#point);
this.#replaceFormToPoint();
}

Check failure on line 119 in src/presenter/point-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
}
2 changes: 1 addition & 1 deletion src/presenter/trip-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import EmptyListView from '../view/empty-list-view.js';
import PointPresenter from './point-presenter.js';
import { render, replace, remove } from '../framework/render.js';
import { updateItem } from '../utils.js';
import { SortType, EnabledSortType } from '../const.js';
import { SortType } from '../const.js';
import { sort } from '../utils/sort.js';
import PointListView from '../view/point-list-view.js';

Expand Down
51 changes: 31 additions & 20 deletions src/service/mock-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,45 @@ export default class MockService {
return this.destinations;
}

getOffers() {
return this.offers;
}

getPoints() {
return this.points;
}

generateDestinations() {
return Array.from(
{ length: DESTINATION_COUNT },
() => generateDestination()
);
}

generateOffers() {
return TYPES.map((type) => ({
type,
offers: Array.from({ length: getRandomInteger(0, OFFER_COUNT) }, () => generateOffer(type))
}));
return TYPES.map((type) => {
const offers = Array.from({ length: getRandomInteger(0, OFFER_COUNT) }, () => generateOffer(type));

const offersWithRandomSelection = offers.map((offer, index) => ({
...offer,
included: index < getRandomInteger(0, offers.length - 1)
}));

return {
type,
offers: offersWithRandomSelection
};
});
}

generatePoints() {
return Array.from({ length: POINT_COUNT }, () => {
const type = getRandomValue(TYPES);
const destination = getRandomValue(this.destinations);
const hasOffers = getRandomInteger(0, 1);
const offersByType = this.offers.find((offerByType) => offerByType.type === type);
const offersByType = this.offers
.find((offerByType) => offerByType.type === type);

const offerIds = (hasOffers)
? offersByType.offers
.slice(0, getRandomInteger(0, OFFER_COUNT))
Expand All @@ -42,19 +68,4 @@ export default class MockService {
return generatePoint(type, destination.id, offerIds);
});
}

getOffers() {
return this.offers;
}

getPoints() {
return this.points;
}

generateDestinations() {
return Array.from(
{ length: DESTINATION_COUNT },
() => generateDestination()
);
}
}
Loading
Loading