Skip to content

Commit

Permalink
not empty subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
bocharovatd committed Dec 16, 2024
1 parent 545a0e9 commit 4c39a0f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 24 deletions.
13 changes: 9 additions & 4 deletions src/pages/artist/ui/Artist.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { TrackListAPI } from '../../../widgets/trackList/index.js';
import { ArtistCardView } from '../../../widgets/artistCard/index.js';
import { TrackListView } from '../../../widgets/trackList/index.js';
import { AlbumCarouselView } from '../../../widgets/albumCarousel/index.js';
import {
TrackListView,
TrackListAPI } from '../../../widgets/trackList/index.js';
import {
AlbumCarouselView,
AlbumCarouselAPI } from '../../../widgets/albumCarousel/index.js';
import { player } from '../../../shared/player/model/store.js';
import { eventBus } from '../../../shared/lib/eventbus.js';
import { userStore } from '../../../entities/user/index.js';
Expand Down Expand Up @@ -38,6 +41,8 @@ export class ArtistPage {
}

const albumCarouselView = new AlbumCarouselView(this.pageContent, this.artistId);
await albumCarouselView.render();
const albumCarouselAPI = new AlbumCarouselAPI(this.artistId);
const albums = await albumCarouselAPI.get()
await albumCarouselView.render(albums);
}
}
5 changes: 4 additions & 1 deletion src/pages/feed/ui/Feed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TrackListAPI } from "../../../widgets/trackList/index.js";
import { ArtistCarouselAPI} from "../../../widgets/artistCarousel/index.js";
import { ListenBlockView } from "../../../widgets/listenBlock/index.js";
import { TrackListView } from "../../../widgets/trackList/index.js";
import { ArtistCarouselView } from "../../../widgets/artistCarousel/index.js";
Expand Down Expand Up @@ -53,8 +54,10 @@ export class FeedPage {
eventBus.emit("hidePlayer");
}

const artistCarouselAPI = new ArtistCarouselAPI();
const artistCarouselView = new ArtistCarouselView(this.pageContent);
await artistCarouselView.render();
const artists = await artistCarouselAPI.get();
await artistCarouselView.render(artists);

const playlistListAPI = new PlaylistListAPI();
const playlistListView = new PlaylistListView(this.pageContent);
Expand Down
34 changes: 29 additions & 5 deletions src/pages/subscriptions/ui/subscriptions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { ArtistCarouselView } from "../../../widgets/artistCarousel/index.js";
import { player } from "../../../shared/player/model/store";
import { userStore } from "../../../entities/user";
import { eventBus } from "../../../shared/lib";
import { AlbumCarouselView } from "../../../widgets/albumCarousel/index.js";
import { ErrorView } from "../../../widgets/error/index.js";
import {
AlbumCarouselView,
AlbumCarouselAPI
} from "../../../widgets/albumCarousel/index.js";
import {
ArtistCarouselView,
ArtistCarouselAPI
} from "../../../widgets/artistCarousel/index.js";
import {
PlaylistListAPI,
PlaylistListView,
Expand All @@ -28,13 +35,21 @@ export class SubscriptionsPage {
this.pageContent.classList.add("page_content");
this.parent.appendChild(this.pageContent);

const artistCarouselAPI = new ArtistCarouselAPI();
const artistCarouselView = new ArtistCarouselView(this.pageContent, {
favorite: true,
});
await artistCarouselView.render();
const artists = await artistCarouselAPI.getFavorite();
if (artists) {
await artistCarouselView.render(artists);
}

const albumCardView = new AlbumCarouselView(this.pageContent, null, true);
await albumCardView.render();
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);
Expand All @@ -43,6 +58,15 @@ export class SubscriptionsPage {
await playlistListView.render(playlists.slice(0, 5), true, true);
}

if (!artists && !albums && !playlists) {
const errorView = new ErrorView(
null,
"У вас пока нед подписок",
"Здесь можно увидеть подписки на артистов, альбомы и плейлисты",
);
await errorView.render();
}

if (
userStore.storage.user.isAuthorized &&
(player.isLoaded || player.isPlaying)
Expand Down
8 changes: 1 addition & 7 deletions src/widgets/albumCarousel/ui/albumCarousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ export class AlbumCarouselView {
/**
* Renders the playlist view.
*/
async render() {
const albumCarouselAPI = new AlbumCarouselAPI(this.artistId);
let albums = !this.favorite
? await albumCarouselAPI.get()
: await albumCarouselAPI.getFavorite();
if (!albums) return;

async render(albums) {
const albumCarouselElement = document.createElement("div");
albumCarouselElement.classList.add("album_carousel");

Expand Down
8 changes: 1 addition & 7 deletions src/widgets/artistCarousel/ui/artistCarousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ export class ArtistCarouselView {
/**
* Renders the playlist view.
*/
async render() {
const artistCarouselAPI = new ArtistCarouselAPI();
let artists = !this.favorite
? await artistCarouselAPI.get()
: await artistCarouselAPI.getFavorite();
if (!artists) return;

async render(artists) {
const artistCarouselElement = document.createElement("div");
artistCarouselElement.classList.add("popular_artists");

Expand Down

0 comments on commit 4c39a0f

Please sign in to comment.