diff --git a/src/index.scss b/src/index.scss index c4b33c6..1ac8199 100644 --- a/src/index.scss +++ b/src/index.scss @@ -1,5 +1,5 @@ -@use "./colors.scss"; -@use "./components.scss"; +@use './colors.scss'; +@use './components.scss'; html, body { @@ -8,7 +8,7 @@ body { padding: 0; background: linear-gradient(180deg, #172b7b 0%, #020718 100%); background-attachment: fixed; - font-family: "Comfortaa", sans-serif; + font-family: 'Comfortaa', sans-serif; font-size: 18px; font-weight: 300; margin: 0; @@ -102,8 +102,7 @@ h5 { font-weight: 300; } - -input[type="range"] { +input[type='range'] { -webkit-appearance: none; appearance: none; width: 100%; @@ -114,7 +113,7 @@ input[type="range"] { border-radius: 16px; } -input[type="range"]::-webkit-slider-runnable-track { +input[type='range']::-webkit-slider-runnable-track { height: 15px; background: #ccc; border-radius: 16px; @@ -128,7 +127,7 @@ input[type="range"]::-webkit-slider-runnable-track { } } -input[type="range"]::-moz-range-track { +input[type='range']::-moz-range-track { height: 15px; background: #ccc; border-radius: 16px; @@ -142,15 +141,15 @@ input[type="range"]::-moz-range-track { } } -input[type="range"]::-webkit-slider-thumb { +input[type='range']::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; height: 15px; width: 15px; background-color: #f1f1f1; border-radius: 50%; - border: 2px solid #FF5F0F; - box-shadow: -407px 0 0 400px #FF5F0F; + border: 2px solid #ff5f0f; + box-shadow: -607px 0 0 600px #ff5f0f; @media (max-width: 1024px) { height: 12px; @@ -163,14 +162,15 @@ input[type="range"]::-webkit-slider-thumb { } } - -input[type="range"]::-moz-range-thumb { +input[type='range']::-moz-range-thumb { + -webkit-appearance: none; + appearance: none; height: 15px; width: 15px; background-color: #f1f1f1; border-radius: 50%; - border: 1px solid #FF5F0F; - box-shadow: -407px 0 0 400px #FF5F0F; + border: 2px solid #ff5f0f; + box-shadow: -607px 0 0 600px #ff5f0f; @media (max-width: 1024px) { height: 12px; @@ -181,4 +181,4 @@ input[type="range"]::-moz-range-thumb { height: 10px; width: 10px; } -} \ No newline at end of file +} diff --git a/src/pages/edit-profile/ui/editProfile.js b/src/pages/edit-profile/ui/editProfile.js index dcb89c4..3f23876 100644 --- a/src/pages/edit-profile/ui/editProfile.js +++ b/src/pages/edit-profile/ui/editProfile.js @@ -1,45 +1,50 @@ -import { UploadAvatarView } from "../../../widgets/uploadAvatar/index.js"; -import { EditUserView } from "../../../widgets/editUser/index.js"; -import { userStore } from "../../../entities/user/index.js"; -import { PUBLIC_ERRORS } from "../../../shared/lib/index.js"; -import { eventBus } from "../../../shared/lib/index.js"; +import { UploadAvatarView } from '../../../widgets/uploadAvatar/index.js'; +import { EditUserView } from '../../../widgets/editUser/index.js'; +import { userStore } from '../../../entities/user/index.js'; +import { PUBLIC_ERRORS } from '../../../shared/lib/index.js'; +import { eventBus } from '../../../shared/lib/index.js'; +import { player } from '../../../shared/player/model/store.js'; export class EditProfilePage { - parent; - username; - - constructor(params) { - this.parent = document.querySelector("#root"); - this.username = params["username"]; - } - - async render() { - this.parent.innerHTML = ""; - - await userStore.checkAuth(); - if (!userStore.isAuth()) { - console.error(PUBLIC_ERRORS.UNAUTHORIZED); - return; - } - - const user = userStore.storage.user; - - if (user.username != this.username) { - console.error(PUBLIC_ERRORS.FORBIDDEN); - eventBus.emit("navigate", "/"); - return; - } - - this.pageContent = document.createElement("div"); - this.pageContent.classList.add("page_content"); - this.parent.appendChild(this.pageContent); - - const uploadAvatarView = new UploadAvatarView(this.pageContent, user.id); - await uploadAvatarView.render(); - - const editUserView = new EditUserView(this.pageContent, user.id); - await editUserView.render(); - - eventBus.emit("hidePlayer"); - } + parent; + username; + + constructor(params) { + this.parent = document.querySelector('#root'); + this.username = params['username']; + } + + async render() { + this.parent.innerHTML = ''; + + await userStore.checkAuth(); + if (!userStore.isAuth()) { + console.error(PUBLIC_ERRORS.UNAUTHORIZED); + return; + } + + const user = userStore.storage.user; + + if (user.username != this.username) { + console.error(PUBLIC_ERRORS.FORBIDDEN); + eventBus.emit('navigate', '/'); + return; + } + + this.pageContent = document.createElement('div'); + this.pageContent.classList.add('page_content'); + this.parent.appendChild(this.pageContent); + + const uploadAvatarView = new UploadAvatarView(this.pageContent, user.id); + await uploadAvatarView.render(); + + const editUserView = new EditUserView(this.pageContent, user.id); + await editUserView.render(); + + if (userStore.storage.user.isAuthorized && player.isReady()) { + eventBus.emit('showPlayer'); + } else { + eventBus.emit('hidePlayer'); + } + } } diff --git a/src/pages/more-albums/ui/MoreAlbums.js b/src/pages/more-albums/ui/MoreAlbums.js index 88d2cbe..fca5d8f 100644 --- a/src/pages/more-albums/ui/MoreAlbums.js +++ b/src/pages/more-albums/ui/MoreAlbums.js @@ -4,43 +4,43 @@ import { AlbumListAPI } from '../../../widgets/albumList/index.js'; import { AlbumListView } from '../../../widgets/albumList/index.js'; export class MoreAlbumsPage { - /** - * Creates an instance of the View class. - */ - constructor(params) { - this.parent = document.querySelector('#root'); - this.type = params['type'] - this.entity = params['entity']; - this.entityId = params['id']; - } - - async render() { - this.parent.innerHTML = ''; - - if (this.entity === 'artist') { - this.artistId = this.entityId; - } - - if (this.type === 'favorite') { - this.favorite = this.type; - } + /** + * Creates an instance of the View class. + */ + constructor(params) { + this.parent = document.querySelector('#root'); + this.type = params['type']; + this.entity = params['entity']; + this.entityId = params['id']; + } + + async render() { + this.parent.innerHTML = ''; + + if (this.entity === 'artist') { + this.artistId = this.entityId; + } + + if (this.type === 'favorite') { + this.favorite = this.type; + } this.pageContent = document.createElement('div'); this.pageContent.classList.add('page_content'); this.parent.appendChild(this.pageContent); - const albumListAPI = new AlbumListAPI(this.artistId); - let albums = !this.favorite - ? await albumListAPI.get() - : await albumListAPI.getFavorite(); + const albumListAPI = new AlbumListAPI(this.artistId); + let albums = !this.favorite + ? await albumListAPI.get() + : await albumListAPI.getFavorite(); const albumListView = new AlbumListView(this.pageContent, this.artistId); await albumListView.render(albums, this.favorite); - if (userStore.storage.user.isAuthorized) { - eventBus.emit('showPlayer'); - } else { - eventBus.emit('hidePlayer'); - } + if (userStore.storage.user.isAuthorized && player.isReady()) { + eventBus.emit('showPlayer'); + } else { + eventBus.emit('hidePlayer'); + } } } diff --git a/src/pages/more-artists/ui/MoreArtists.js b/src/pages/more-artists/ui/MoreArtists.js index 3773454..881e5a1 100644 --- a/src/pages/more-artists/ui/MoreArtists.js +++ b/src/pages/more-artists/ui/MoreArtists.js @@ -4,37 +4,37 @@ import { ArtistListAPI } from '../../../widgets/artistList/index.js'; import { ArtistListView } from '../../../widgets/artistList/index.js'; export class MoreArtistsPage { - /** - * Creates an instance of the View class. - */ - constructor(params) { - this.parent = document.querySelector('#root'); - this.type = params['type'] - } + /** + * Creates an instance of the View class. + */ + constructor(params) { + this.parent = document.querySelector('#root'); + this.type = params['type']; + } - async render() { - this.parent.innerHTML = ''; + async render() { + this.parent.innerHTML = ''; - if (this.type === 'favorite') { - this.favorite = this.type; - } + if (this.type === 'favorite') { + this.favorite = this.type; + } this.pageContent = document.createElement('div'); this.pageContent.classList.add('page_content'); this.parent.appendChild(this.pageContent); - const artistListAPI = new ArtistListAPI(); - let artists = !this.favorite - ? await artistListAPI .get() - : await artistListAPI .getFavorite(); + const artistListAPI = new ArtistListAPI(); + let artists = !this.favorite + ? await artistListAPI.get() + : await artistListAPI.getFavorite(); const artistListView = new ArtistListView(this.pageContent); await artistListView.render(artists, this.favorite); - if (userStore.storage.user.isAuthorized) { - eventBus.emit('showPlayer'); - } else { - eventBus.emit('hidePlayer'); - } + if (userStore.storage.user.isAuthorized && player.isReady()) { + eventBus.emit('showPlayer'); + } else { + eventBus.emit('hidePlayer'); + } } } diff --git a/src/pages/more-playlists/ui/morePlaylists.js b/src/pages/more-playlists/ui/morePlaylists.js index a60c4fb..ef7e259 100644 --- a/src/pages/more-playlists/ui/morePlaylists.js +++ b/src/pages/more-playlists/ui/morePlaylists.js @@ -4,37 +4,37 @@ import { PlaylistListAPI } from '../../../widgets/playlistList/index.js'; import { PlaylistListView } from '../../../widgets/playlistList/index.js'; export class MorePlaylistsPage { - /** - * Creates an instance of the View class. - */ - constructor(params) { - this.parent = document.querySelector('#root'); - this.type = params['type'] - } + /** + * Creates an instance of the View class. + */ + constructor(params) { + this.parent = document.querySelector('#root'); + this.type = params['type']; + } async render() { this.parent.innerHTML = ''; - if (this.type === 'favorite') { - this.favorite = this.type; - } + if (this.type === 'favorite') { + this.favorite = this.type; + } this.pageContent = document.createElement('div'); this.pageContent.classList.add('page_content'); this.parent.appendChild(this.pageContent); - const playlistListAPI = new PlaylistListAPI(); - let playlists = !this.favorite - ? await playlistListAPI.get() - : await playlistListAPI.getFavorite(); + const playlistListAPI = new PlaylistListAPI(); + let playlists = !this.favorite + ? await playlistListAPI.get() + : await playlistListAPI.getFavorite(); const playlistListView = new PlaylistListView(this.pageContent); await playlistListView.render(playlists, false, this.favorite); - if (userStore.storage.user.isAuthorized) { - eventBus.emit('showPlayer'); - } else { - eventBus.emit('hidePlayer'); - } - } + if (userStore.storage.user.isAuthorized && player.isReady()) { + eventBus.emit('showPlayer'); + } else { + eventBus.emit('hidePlayer'); + } + } } diff --git a/src/pages/playlist/ui/playlistPage.js b/src/pages/playlist/ui/playlistPage.js index e92753b..73693c4 100644 --- a/src/pages/playlist/ui/playlistPage.js +++ b/src/pages/playlist/ui/playlistPage.js @@ -7,47 +7,53 @@ import { player } from '../../../shared/player/model/store.js'; import { eventBus } from '../../../shared/lib/eventbus.js'; export class PlaylistPage { - parent; - playlistId; - /** - * Creates an instance of the View class. - */ - constructor(params) { - this.parent = document.querySelector('#root'); - this.playlistId = params.playlistId; - } - - async render() { - this.parent.innerHTML = ''; + parent; + playlistId; + /** + * Creates an instance of the View class. + */ + constructor(params) { + this.parent = document.querySelector('#root'); + this.playlistId = params.playlistId; + } + + async render() { + this.parent.innerHTML = ''; this.pageContent = document.createElement('div'); this.pageContent.classList.add('page_content'); this.parent.appendChild(this.pageContent); - const playlistCardView = new PlaylistCardView(this.pageContent, this.playlistId); + const playlistCardView = new PlaylistCardView( + this.pageContent, + this.playlistId, + ); await playlistCardView.render(); - const myPlaylistsAPI = new UserPlaylistsAPI(userStore.storage.user.id); - this.isMyPlaylist = await myPlaylistsAPI.isMyPlaylist(this.playlistId); - //myPlaylistsAPI.isMyPlaylist(this.playlistId); + const myPlaylistsAPI = new UserPlaylistsAPI(userStore.storage.user.id); + this.isMyPlaylist = await myPlaylistsAPI.isMyPlaylist(this.playlistId); + //myPlaylistsAPI.isMyPlaylist(this.playlistId); - const trackListAPI = new TrackListAPI({ playlistId: this.playlistId }); - const tracks = await trackListAPI.get(); - let args; - if (this.isMyPlaylist) { - args = { myPlaylistId: this.playlistId }; - } else { - args = {}; - } + const trackListAPI = new TrackListAPI({ playlistId: this.playlistId }); + const tracks = await trackListAPI.get(); + let args; + if (this.isMyPlaylist) { + args = { myPlaylistId: this.playlistId }; + } else { + args = {}; + } const trackListView = new TrackListView(this.pageContent, args); await trackListView.render(tracks, false); - if (tracks.length > 0 && userStore.storage.user.isAuthorized) { - player.addTracks(tracks); - eventBus.emit('showPlayer'); - } else { - eventBus.emit('hidePlayer'); - } - } + if (tracks.length > 0) { + player.addTracks(tracks); + } + + if (player.isReady() && userStore.storage.user.isAuthorized) { + eventBus.emit('showPlayer'); + } else { + eventBus.emit('hidePlayer'); + } + } } diff --git a/src/pages/profile/ui/profile.js b/src/pages/profile/ui/profile.js index 0ed74fe..3217dcc 100644 --- a/src/pages/profile/ui/profile.js +++ b/src/pages/profile/ui/profile.js @@ -7,16 +7,16 @@ import { UserPlaylistsView } from '../../../widgets/userPlaylists/index.js'; import { eventBus } from '../../../shared/lib/eventbus.js'; export class ProfilePage { - parent; - username; + parent; + username; - constructor(params) { - this.parent = document.querySelector('#root'); - this.username = params['username']; - } + constructor(params) { + this.parent = document.querySelector('#root'); + this.username = params['username']; + } - async render() { - this.parent.innerHTML = ''; + async render() { + this.parent.innerHTML = ''; this.pageContent = document.createElement('div'); this.pageContent.classList.add('page_content'); @@ -26,26 +26,31 @@ export class ProfilePage { await userCardView.render(); this.user = await userStore.getUser(this.username); - const myPlaylistsView = new UserPlaylistsView(this.pageContent, this.user.id); + const myPlaylistsView = new UserPlaylistsView( + this.pageContent, + this.user.id, + ); await myPlaylistsView.render(); - if (this.user.id === userStore.storage.user.id) { - await this.renderFavorites(); - } - } - - async renderFavorites() { - const trackListAPI = new TrackListAPI({ favorite: true }); - const tracks = await trackListAPI.get(); - if (!tracks) return; - if (tracks.length > 0 && userStore.storage.user.isAuthorized) { - const trackListView = new TrackListView(this.pageContent, { favorite: true }); - await trackListView.render(tracks.slice(0, 5)); - trackListView.setTitle('Любимые треки'); - player.addTracks(tracks); - eventBus.emit('showPlayer'); - } else { - eventBus.emit('hidePlayer'); - } - } + await this.renderFavorites(); + if (player.isReady() && userStore.storage.user.isAuthorized) { + eventBus.emit('showPlayer'); + } else { + eventBus.emit('hidePlayer'); + } + } + + async renderFavorites() { + const trackListAPI = new TrackListAPI({ favorite: true }); + const tracks = await trackListAPI.get(); + if (!tracks) return; + if (tracks.length > 0 && userStore.storage.user.isAuthorized) { + const trackListView = new TrackListView(this.pageContent, { + favorite: true, + }); + await trackListView.render(tracks.slice(0, 5)); + trackListView.setTitle('Любимые треки'); + player.addTracks(tracks); + } + } } diff --git a/src/pages/search/ui/Search.js b/src/pages/search/ui/Search.js index b1da084..1882b5c 100644 --- a/src/pages/search/ui/Search.js +++ b/src/pages/search/ui/Search.js @@ -1,135 +1,132 @@ -import { SearchLineView } from "../../../widgets/searchLine/index.js"; -import { ArtistListView } from "../../../widgets/artistList/index.js"; -import { TrackListView } from "../../../widgets/trackList/index.js"; -import { AlbumListView } from "../../../widgets/albumList/index.js"; -import { ErrorView } from "../../../widgets/error/index.js"; -import { player } from "../../../shared/player/model/store.js"; -import { eventBus } from "../../../shared/lib/index.js"; -import { userStore } from "../../../entities/user/index.js"; +import { SearchLineView } from '../../../widgets/searchLine/index.js'; +import { ArtistListView } from '../../../widgets/artistList/index.js'; +import { TrackListView } from '../../../widgets/trackList/index.js'; +import { AlbumListView } from '../../../widgets/albumList/index.js'; +import { ErrorView } from '../../../widgets/error/index.js'; +import { player } from '../../../shared/player/model/store.js'; +import { eventBus } from '../../../shared/lib/index.js'; +import { userStore } from '../../../entities/user/index.js'; export class SearchPage { - /** - * Creates an instance of the View class. - */ - constructor() { - this.parent = document.querySelector("#root"); - this.eventHandlers = { - foundArtists: this.handleFoundArtists.bind(this), - foundAlbums: this.handleFoundAlbums.bind(this), - foundTracks: this.handleFoundTracks.bind(this), - emptySearchResult: this.handleNotFound.bind(this), - }; - } - - async render() { - this.parent.innerHTML = ""; - - this.pageContent = document.createElement("div"); - this.pageContent.classList.add("page_content"); - this.parent.appendChild(this.pageContent); - - const searchLine = new SearchLineView(this.pageContent); - await searchLine.render(); - - this.onEvents(); - if ( - userStore.storage.user.isAuthorized && - (player.isLoaded || player.isPlaying) - ) { - eventBus.emit("showPlayer"); - } else { - eventBus.emit("hidePlayer"); - } - } - - onEvents() { - Object.keys(this.eventHandlers).forEach((event) => { - eventBus.on(event, this.eventHandlers[event]); - }); - } - - offEvents() { - Object.keys(this.eventHandlers).forEach((event) => { - eventBus.off(event, this.eventHandlers[event]); - }); - } - - async handleFoundArtists(artists) { - const errorElement = document.querySelector(".error"); - if (errorElement) { - errorElement.remove(); - } - - const artistsElement = document.querySelector(".artists"); - if (artistsElement) { - artistsElement.remove(); - } - - if (!artists) { - return; - } - - const artistListView = new ArtistListView(this.pageContent); - await artistListView.render(artists); - } - - async handleFoundAlbums(albums) { - const errorElement = document.querySelector(".error"); - if (errorElement) { - errorElement.remove(); - } - - const albumsElement = document.querySelector(".albums"); - if (albumsElement) { - albumsElement.remove(); - } - - if (!albums) { - return; - } - - const albumListView = new AlbumListView(this.pageContent); - await albumListView.render(albums); - } - - async handleFoundTracks(tracks) { - if (tracks.length > 0) { - player.addTracks(tracks); - } - - const errorElement = document.querySelector(".error"); - if (errorElement) { - errorElement.remove(); - } - - const tracksElement = document.querySelector(".tracks"); - if (tracksElement) { - tracksElement.remove(); - } - - if (!tracks) { - return; - } - - const trackListView = new TrackListView(this.pageContent); - await trackListView.render(tracks, false); - } - - async handleNotFound() { - const errorElement = document.querySelector(".error"); - if (errorElement) { - errorElement.remove(); - } - - const errorView = new ErrorView( - null, - "Ничего не найдено", - "Попробуйте поискать что-то другое.", - ); - await errorView.render(); - } - - destructor() { - this.offEvents(); - } + /** + * Creates an instance of the View class. + */ + constructor() { + this.parent = document.querySelector('#root'); + this.eventHandlers = { + foundArtists: this.handleFoundArtists.bind(this), + foundAlbums: this.handleFoundAlbums.bind(this), + foundTracks: this.handleFoundTracks.bind(this), + emptySearchResult: this.handleNotFound.bind(this), + }; + } + + async render() { + this.parent.innerHTML = ''; + + this.pageContent = document.createElement('div'); + this.pageContent.classList.add('page_content'); + this.parent.appendChild(this.pageContent); + + const searchLine = new SearchLineView(this.pageContent); + await searchLine.render(); + + this.onEvents(); + if (userStore.storage.user.isAuthorized && player.isReady()) { + eventBus.emit('showPlayer'); + } else { + eventBus.emit('hidePlayer'); + } + } + + onEvents() { + Object.keys(this.eventHandlers).forEach((event) => { + eventBus.on(event, this.eventHandlers[event]); + }); + } + + offEvents() { + Object.keys(this.eventHandlers).forEach((event) => { + eventBus.off(event, this.eventHandlers[event]); + }); + } + + async handleFoundArtists(artists) { + const errorElement = document.querySelector('.error'); + if (errorElement) { + errorElement.remove(); + } + + const artistsElement = document.querySelector('.artists'); + if (artistsElement) { + artistsElement.remove(); + } + + if (!artists) { + return; + } + + const artistListView = new ArtistListView(this.pageContent); + await artistListView.render(artists); + } + + async handleFoundAlbums(albums) { + const errorElement = document.querySelector('.error'); + if (errorElement) { + errorElement.remove(); + } + + const albumsElement = document.querySelector('.albums'); + if (albumsElement) { + albumsElement.remove(); + } + + if (!albums) { + return; + } + + const albumListView = new AlbumListView(this.pageContent); + await albumListView.render(albums); + } + + async handleFoundTracks(tracks) { + if (tracks.length > 0) { + player.addTracks(tracks); + } + + const errorElement = document.querySelector('.error'); + if (errorElement) { + errorElement.remove(); + } + + const tracksElement = document.querySelector('.tracks'); + if (tracksElement) { + tracksElement.remove(); + } + + if (!tracks) { + return; + } + + const trackListView = new TrackListView(this.pageContent); + await trackListView.render(tracks, false); + } + + async handleNotFound() { + const errorElement = document.querySelector('.error'); + if (errorElement) { + errorElement.remove(); + } + + const errorView = new ErrorView( + null, + 'Ничего не найдено', + 'Попробуйте поискать что-то другое.', + ); + await errorView.render(); + } + + destructor() { + this.offEvents(); + } } diff --git a/src/pages/subscriptions/ui/subscriptions.js b/src/pages/subscriptions/ui/subscriptions.js index d6e008a..3c01db4 100644 --- a/src/pages/subscriptions/ui/subscriptions.js +++ b/src/pages/subscriptions/ui/subscriptions.js @@ -1,79 +1,80 @@ -import { player } from "../../../shared/player/model/store"; -import { userStore } from "../../../entities/user"; -import { eventBus } from "../../../shared/lib"; -import { ErrorView } from "../../../widgets/error/index.js"; -import { - AlbumCarouselView, - AlbumCarouselAPI -} from "../../../widgets/albumCarousel/index.js"; -import { - ArtistCarouselView, - ArtistCarouselAPI -} from "../../../widgets/artistCarousel/index.js"; +import { player } from '../../../shared/player/model/store'; +import { userStore } from '../../../entities/user'; +import { eventBus } from '../../../shared/lib'; +import { ErrorView } from '../../../widgets/error/index.js'; import { - PlaylistListAPI, - PlaylistListView, -} from "../../../widgets/playlistList/index.js"; + AlbumCarouselView, + AlbumCarouselAPI, +} from '../../../widgets/albumCarousel/index.js'; +import { + ArtistCarouselView, + ArtistCarouselAPI, +} from '../../../widgets/artistCarousel/index.js'; +import { + PlaylistListAPI, + PlaylistListView, +} from '../../../widgets/playlistList/index.js'; export class SubscriptionsPage { - /** - * Creates an instance of the View class. - */ - constructor() { - this.parent = document.querySelector("#root"); - } + /** + * Creates an instance of the View class. + */ + constructor() { + this.parent = document.querySelector('#root'); + } - async render() { - await userStore.checkAuth(); - if (!userStore.isAuth()) { - return; - } + async render() { + await userStore.checkAuth(); + if (!userStore.isAuth()) { + return; + } - this.parent.innerHTML = ""; + this.parent.innerHTML = ''; - this.pageContent = document.createElement("div"); - this.pageContent.classList.add("page_content"); - this.parent.appendChild(this.pageContent); + this.pageContent = document.createElement('div'); + this.pageContent.classList.add('page_content'); + this.parent.appendChild(this.pageContent); - const artistCarouselAPI = new ArtistCarouselAPI(); - const artistCarouselView = new ArtistCarouselView(this.pageContent, { - favorite: true, - }); - const artists = await artistCarouselAPI.getFavorite(); - if (artists) { - await artistCarouselView.render(artists); - } + const artistCarouselAPI = new ArtistCarouselAPI(); + const artistCarouselView = new ArtistCarouselView(this.pageContent, { + favorite: true, + }); + const artists = await artistCarouselAPI.getFavorite(); + if (artists) { + await artistCarouselView.render(artists); + } - const albumCarouselAPI = new AlbumCarouselAPI(); - const albumCarouselView = new AlbumCarouselView(this.pageContent, null, true); - const albums = await albumCarouselAPI.getFavorite(); - if (albums) { - await albumCarouselView.render(albums); - } + const albumCarouselAPI = new AlbumCarouselAPI(); + const albumCarouselView = new AlbumCarouselView( + this.pageContent, + null, + true, + ); + const albums = await albumCarouselAPI.getFavorite(); + if (albums) { + await albumCarouselView.render(albums); + } - const playlistListAPI = new PlaylistListAPI(); - const playlistListView = new PlaylistListView(this.pageContent); - const playlists = await playlistListAPI.getFavorite(); - if (playlists) { - await playlistListView.render(playlists.slice(0, 5), true, true); - } + const playlistListAPI = new PlaylistListAPI(); + const playlistListView = new PlaylistListView(this.pageContent); + const playlists = await playlistListAPI.getFavorite(); + if (playlists) { + await playlistListView.render(playlists.slice(0, 5), true, true); + } - if (!artists && !albums && !playlists) { - const errorView = new ErrorView( - null, - "У вас пока нед подписок", - "Здесь можно увидеть подписки на артистов, альбомы и плейлисты", - ); - await errorView.render(); - } + if (!artists && !albums && !playlists) { + const errorView = new ErrorView( + null, + 'У вас пока нед подписок', + 'Здесь можно увидеть подписки на артистов, альбомы и плейлисты', + ); + await errorView.render(); + } - if ( - userStore.storage.user.isAuthorized && - (player.isLoaded || player.isPlaying) - ) { - eventBus.emit("showPlayer"); - } else { - eventBus.emit("hidePlayer"); - } - } + if (userStore.storage.user.isAuthorized && player.isReady()) { + eventBus.emit('showPlayer'); + } else { + eventBus.emit('hidePlayer'); + } + } } diff --git a/src/shared/config/api.js b/src/shared/config/api.js index 7c776ab..06cfaaa 100644 --- a/src/shared/config/api.js +++ b/src/shared/config/api.js @@ -1,21 +1,21 @@ // export const BASE_URL = "http://localhost:8080"; -/* export const API_USER_URL = "http://localhost:8080"; -export const API_ALBUM_URL = "http://localhost:8080"; -export const API_ARTIST_URL = "http://localhost:8080"; -export const API_PLAYLIST_URL = "http://localhost:8080"; -export const API_TRACK_URL = "http://localhost:8080"; -export const API_GENRE_URL = "http://localhost:8080"; -export const API_CSAT_URL = "http://localhost:8080"; -export const S3_URL = "http://localhost:8010"; */ +// export const API_USER_URL = 'http://localhost:8080'; +// export const API_ALBUM_URL = 'http://localhost:8080'; +// export const API_ARTIST_URL = 'http://localhost:8080'; +// export const API_PLAYLIST_URL = 'http://localhost:8080'; +// export const API_TRACK_URL = 'http://localhost:8080'; +// export const API_GENRE_URL = 'http://localhost:8080'; +// export const API_CSAT_URL = 'http://localhost:8080'; +// export const S3_URL = 'http://localhost:8010'; -export const BASE_URL = "https://nova-music.ru"; +export const BASE_URL = 'https://nova-music.ru'; -export const API_USER_URL = "https://nova-music.ru"; -export const API_ALBUM_URL = "https://nova-music.ru"; -export const API_ARTIST_URL = "https://nova-music.ru:"; -export const API_PLAYLIST_URL = "https://nova-music.ru"; -export const API_TRACK_URL = "https://nova-music.ru"; -export const API_GENRE_URL = "https://nova-music.ru"; -export const API_CSAT_URL = "https://nova-music.ru"; -export const S3_URL = "https://nova-music.ru:8010"; +export const API_USER_URL = 'https://nova-music.ru'; +export const API_ALBUM_URL = 'https://nova-music.ru'; +export const API_ARTIST_URL = 'https://nova-music.ru:'; +export const API_PLAYLIST_URL = 'https://nova-music.ru'; +export const API_TRACK_URL = 'https://nova-music.ru'; +export const API_GENRE_URL = 'https://nova-music.ru'; +export const API_CSAT_URL = 'https://nova-music.ru'; +export const S3_URL = 'https://nova-music.ru:8010'; diff --git a/src/shared/player/model/store.js b/src/shared/player/model/store.js index 638d8ea..64a1d71 100644 --- a/src/shared/player/model/store.js +++ b/src/shared/player/model/store.js @@ -1,181 +1,185 @@ -import { eventBus } from "../../../shared/lib/index.js"; -import { DEFAULT_PLAYER_VOLUME } from "../../lib/constants/player.js"; -import { S3_BUCKETS } from "../../../shared/lib/index.js"; +import { eventBus } from '../../../shared/lib/index.js'; +import { DEFAULT_PLAYER_VOLUME } from '../../lib/constants/player.js'; +import { S3_BUCKETS } from '../../../shared/lib/index.js'; import { - PLAYER_PAUSED_STATE, - PLAYER_PLAYING_STATE, - PLAYER_STATE, -} from "../../lib/constants/player.js"; + PLAYER_PAUSED_STATE, + PLAYER_PLAYING_STATE, + PLAYER_STATE, +} from '../../lib/constants/player.js'; class PlayerStore { - constructor() { - this.currentIndex = -1; - this.isPlaying = false; - this.isLoaded = false; - - this.sessionID = `session_${Date.now()}_${Math.random().toString(36).substring(2)}`; - this.queue = []; - this.tracks = []; - this.currentTrack = document.createElement("audio"); - this.currentTrack.volume = DEFAULT_PLAYER_VOLUME; - - this.onEvents(); - window.addEventListener("storage", this.storageHandler); - window.addEventListener("beforeunload", this.beforeUnloadHandler); - } - - clearTracks() { - this.currentTrack.pause(); - this.tracks = []; - } - - addTracks(tracks) { - this.isLoaded = false; - if (this.tracks.length == 0) { - this.tracks = tracks; - this.setTracks(); - } else { - this.queue = tracks; - } - } - - setTracks() { - this.currentIndex = 0; - this.loadTrack(); - } - - getTrackInfo() { - return this.tracks[this.currentIndex]; - } - - onEvents() { - eventBus.on("playPauseTrack", this.onPlayPauseTrack); - eventBus.on("playById", this.onPlayById); - eventBus.on("nextTrack", this.onNextTrack); - eventBus.on("prevTrack", this.onPrevTrack); - eventBus.on("reloadTracks", this.onReloadTracks); - } - - offEvents() { - eventBus.off("playPauseTrack", this.onPlayPauseTrack); - eventBus.off("playById", this.onPlayById); - eventBus.off("nextTrack", this.onNextTrack); - eventBus.off("prevTrack", this.onPrevTrack); - eventBus.off("reloadTracks", this.onReloadTracks); - } - - loadTrack() { - this.currentTrack.src = `${S3_BUCKETS.TRACK_FILES}/${this.tracks[this.currentIndex].filepath}`; - this.currentTrack.load(); - this.currentTrack.addEventListener("ended", this.onNextTrack); - eventBus.emit("loadingTrack"); - } - - setTime(time) { - this.currentTrack.currentTime = time; - } - - getTime() { - return this.currentTrack.currentTime; - } - - setVolume(volume) { - this.currentTrack.volume = volume; - } - - getVolume() { - return this.currentTrack.volume; - } - - getDuration() { - return this.currentTrack.duration; - } - - isPaused() { - return this.currentTrack.paused; - } - - onReloadTracks = () => { - if (!this.isLoaded && this.queue.length > 0) { - this.clearTracks(); - this.tracks = this.queue; - this.queue = []; - this.isLoaded = true; - } - }; - - onPlayPauseTrack = () => { - if (this.isPlaying) { - this.currentTrack.pause(); - this.isPlaying = false; - } else { - this.currentTrack.play(); - this.isPlaying = true; - } - this.onChangeState(); - }; - - onPlayById = (index) => { - this.currentTrack.pause(); - this.currentIndex = index; - this.loadTrack(); - this.currentTrack.play(); - this.isPlaying = true; - this.onChangeState(); - }; - - onNextTrack = () => { - this.currentIndex = - this.currentIndex + 1 >= this.tracks.length ? 0 : this.currentIndex + 1; - this.loadTrack(); - this.currentTrack.play(); - this.isPlaying = true; - this.onChangeState(); - }; - - onPrevTrack = () => { - this.currentIndex = - this.currentIndex - 1 < 0 - ? this.tracks.length - 1 - : this.currentIndex - 1; - this.loadTrack(); - this.currentTrack.play(); - this.isPlaying = true; - this.onChangeState(); - }; - - onChangeState = () => { - const state = { - sessionID: this.sessionID, - status: this.isPaused() ? PLAYER_PAUSED_STATE : PLAYER_PLAYING_STATE, - }; - localStorage.setItem(PLAYER_STATE, JSON.stringify(state)); - }; - - storageHandler = (event) => { - if (event.key === PLAYER_STATE) { - const state = JSON.parse(event.newValue); - if ( - state && - state.sessionID !== this.sessionID && - state.status === PLAYER_PLAYING_STATE && - this.isPlaying - ) { - this.currentTrack.pause(); - this.isPlaying = false; - } - } - }; - - beforeUnloadHandler = () => { - localStorage.removeItem(PLAYER_STATE); - }; - - destructor() { - this.offEvents(); - window.removeEventListener("storage", this.storageHandler); - window.removeEventListener("beforeunload", this.beforeUnloadHandler); - } + constructor() { + this.currentIndex = -1; + this.isPlaying = false; + this.isLoaded = false; + + this.sessionID = `session_${Date.now()}_${Math.random().toString(36).substring(2)}`; + this.queue = []; + this.tracks = []; + this.currentTrack = document.createElement('audio'); + this.currentTrack.volume = DEFAULT_PLAYER_VOLUME; + + this.onEvents(); + window.addEventListener('storage', this.storageHandler); + window.addEventListener('beforeunload', this.beforeUnloadHandler); + } + + clearTracks() { + this.currentTrack.pause(); + this.tracks = []; + } + + addTracks(tracks) { + this.isLoaded = false; + if (this.tracks.length == 0) { + this.tracks = tracks; + this.setTracks(); + } else { + this.queue = tracks; + } + } + + isReady() { + return this.isPlaying || this.tracks.length > 0; + } + + setTracks() { + this.currentIndex = 0; + this.loadTrack(); + } + + getTrackInfo() { + return this.tracks[this.currentIndex]; + } + + onEvents() { + eventBus.on('playPauseTrack', this.onPlayPauseTrack); + eventBus.on('playById', this.onPlayById); + eventBus.on('nextTrack', this.onNextTrack); + eventBus.on('prevTrack', this.onPrevTrack); + eventBus.on('reloadTracks', this.onReloadTracks); + } + + offEvents() { + eventBus.off('playPauseTrack', this.onPlayPauseTrack); + eventBus.off('playById', this.onPlayById); + eventBus.off('nextTrack', this.onNextTrack); + eventBus.off('prevTrack', this.onPrevTrack); + eventBus.off('reloadTracks', this.onReloadTracks); + } + + loadTrack() { + this.currentTrack.src = `${S3_BUCKETS.TRACK_FILES}/${this.tracks[this.currentIndex].filepath}`; + this.currentTrack.load(); + this.currentTrack.addEventListener('ended', this.onNextTrack); + eventBus.emit('loadingTrack'); + } + + setTime(time) { + this.currentTrack.currentTime = time; + } + + getTime() { + return this.currentTrack.currentTime; + } + + setVolume(volume) { + this.currentTrack.volume = volume; + } + + getVolume() { + return this.currentTrack.volume; + } + + getDuration() { + return this.currentTrack.duration; + } + + isPaused() { + return this.currentTrack.paused; + } + + onReloadTracks = () => { + if (!this.isLoaded && this.queue.length > 0) { + this.clearTracks(); + this.tracks = this.queue; + this.queue = []; + this.isLoaded = true; + } + }; + + onPlayPauseTrack = () => { + if (this.isPlaying) { + this.currentTrack.pause(); + this.isPlaying = false; + } else { + this.currentTrack.play(); + this.isPlaying = true; + } + this.onChangeState(); + }; + + onPlayById = (index) => { + this.currentTrack.pause(); + this.currentIndex = index; + this.loadTrack(); + this.currentTrack.play(); + this.isPlaying = true; + this.onChangeState(); + }; + + onNextTrack = () => { + this.currentIndex = + this.currentIndex + 1 >= this.tracks.length ? 0 : this.currentIndex + 1; + this.loadTrack(); + this.currentTrack.play(); + this.isPlaying = true; + this.onChangeState(); + }; + + onPrevTrack = () => { + this.currentIndex = + this.currentIndex - 1 < 0 + ? this.tracks.length - 1 + : this.currentIndex - 1; + this.loadTrack(); + this.currentTrack.play(); + this.isPlaying = true; + this.onChangeState(); + }; + + onChangeState = () => { + const state = { + sessionID: this.sessionID, + status: this.isPaused() ? PLAYER_PAUSED_STATE : PLAYER_PLAYING_STATE, + }; + localStorage.setItem(PLAYER_STATE, JSON.stringify(state)); + }; + + storageHandler = (event) => { + if (event.key === PLAYER_STATE) { + const state = JSON.parse(event.newValue); + if ( + state && + state.sessionID !== this.sessionID && + state.status === PLAYER_PLAYING_STATE && + this.isPlaying + ) { + this.currentTrack.pause(); + this.isPlaying = false; + } + } + }; + + beforeUnloadHandler = () => { + localStorage.removeItem(PLAYER_STATE); + }; + + destructor() { + this.offEvents(); + window.removeEventListener('storage', this.storageHandler); + window.removeEventListener('beforeunload', this.beforeUnloadHandler); + } } export const player = new PlayerStore();