-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sergei Pozdeev
committed
Sep 23, 2024
1 parent
07879bc
commit 2f972a3
Showing
12 changed files
with
85 additions
and
50 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { FilterType } from '../constants.js'; | ||
import { isDatePast, isDatePresent, isDateFuture } from '../util/utils.js'; | ||
|
||
const filter = { | ||
[FilterType.EVERYTHING]: (points) => points, | ||
[FilterType.FUTURE]: (points) => points.filter((point) => isDateFuture(point.dateFrom)), | ||
[FilterType.PRESENT]: (points) => points.filter((point) => isDatePresent(point.dateFrom, point.dateTo)), | ||
[FilterType.PAST]: (points) => points.filter((point) => isDatePast(point.dateTo)) | ||
}; | ||
|
||
export function generateFilter(points) { | ||
return Object.entries(filter).map(([filterType, filterPoints]) => ({ | ||
type: filterType, | ||
count: filterPoints(points).length, | ||
})); | ||
} |
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
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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import AbstractView from '../framework/view/abstract-view.js'; | ||
|
||
const createEventsMessageTemplate = () => ` | ||
<p class="trip-events__msg"></p>`; | ||
const createEventsMessageTemplate = (message) => ` | ||
<p class="trip-events__msg">${message}</p>`; | ||
|
||
export default class EventsMessageView extends AbstractView { | ||
#message = null; | ||
|
||
constructor({message}) { | ||
super(); | ||
this.#message = message; | ||
} | ||
|
||
get template() { | ||
return createEventsMessageTemplate(); | ||
return createEventsMessageTemplate(this.#message); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,27 +1,33 @@ | ||
import AbstractView from '../framework/view/abstract-view.js'; | ||
import { getCapitalized } from '../utils.js'; | ||
import { FILTER_TYPES } from '../constants.js'; | ||
import { getCapitalized } from '../util/utils.js'; | ||
|
||
const createTripFilterTypeTemplate = (filter) => ` | ||
const createTripFilterTypeTemplate = (filter, isChecked) => ` | ||
<div class="trip-filters__filter"> | ||
<input id="filter-${filter.type}" class="trip-filters__filter-input visually-hidden" type="radio" name="trip-filter" value="${filter.type}" ${filter.checked ? 'checked' : ''}> | ||
<input id="filter-${filter.type}" class="trip-filters__filter-input visually-hidden" type="radio" name="trip-filter" value="${filter.type}" ${isChecked ? 'checked' : ''} ${filter.count === 0 ? 'disabled' : ''}> | ||
<label class="trip-filters__filter-label" for="filter-${filter.type}">${getCapitalized(filter.type)}</label> | ||
</div>`; | ||
|
||
const createFiltersTemplate = () => ` | ||
const createFiltersTemplate = (filters) => ` | ||
<div class="trip-main__trip-controls trip-controls"> | ||
<div class="trip-controls__filters"> | ||
<h2 class="visually-hidden">Filter events</h2> | ||
<form class="trip-filters" action="#" method="get"> | ||
${FILTER_TYPES.map((filter) => createTripFilterTypeTemplate(filter)).join('')} | ||
${filters.map((filter, index) => createTripFilterTypeTemplate(filter, index === 0)).join('')} | ||
<button class="visually-hidden" type="submit">Accept filter</button> | ||
</form> | ||
</div> | ||
</div>`; | ||
|
||
export default class FiltersView extends AbstractView { | ||
#filters = []; | ||
|
||
constructor({filters}) { | ||
super(); | ||
this.#filters = filters; | ||
} | ||
|
||
get template() { | ||
return createFiltersTemplate(); | ||
return createFiltersTemplate(this.#filters); | ||
} | ||
} |