Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nm 97 #98

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>NovaMusic</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/public/images/icons/logo.svg">
<link rel="icon" href="images/logo.svg">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Comfortaa:[email protected]&display=swap" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion src/app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const PAGES = [
view: StatisticPage,
},
{
path: "/more_playlists/popular",
path: "/more_playlists/{type}",
view: MorePlaylistsPage,
},
{
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './index.scss';
import { App } from './app/app.js';
import "../public/images/icons/logo.svg";

// if ('serviceWorker' in navigator) {
// navigator.serviceWorker
Expand Down
14 changes: 11 additions & 3 deletions src/pages/more-albums/ui/MoreAlbums.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class MoreAlbumsPage {
*/
constructor(params) {
this.parent = document.querySelector('#root');
this.type = params['type']
this.entity = params['entity'];
this.entityId = params['id'];
}
Expand All @@ -20,14 +21,21 @@ export class MoreAlbumsPage {
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);
const albums = await albumListAPI.get();
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);
await albumListView.render(albums, this.favorite);

if (userStore.storage.user.isAuthorized) {
eventBus.emit('showPlayer');
Expand Down
16 changes: 12 additions & 4 deletions src/pages/more-artists/ui/MoreArtists.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@ export class MoreArtistsPage {
/**
* Creates an instance of the View class.
*/
constructor() {
constructor(params) {
this.parent = document.querySelector('#root');
this.type = params['type']
}

async render() {
this.parent.innerHTML = '';

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();
const artists = await artistListAPI.get();
const artistListAPI = new ArtistListAPI();
let artists = !this.favorite
? await artistListAPI .get()
: await artistListAPI .getFavorite();

const artistListView = new ArtistListView(this.pageContent);
await artistListView.render(artists);
await artistListView.render(artists, this.favorite);

if (userStore.storage.user.isAuthorized) {
eventBus.emit('showPlayer');
Expand Down
16 changes: 12 additions & 4 deletions src/pages/more-playlists/ui/morePlaylists.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@ export class MorePlaylistsPage {
/**
* Creates an instance of the View class.
*/
constructor() {
constructor(params) {
this.parent = document.querySelector('#root');
this.type = params['type']
}

async render() {
this.parent.innerHTML = '';

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();
const playlists = await playlistListAPI.get();
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);
await playlistListView.render(playlists, false, this.favorite);

if (userStore.storage.user.isAuthorized) {
eventBus.emit('showPlayer');
Expand Down
2 changes: 1 addition & 1 deletion src/pages/more-tracks/ui/MoreTracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class MoreTracksPage {
this.pageContent.classList.add('page_content');
this.parent.appendChild(this.pageContent);

const trackListAPI = new TrackListAPI({artistId: this.artistId, albumId: this.albumId});
const trackListAPI = new TrackListAPI({artistId: this.artistId, albumId: this.albumId, favorite: this.favorite});
const trackListView = new TrackListView(
this.pageContent,
{
Expand Down
1 change: 1 addition & 0 deletions src/pages/profile/ui/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class ProfilePage {
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));
Expand Down
4 changes: 3 additions & 1 deletion src/pages/subscriptions/ui/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export class SubscriptionsPage {
const playlistListAPI = new PlaylistListAPI();
const playlistListView = new PlaylistListView(this.pageContent);
const playlists = await playlistListAPI.getFavorite();
await playlistListView.render(playlists.slice(0, 5), true, true);
if (playlists) {
await playlistListView.render(playlists.slice(0, 5), true, true);
}

if (
userStore.storage.user.isAuthorized &&
Expand Down
2 changes: 1 addition & 1 deletion src/shared/config/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// 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";
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/albumCarousel/ui/albumCarousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class AlbumCarouselView {
let albums = !this.favorite
? await albumCarouselAPI.get()
: await albumCarouselAPI.getFavorite();
if (!albums) return;

const albumCarouselElement = document.createElement("div");
albumCarouselElement.classList.add("album_carousel");
Expand All @@ -40,7 +41,7 @@ export class AlbumCarouselView {
showMoreHref = `/more_albums/${"artist"}/${this.artistId}`;
titleText = "Альбомы исполнителя";
} else if (this.favorite) {
showMoreHref = `/more_albums/popular`;
showMoreHref = `/more_albums/favorite`;
titleText = "Любимые альбомы";
} else {
showMoreHref = `/more_albums/popular`;
Expand Down
13 changes: 13 additions & 0 deletions src/widgets/albumList/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,17 @@ export class AlbumListAPI {
console.error(error);
}
}

async getFavorite() {
try {
const response = await GET(`${API_ENDPOINTS.GET_FAVORITE_ALBUMS}`);
if (!response.error) {
return response.data;
} else {
console.log("Error during favorite AlbumList loading:");
}
} catch (error) {
console.error(error);
}
}
}
4 changes: 3 additions & 1 deletion src/widgets/albumList/ui/albumList.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ export class AlbumListView {
/**
* Renders the album view.
*/
async render(albums) {
async render(albums, favorite = false) {
const albumListElement = document.createElement('div');
albumListElement.classList.add('albums');

let titleText;
if (this.artistId) {
titleText = "Альбомы исполнителя";
} else if (favorite) {
titleText = "Любимые альбомы";
} else {
titleText = "Популярные альбомы";
}
Expand Down
18 changes: 14 additions & 4 deletions src/widgets/artistCarousel/ui/artistCarousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,21 @@ export class ArtistCarouselView {
let artists = !this.favorite
? await artistCarouselAPI.get()
: await artistCarouselAPI.getFavorite();
if (!artists) return;

const artistCarouselElement = document.createElement("div");
artistCarouselElement.classList.add("popular_artists");
let showMoreHref = `/more_artists/popular`;

let titleText;
let showMoreHref;
if (this.favorite) {
showMoreHref = `/more_artists/favorite`;
titleText = "Любимые артисты";
} else {
showMoreHref = `/more_artists/popular`;
titleText = "Популярные артисты";
}

artistCarouselElement.innerHTML = template({ styles, showMoreHref });
this.parent.appendChild(artistCarouselElement);

Expand All @@ -46,9 +57,8 @@ export class ArtistCarouselView {
});

await this.getElements();
if (this.favorite) {
this.setTitle("Любимые артисты");
}

this.setTitle(titleText);

this.onEvents();
this.addEvents();
Expand Down
13 changes: 13 additions & 0 deletions src/widgets/artistList/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,17 @@ export class ArtistListAPI {
console.error(error);
}
}

async getFavorite() {
try {
const response = await GET(`${API_ENDPOINTS.GET_FAVORITE_ARTIST}`);
if (!response.error) {
return response.data;
} else {
console.log("Error during favorite ArtistList loading:");
}
} catch (error) {
console.error(error);
}
}
}
17 changes: 16 additions & 1 deletion src/widgets/artistList/ui/artistList.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ export class ArtistListView {
/**
* Renders the playlist view.
*/
async render(artists) {
async render(artists, favorite = false) {
const artistListElement = document.createElement('div');
artistListElement.classList.add('artists');

let titleText;
if (favorite) {
titleText = "Любимые артисты";
} else {
titleText = "Популярные артисты";
}

artistListElement.innerHTML = template({ styles });

Expand All @@ -33,5 +40,13 @@ export class ArtistListView {
const artistView = new ArtistView(artistsBlock);
artistView.render(artist);
});

this.setTitle(titleText);
}

setTitle(titleText) {
const titleBlock = document.querySelector(`.${styles['artists__recommend_text']}`);
const title = titleBlock.querySelector('h4');
title.textContent = titleText;
}
}
12 changes: 6 additions & 6 deletions src/widgets/playlistList/ui/playlistList.hbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div class="{{ styles.playlists__container }} container">
<div class="{{ styles.playlists__block }} block">
{{#if showMoreHref}}
<div class="{{ styles.playlists__text }}">
<h4>Популярные плейлисты</h4>
<h4><a href="{{ showMoreHref }}" class="playlists__show_more link">Показать еще</a></h4>
</div>
{{/if}}
<div class="{{ styles.playlists__text }}">
<h4>Популярные плейлисты</h4>
{{#if showMoreHref}}
<h4><a href="{{ showMoreHref }}" class="playlists__show_more link">Показать еще</a></h4>
{{/if}}
</div>
<div class="{{ styles.playlists__list }}" id="mainpage-popular-playlists">

</div>
Expand Down
18 changes: 13 additions & 5 deletions src/widgets/playlistList/ui/playlistList.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ export class PlaylistListView {
const playlistListElement = document.createElement("div");
playlistListElement.classList.add("playlists");

let titleText;
let showMoreHref;
if (favorite) {
showMoreHref = `/more_playlists/favorite`;
titleText = "Любимые плейлисты";
} else {
showMoreHref = `/more_playlists/popular`;
titleText = "Популярные плейлисты";
}

if (needsShowMoreHref) {
let showMoreHref = `/more_playlists/popular`;
playlistListElement.innerHTML = template({ styles, showMoreHref });
} else {
playlistListElement.innerHTML = template({ styles });
Expand All @@ -45,13 +54,12 @@ export class PlaylistListView {

this.addEvents();

if (favorite && needsShowMoreHref) {
this.setTitle("Любимые плейлисты");
}
this.setTitle(titleText);
}

setTitle(newTitle) {
const title = document.querySelector(`.${styles["playlists__text"]}>h4`);
const titleBlock = document.querySelector(`.${styles['playlists__text']}`);
const title = titleBlock.querySelector('h4');
title.textContent = newTitle;
}

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/trackList/ui/trackList.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class TrackListView {
this.parent = parent ?? document.querySelector('#root');
this.artistId = args.artistId ?? null;
this.albumId = args.albumId ?? null;
this.favorite = arguments.favorite ?? null;
this.favorite = args.favorite ?? null;
this.myPlaylistId = args.myPlaylistId ?? false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/userPlaylists/ui/userPlaylists.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class UserPlaylistsView {
async render() {
const userPlaylistsAPI = new UserPlaylistsAPI(this.userId);
const playlists = await userPlaylistsAPI.get();
if (!playlists) return;

const userPlaylistsElement = document.createElement("div");
userPlaylistsElement.classList.add("user-playlists");
Expand All @@ -52,7 +53,6 @@ export class UserPlaylistsView {
}

const playlistsBlock = document.getElementById("user-playlists");
if (playlists?.length === 0) return;
Array.from(playlists).forEach((playlist) => {
const playlistView = new PlaylistView(playlistsBlock);
playlistView.render(playlist);
Expand Down
Loading