-
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.
Merge pull request #7 from MaxSiryatov/module5-task1
- Loading branch information
Showing
35 changed files
with
214 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,3 +72,4 @@ export default class UiBlocker { | |
this.#element.classList.remove('ui-blocker--on'); | ||
}; | ||
} | ||
|
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 |
---|---|---|
|
@@ -10,4 +10,4 @@ function getRandomDestination() { | |
}); | ||
} | ||
|
||
export {getRandomDestination}; | ||
export {getRandomDestination}; |
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 |
---|---|---|
|
@@ -10,4 +10,4 @@ function getRandomOffer() { | |
}); | ||
} | ||
|
||
export {getRandomOffer}; | ||
export {getRandomOffer}; |
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 |
---|---|---|
|
@@ -14,4 +14,4 @@ function getRandomPoint(destinationID, offersID) { | |
}); | ||
} | ||
|
||
export {getRandomPoint}; | ||
export {getRandomPoint}; |
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 |
---|---|---|
|
@@ -27,4 +27,4 @@ export default class DestinationModel { | |
}); | ||
return temp; | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -33,4 +33,4 @@ export default class PointModel { | |
getPoint() { | ||
return this.points[0]; | ||
} | ||
} | ||
} |
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,116 @@ | ||
import PointEditView from '../view/point-edit-view.js'; | ||
import PointView from '../view/point-view.js'; | ||
import OpenFormBtnView from '../view/open-form-button-view.js'; | ||
import CloseFormBtnView from '../view/close-form-button-view.js'; | ||
import SaveFormBtnView from '../view/save-form-button-view.js'; | ||
import { RenderPosition, remove, render, replace } from '../framework/render.js'; | ||
import { Mode } from '../const.js'; | ||
|
||
export default class PointPresenter { | ||
|
||
#pointsListView; | ||
#handlePointChange; | ||
#handleModeChange; | ||
|
||
#point; | ||
#mode = Mode.DEFAULT; | ||
|
||
#pointComponent; | ||
#pointEditComponent; | ||
|
||
constructor ({pointListContainer, onDataChange, onModeChange}) { | ||
this.#pointsListView = pointListContainer; | ||
this.#handlePointChange = onDataChange; | ||
this.#handleModeChange = onModeChange; | ||
} | ||
|
||
init(point) { | ||
this.#point = point; | ||
|
||
const prevPointComponent = this.#pointComponent; | ||
const prevEditFormComponent = this.#pointEditComponent; | ||
|
||
const escKeyDownHandler = (evt) => { | ||
if (evt.key === 'Escape') { | ||
this.#replacePointToEditForm(); | ||
document.removeEventListener('keydown', escKeyDownHandler); | ||
} | ||
}; | ||
|
||
this.#pointComponent = new PointView({ | ||
data: this.#point, | ||
onFavouriteClick: this.#onFavouriteClick, | ||
}); | ||
|
||
this.#pointEditComponent = new PointEditView({ | ||
data: this.#point, | ||
onSubmit: () => { | ||
this.#replaceEditFormToPoint(); | ||
document.removeEventListener('keydown', escKeyDownHandler); | ||
} | ||
}); | ||
|
||
const deleteBtn = this.#pointEditComponent.element.querySelector('.event__reset-btn'); | ||
|
||
const openBtn = new OpenFormBtnView({ | ||
onClick: () => { | ||
this.#replacePointToEditForm(); | ||
document.addEventListener('keydown', escKeyDownHandler); | ||
}}); | ||
|
||
const closeBtn = new CloseFormBtnView({ | ||
onClick: () => { | ||
this.#replaceEditFormToPoint(); | ||
document.removeEventListener('keydown', escKeyDownHandler); | ||
}}); | ||
|
||
const saveBtn = new SaveFormBtnView(); | ||
|
||
render(openBtn, this.#pointComponent.element, RenderPosition.BEFOREEND); | ||
render(saveBtn, deleteBtn, RenderPosition.BEFOREBEGIN); | ||
render(closeBtn, deleteBtn, RenderPosition.AFTEREND); | ||
|
||
if (!prevPointComponent || !prevEditFormComponent) { | ||
render(this.#pointComponent, this.#pointsListView); | ||
return; | ||
} | ||
|
||
if (this.#mode === Mode.DEFAULT) { | ||
replace(this.#pointComponent, prevPointComponent); | ||
} | ||
|
||
if (this.#mode === Mode.EDITING) { | ||
replace(this.#pointEditComponent, prevEditFormComponent); | ||
} | ||
|
||
remove(prevEditFormComponent); | ||
remove(prevPointComponent); | ||
} | ||
|
||
resetView() { | ||
if (this.#mode === Mode.EDITING) { | ||
this.#replaceEditFormToPoint(); | ||
} | ||
} | ||
|
||
destroy() { | ||
remove(this.#pointComponent); | ||
remove(this.#pointEditComponent); | ||
} | ||
|
||
#replaceEditFormToPoint() { | ||
replace(this.#pointComponent, this.#pointEditComponent); | ||
this.#mode = Mode.DEFAULT; | ||
} | ||
|
||
#replacePointToEditForm() { | ||
replace(this.#pointEditComponent, this.#pointComponent); | ||
this.#handleModeChange(); | ||
this.#mode = Mode.EDITING; | ||
} | ||
|
||
#onFavouriteClick = () => { | ||
this.#handlePointChange({...this.#point, isFavorite: !this.#point.isFavorite}); | ||
}; | ||
|
||
} |
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,6 @@ | ||
export function createCloseFormBtn() { | ||
return `<button class="event__rollup-btn" type="button"> | ||
<span class="visually-hidden">Open event</span> | ||
</button>`; | ||
} | ||
|
||
Check failure on line 6 in src/templates/close-form-button-template.js GitHub Actions / Check
|
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,3 @@ | ||
export function createEmptyPointsListTemplate() { | ||
return '<p class="trip-events__msg">Click New Event to create your first point</p>'; | ||
} | ||
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,5 @@ | ||
export function createOpenFormBtn() { | ||
return `<button class="event__rollup-btn" type="button"> | ||
<span class="visually-hidden">Open event</span> | ||
</button>`; | ||
} |
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,3 @@ | ||
export function createSaveFormBtn() { | ||
return '<button class="event__save-btn btn btn--blue" type="submit">Save</button>'; | ||
} |
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 |
---|---|---|
|
@@ -23,4 +23,4 @@ const createSortTemplate = () => ` | |
</form> | ||
`; | ||
|
||
export {createSortTemplate}; | ||
export {createSortTemplate}; |
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.