- New playlist-details component with header (back button, playlist icon, title, track count) - Full track list with all interactions: select, play, context menu, drag, phantom handling - Drop target support for adding tracks from other views - Search filtering for tracks within the detail view - Navigation routing in index.ts for playlist-details view - Added playlist-details to SEARCHABLE_VIEWS in search-store
177 lines
6.3 KiB
TypeScript
177 lines
6.3 KiB
TypeScript
import '@components/audio-player/audio-player.ts';
|
|
import '@components/track-list/track-list.ts';
|
|
import '@components/cover-grid/cover-grid.ts';
|
|
import '@components/now-playing/now-playing.ts';
|
|
import '@components/sidebar/app-sidebar.ts';
|
|
import '@components/queue-panel/queue-panel.ts';
|
|
import '@components/playlist-view/playlist-view.ts';
|
|
import '@components/library-manager/library-manager.ts';
|
|
import '@components/config-page/config-page.ts';
|
|
import '@components/artists-view/artists-view.ts';
|
|
import '@components/artist-details/artist-details.ts';
|
|
import '@components/genres-view/genres-view.ts';
|
|
import '@components/genre-details/genre-details.ts';
|
|
import '@components/playlist-details/playlist-details.ts';
|
|
import '@components/search-bar/search-bar.ts';
|
|
import '@components/track-details/track-details.ts';
|
|
import '@awesome.me/webawesome/dist/styles/themes/default.css';
|
|
import '@awesome.me/webawesome/dist/components/icon/icon.js';
|
|
import { setBasePath } from '@awesome.me/webawesome/dist/webawesome.js';
|
|
import { queueStore } from '@store/queue-store';
|
|
import { searchStore } from '@store/search-store';
|
|
import * as Player from '@go/player/Player';
|
|
import * as Queue from '@go/queue/Queue';
|
|
// Importing the theme store triggers initialization: it fetches the saved
|
|
// theme from the backend and applies CSS custom properties to :root.
|
|
import '@store/theme-store';
|
|
// Importing the keyboard shortcut service triggers initialization:
|
|
// registers the document keydown listener for global shortcuts.
|
|
import './src/services/keyboard-shortcut-service';
|
|
import {
|
|
hasTrackPayload,
|
|
getDragPayload,
|
|
} from '@utils/drag-controller';
|
|
import type { DragActiveDetail } from '@utils/drag-controller';
|
|
|
|
setBasePath('/dist/webawesome');
|
|
|
|
// Navigation event listener for view switching
|
|
document.addEventListener('navigate', (e: Event) => {
|
|
const { view } = (e as CustomEvent).detail;
|
|
const mainContent = document.getElementById('main-content');
|
|
|
|
if (!mainContent) return;
|
|
|
|
searchStore.setCurrentView(view);
|
|
|
|
switch (view) {
|
|
case 'albums':
|
|
mainContent.innerHTML = '<cover-grid></cover-grid>';
|
|
break;
|
|
case 'tracks':
|
|
mainContent.innerHTML = '<track-list></track-list>';
|
|
break;
|
|
case 'playlists':
|
|
mainContent.innerHTML = '<playlist-view></playlist-view>';
|
|
break;
|
|
case 'artists':
|
|
mainContent.innerHTML = '<artists-view></artists-view>';
|
|
break;
|
|
case 'artist-details': {
|
|
const { artistId, artistName } =
|
|
(e as CustomEvent).detail;
|
|
const el = document.createElement('artist-details');
|
|
|
|
el.setAttribute('artist-id', String(artistId));
|
|
el.setAttribute('artist-name', artistName);
|
|
mainContent.innerHTML = '';
|
|
mainContent.appendChild(el);
|
|
break;
|
|
}
|
|
case 'playlist-details': {
|
|
const { playlistId, playlistName } =
|
|
(e as CustomEvent).detail;
|
|
const plEl = document.createElement('playlist-details');
|
|
|
|
plEl.setAttribute('playlist-id', String(playlistId));
|
|
plEl.setAttribute('playlist-name', playlistName);
|
|
mainContent.innerHTML = '';
|
|
mainContent.appendChild(plEl);
|
|
break;
|
|
}
|
|
case 'genres':
|
|
mainContent.innerHTML = '<genres-view></genres-view>';
|
|
break;
|
|
case 'genre-details': {
|
|
const { genreName } =
|
|
(e as CustomEvent).detail;
|
|
const genreEl = document.createElement('genre-details');
|
|
|
|
genreEl.setAttribute('genre-name', genreName);
|
|
mainContent.innerHTML = '';
|
|
mainContent.appendChild(genreEl);
|
|
break;
|
|
}
|
|
case 'libraries':
|
|
mainContent.innerHTML = '<library-manager></library-manager>';
|
|
break;
|
|
case 'settings':
|
|
mainContent.innerHTML = '<config-page></config-page>';
|
|
break;
|
|
default:
|
|
mainContent.innerHTML = `<div style="padding: 1em; color: var(--yj-text-secondary, #b3b3b3);">
|
|
<p>Coming soon: ${view}</p>
|
|
</div>`;
|
|
}
|
|
});
|
|
|
|
// Queue panel toggle
|
|
const queueButton = document.getElementById('queue-button');
|
|
const queuePanel = document.getElementById('queue-panel') as HTMLElement | null;
|
|
|
|
if (queueButton && queuePanel) {
|
|
queueButton.addEventListener('click', () => {
|
|
const isOpen = queuePanel.hasAttribute('open');
|
|
|
|
if (isOpen) {
|
|
queuePanel.removeAttribute('open');
|
|
} else {
|
|
queuePanel.setAttribute('open', '');
|
|
}
|
|
});
|
|
|
|
// ---------------------------------------------------------------
|
|
// Queue button as drop target (when queue panel is closed)
|
|
// ---------------------------------------------------------------
|
|
|
|
queueButton.addEventListener('dragover', (e: DragEvent) => {
|
|
if (!hasTrackPayload(e)) return;
|
|
|
|
e.preventDefault();
|
|
|
|
if (e.dataTransfer) {
|
|
e.dataTransfer.dropEffect = 'copy';
|
|
}
|
|
|
|
queueButton.classList.add('drag-over');
|
|
});
|
|
|
|
queueButton.addEventListener('dragleave', () => {
|
|
queueButton.classList.remove('drag-over');
|
|
});
|
|
|
|
queueButton.addEventListener('drop', (e: DragEvent) => {
|
|
e.preventDefault();
|
|
queueButton.classList.remove('drag-over');
|
|
|
|
const payload = getDragPayload(e);
|
|
|
|
if (!payload || payload.filePaths.length === 0) return;
|
|
|
|
if (payload.source === 'queue') return;
|
|
|
|
queueStore.addTracksToQueue(payload.filePaths);
|
|
});
|
|
|
|
// Show/hide drag-over styling globally.
|
|
document.addEventListener(
|
|
'yj-drag-active',
|
|
((e: CustomEvent<DragActiveDetail>) => {
|
|
if (!e.detail.active) {
|
|
queueButton.classList.remove('drag-over');
|
|
}
|
|
}) as EventListener,
|
|
);
|
|
}
|
|
|
|
// ---------------------------------------------------------------
|
|
// Request current state from the backend
|
|
// ---------------------------------------------------------------
|
|
// All stores have registered their EventsOn listeners by now
|
|
// (module-level singletons are instantiated during import
|
|
// evaluation), so the state-push events emitted by these
|
|
// binding calls will be received deterministically — no sleep
|
|
// or timing assumptions needed.
|
|
void Player.EmitCurrentState();
|
|
void Queue.EmitCurrentState();
|