Skip to content

Commit

Permalink
update show/hide logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MatiXxD committed Dec 17, 2024
1 parent 995f7d1 commit f92b6d3
Show file tree
Hide file tree
Showing 10 changed files with 580 additions and 562 deletions.
89 changes: 47 additions & 42 deletions src/pages/edit-profile/ui/editProfile.js
Original file line number Diff line number Diff line change
@@ -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');
}
}
}
58 changes: 29 additions & 29 deletions src/pages/more-albums/ui/MoreAlbums.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
42 changes: 21 additions & 21 deletions src/pages/more-artists/ui/MoreArtists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
40 changes: 20 additions & 20 deletions src/pages/more-playlists/ui/morePlaylists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
68 changes: 37 additions & 31 deletions src/pages/playlist/ui/playlistPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
Loading

0 comments on commit f92b6d3

Please sign in to comment.