-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
10 changed files
with
113 additions
and
192 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 |
---|---|---|
@@ -1,89 +1,40 @@ | ||
import {remove, render, replace} from '../framework/render.js'; | ||
import { render, replace, remove } from '../framework/render.js'; | ||
import FilterView from '../view/filter-view.js'; | ||
import {UpdateType} from '../mock/const.js'; | ||
// import {FilterType} from '../model/filter-model.js'; | ||
import {filter} from '../utils.js'; | ||
import { UpdateType } from '../const.js'; | ||
|
||
export default class FilterPresenter{ | ||
#container = null; | ||
#filterComponent = null; | ||
|
||
#pointsModel = null; | ||
export default class FilterPresenter { | ||
#filterContainer = null; | ||
#filterModel = null; | ||
#filterComponent = null; | ||
|
||
#currentFilter = null; | ||
|
||
constructor({container, pointsModel, filterModel}) { | ||
this.#container = container; | ||
this.#pointsModel = pointsModel; | ||
constructor(filterContainer, filterModel) { | ||
this.#filterContainer = filterContainer; | ||
this.#filterModel = filterModel; | ||
|
||
this.#pointsModel.addObserver(this.#modelEventHandler); | ||
this.#filterModel.addObserver(this.#modelEventHandler); | ||
} | ||
|
||
get filters() { | ||
const points = this.#pointsModel.get(); | ||
|
||
return Object.entries(filter) | ||
.map(([filterType, filterPoints]) => ({ | ||
type: filterType, | ||
isChecked: filterType === this.#currentFilter, | ||
isDisable: filterPoints(points.length) === 0 | ||
})); | ||
init() { | ||
this.#renderFilters(); | ||
} | ||
|
||
// get filters() { | ||
// const points = this.#pointsModel.points; | ||
|
||
// return [ | ||
// { | ||
// type: FilterType.EVERYTHING, | ||
// name: 'EVERYTHING', | ||
// count: filter[FilterType.EVERYTHING](points).length, | ||
// }, | ||
// { | ||
// type: FilterType.PAST, | ||
// name: 'PAST', | ||
// count: filter[FilterType.PAST](points).length, | ||
// }, | ||
// { | ||
// type: FilterType.FUTURE, | ||
// name: 'FUTURE', | ||
// count: filter[FilterType.FUTURE](points).length, | ||
// } | ||
// ]; | ||
// } | ||
|
||
init(){ | ||
this.#currentFilter = this.#filterModel.get(); | ||
remove() { | ||
remove(this.#filterComponent); | ||
} | ||
|
||
const filters = this.filters; | ||
const prevFilterComponent = this.#filterComponent; | ||
#renderFilters = () => { | ||
const previousFilterComponent = this.#filterComponent; | ||
|
||
this.#filterComponent = new FilterView({ | ||
items: filters, | ||
onItemChange: this.#filterTypeChangeHandler | ||
}); | ||
this.#filterComponent = new FilterView( | ||
this.#filterModel.get(), | ||
this.#filterChangeHandler | ||
); | ||
|
||
if (prevFilterComponent === null) { | ||
render(this.#filterComponent, this.#container); | ||
if (!previousFilterComponent) { | ||
render(this.#filterComponent, this.#filterContainer); | ||
return; | ||
} | ||
|
||
replace(this.#filterComponent, prevFilterComponent); | ||
remove(prevFilterComponent); | ||
} | ||
|
||
#filterTypeChangeHandler = (filterType) => { | ||
// if (filterType === this.#filterModel.filter) { | ||
// return; | ||
// } | ||
|
||
this.#filterModel.set(UpdateType.MAJOR, filterType); | ||
replace(this.#filterComponent, previousFilterComponent); | ||
}; | ||
|
||
#modelEventHandler = () => { | ||
this.init(); | ||
}; | ||
#filterChangeHandler = (filterType) => this.#filterModel.set(UpdateType.MAJOR, filterType); | ||
} |
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
Oops, something went wrong.