-
Notifications
You must be signed in to change notification settings - Fork 1
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) #6
Merged
keksobot
merged 17 commits into
htmlacademy-ecmascript:master
from
Talurion:module5-task1
Oct 18, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c8914a7
выделил event presenter
Talurion 8c271e7
нашел ошибку в event presenter
Talurion 6a69b9a
module5-task1 - готово
Talurion fa6d23f
SortType - data атрибут
Talurion a6d2837
заготовка под сортировку
Talurion 0e957e4
метод сортировки
Talurion 858a1c0
связал сортировку и рендеринг задач
Talurion 47197b6
6.1.1
Talurion 577fb01
сохранение пользовательских данных
Talurion f7bd16a
добавил выбор города
Talurion f73bca4
протянул поиск данных о городе из модели во вью
Talurion ad12ad8
установил flatpickr
Talurion fec8a72
ограничил выбор дат, что бы нельзя было выбрать дату начала больше че…
Talurion f1c7359
добавил еще более случайную генерацию офферов и исправил коннектор
Talurion 9239f68
добавил выбор офферов
Talurion be187d7
отимизировал коннектор
Talurion a986516
небольшие правки
Talurion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,40 +3,74 @@ import { getRandomOffers } from '../mock/offers'; | |
import { getRandomDestinations } from '../mock/destinations'; | ||
import { convertKeysToCamelCase } from '../utils/common'; | ||
|
||
const EVENTS_COUNT = 3; | ||
|
||
const createUserEvents = () => { | ||
const offersList = convertKeysToCamelCase(getRandomOffers()); | ||
const destinationsList = convertKeysToCamelCase(getRandomDestinations()); | ||
const eventsList = convertKeysToCamelCase(getRandomEvents(EVENTS_COUNT, destinationsList)); | ||
|
||
const destinationsMap = new Map(destinationsList.map((destination) => [destination.id, destination])); | ||
const offers = offersList[0].offers; | ||
|
||
const mergedEvents = eventsList.map((event) => { | ||
const destinationData = destinationsMap.get(event.destination); | ||
|
||
const offersData = event.offers | ||
.map((offerId) => offers.find((offer) => offer.id === offerId)) | ||
.filter(Boolean); | ||
|
||
return { | ||
...event, | ||
destination: { | ||
id: destinationData.id, | ||
name: destinationData.name, | ||
description: destinationData.description, | ||
pictures: destinationData.pictures, | ||
}, | ||
offers: offersData | ||
}; | ||
}); | ||
|
||
return Array.from(new Map(mergedEvents.map((event) => [event.id, event])).values()); | ||
}; | ||
const EVENTS_COUNT = 5; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. я бы вынес в файл с константами, но если это только для моков - то можно оставить здесь, главное потом не забыть удалить |
||
|
||
export default class EventsConnector { | ||
#destinationsData = convertKeysToCamelCase(getRandomDestinations()); | ||
#offersMap = this.#initializeOffersMap(convertKeysToCamelCase(getRandomOffers())); | ||
#clonedOffersMap = structuredClone(this.#offersMap); | ||
#eventsList = convertKeysToCamelCase(getRandomEvents(EVENTS_COUNT, this.#destinationsData, this.#clonedOffersMap)); | ||
|
||
#initializeOffersMap (data) { | ||
return data.reduce((offersMap, { type, offers }) => { | ||
const offersById = new Map( | ||
offers.map(({ id, title, price }) => [id, { title, price, isActive: false }]) | ||
); | ||
offersMap.set(type, offersById); | ||
return offersMap; | ||
}, new Map()); | ||
} | ||
|
||
#updateOffersActivity () { | ||
this.#eventsList.forEach(({ offers: eventOffers, type }) => { | ||
const offersById = this.#clonedOffersMap.get(type); | ||
eventOffers.forEach((offerId) => { | ||
const offer = offersById.get(offerId); | ||
if (offer) { | ||
offer.isActive = true; | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
constructor () { | ||
this.#updateOffersActivity(); | ||
} | ||
|
||
#getOfferById (type, id) { | ||
const offer = this.#clonedOffersMap.get(type)?.get(id); | ||
return offer ? { id, ...offer } : null; | ||
} | ||
|
||
#createUserEvents () { | ||
const destinationsMap = new Map(this.#destinationsData.map(({ id, ...rest }) => [id, rest])); | ||
|
||
return Array.from(this.#eventsList.map((event) => { | ||
const destinationData = destinationsMap.get(event.destination); | ||
const offersMap = new Map( | ||
event.offers.map((offerId) => this.#getOfferById(event.type, offerId)).filter(Boolean).map((offer) => [offer.id, offer]) | ||
); | ||
|
||
return { | ||
...event, | ||
destination: { id: destinationData.id, ...destinationData }, | ||
offers: offersMap | ||
}; | ||
}).reduce((acc, event) => { | ||
acc.set(event.id, event); | ||
return acc; | ||
}, new Map()).values()); | ||
} | ||
|
||
get userEvents () { | ||
return structuredClone(createUserEvents()); | ||
return this.#createUserEvents(); | ||
} | ||
|
||
get destinationsData () { | ||
return this.#destinationsData; | ||
} | ||
|
||
get offersMap () { | ||
return this.#offersMap; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
так вот здесь чуть чуть не понял, а как ты мапишь потом по id, если они у тебя рандомно генерятся?