-
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
Showing
4 changed files
with
109 additions
and
76 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 |
---|---|---|
@@ -1,82 +1,91 @@ | ||
import { eventBus } from '../../../shared/lib/eventbus.js'; | ||
import { eventBus } from "../../../shared/lib/eventbus.js"; | ||
import { player } from "../../../shared/player/model/store.js"; | ||
import template from './listenBlock.hbs'; | ||
import * as styles from './listenBlock.scss'; | ||
import playCircleIcon from '../../../../public/images/icons/play-circle.svg'; | ||
import pauseCircleIcon from '../../../../public/images/icons/pause-circle.svg'; | ||
import template from "./listenBlock.hbs"; | ||
import * as styles from "./listenBlock.scss"; | ||
import playCircleIcon from "../../../../public/images/icons/play-circle.svg"; | ||
import pauseCircleIcon from "../../../../public/images/icons/pause-circle.svg"; | ||
|
||
export class ListenBlockView { | ||
/** | ||
* The parent HTML element. | ||
* @type {HTMLElement} | ||
*/ | ||
parent; | ||
/** | ||
* The parent HTML element. | ||
* @type {HTMLElement} | ||
*/ | ||
parent; | ||
|
||
/** | ||
* Initializes the ListenBlockView. | ||
* | ||
*/ | ||
constructor(parent) { | ||
this.parent = parent ? parent : document.querySelector('#root'); | ||
} | ||
/** | ||
* Initializes the ListenBlockView. | ||
* | ||
*/ | ||
constructor(parent) { | ||
this.parent = parent ? parent : document.querySelector("#root"); | ||
} | ||
|
||
/** | ||
* Renders the listen block view. | ||
*/ | ||
async render() { | ||
const listenBlockElement = document.createElement('div'); | ||
listenBlockElement.classList.add('listen'); | ||
listenBlockElement.innerHTML = template({ styles, playCircleIcon, pauseCircleIcon }); | ||
this.parent.appendChild(listenBlockElement); | ||
/** | ||
* Renders the listen block view. | ||
*/ | ||
async render() { | ||
const listenBlockElement = document.createElement("div"); | ||
listenBlockElement.classList.add("listen"); | ||
listenBlockElement.innerHTML = template({ | ||
styles, | ||
playCircleIcon, | ||
pauseCircleIcon, | ||
}); | ||
this.parent.appendChild(listenBlockElement); | ||
|
||
this.getElements(); | ||
this.getElements(); | ||
|
||
this.addEvents(); | ||
this.onEvents(); | ||
} | ||
this.addEvents(); | ||
this.onEvents(); | ||
} | ||
|
||
async getElements() { | ||
this.playPauseBtn = document.querySelector(`.${styles['listen__btn_img']}`); | ||
} | ||
async getElements() { | ||
this.playPauseBtn = document.querySelector(`.${styles["listen__btn_img"]}`); | ||
} | ||
|
||
addEvents() { | ||
this.playPauseBtn.addEventListener('click', this.handlePlayPauseBtn); | ||
} | ||
addEvents() { | ||
this.playPauseBtn.addEventListener("click", this.handlePlayPauseBtn); | ||
} | ||
|
||
deleteEvents() { | ||
this.playPauseBtn.removeEventListener('click', this.handlePlayPauseBtn); | ||
} | ||
deleteEvents() { | ||
this.playPauseBtn.removeEventListener("click", this.handlePlayPauseBtn); | ||
} | ||
|
||
onEvents() { | ||
eventBus.on("playPauseTrack", this.changePlayPauseBtnImg); | ||
eventBus.on("playById", this.changePlayPauseBtnImg); | ||
eventBus.on("nextTrack", this.setPlayBtnImg); | ||
eventBus.on("prevTrack", this.setPlayBtnImg); | ||
} | ||
|
||
offEvents() { | ||
eventBus.off("playPauseTrack", this.changePlayPauseBtnImg); | ||
eventBus.off("playById", this.changePlayPauseBtnImg); | ||
} | ||
onEvents() { | ||
eventBus.on("playPauseTrack", this.changePlayPauseBtnImg); | ||
eventBus.on("playById", this.changePlayPauseBtnImg); | ||
eventBus.on("nextTrack", this.setPlayBtnImg); | ||
eventBus.on("prevTrack", this.setPlayBtnImg); | ||
} | ||
|
||
changePlayPauseBtnImg = () => { | ||
if (player.isPlaying) { | ||
this.playPauseBtn.src = pauseCircleIcon; | ||
} else { | ||
this.playPauseBtn.src = playCircleIcon; | ||
} | ||
} | ||
offEvents() { | ||
eventBus.off("playPauseTrack", this.changePlayPauseBtnImg); | ||
eventBus.off("playById", this.changePlayPauseBtnImg); | ||
} | ||
|
||
setPlayBtnImg = () => { | ||
this.playPauseBtn.src = pauseCircleIcon; | ||
} | ||
changePlayPauseBtnImg = () => { | ||
if (player.isPlaying) { | ||
this.playPauseBtn.src = pauseCircleIcon; | ||
} else { | ||
this.playPauseBtn.src = playCircleIcon; | ||
} | ||
}; | ||
|
||
handlePlayPauseBtn() { | ||
eventBus.emit('playPauseTrack'); | ||
} | ||
setPlayBtnImg = () => { | ||
this.playPauseBtn.src = pauseCircleIcon; | ||
}; | ||
|
||
destructor() { | ||
this.deleteEvents(); | ||
this.offEvents(); | ||
} | ||
handlePlayPauseBtn() { | ||
if (player.queue.length > 0) { | ||
eventBus.emit("reloadTracks"); | ||
eventBus.emit("playById", 0); | ||
} else { | ||
eventBus.emit("playPauseTrack"); | ||
} | ||
} | ||
|
||
destructor() { | ||
this.deleteEvents(); | ||
this.offEvents(); | ||
} | ||
} |
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