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

Update miniPlayer.ts #227

Closed
wants to merge 4 commits into from
Closed
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
7 changes: 4 additions & 3 deletions src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const store: {
superCollectionType: 'featured' | 'collections' | 'channels' | 'feed' | 'playlists',
actionsMenu: CollectionItem,
list: List & Record<'url' | 'type' | 'uploader', string>,
downloadFormat: 'opus' | 'wav' | 'mp3' | 'ogg'
downloadFormat: 'opus' | 'wav' | 'mp3' | 'ogg',
routes: string[]
} = {
player: {
playbackState: 'none',
Expand Down Expand Up @@ -85,6 +86,6 @@ export const store: {
uploader: '',
thumbnail: ''
},
downloadFormat: getSaved('dlFormat') as 'opus' || 'opus'
downloadFormat: getSaved('dlFormat') as 'opus' || 'opus',
routes: ['/', '/upcoming', '/search', '/library', '/settings', '/list']
}

10 changes: 6 additions & 4 deletions src/modules/miniPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,32 @@ if (store.loadImage === 'off') {
img = '';
}


miniPlayer.addEventListener('click', (e) => {
e.preventDefault();
if (!(<HTMLElement>e.target).matches('button'))
goTo('/');
});
const mptext = document.getElementById('mptext') as HTMLDivElement;


export function miniPlayerRoutingHandler(inHome: boolean, header: DOMTokenList) {

if (inHome) {
header.add('hide');
document.getElementById('upperLayer')!.prepend(img);
document.getElementById('meta')!.prepend(title, author);
document.getElementById('playerControls')!.insertBefore(playButton, document.getElementById('seekFwdButton'));
document.getElementById('selectors')!.appendChild(ytifyIcon);
// Update document title when in MiniPlayer (Home)
document.title = (store.stream.title || 'Home') + ' - ytify';
}
else if (header.contains('hide')) {
header.remove('hide');
miniPlayer.prepend(img);
mptext.append(title, author);
miniPlayer.lastElementChild!.append(mptext, playButton);
document.getElementById('ytifyIconContainer')!.prepend(ytifyIcon);
// Update document title when not in MiniPlayer
const activeRoute = store.routes.find(route => location.pathname === route);
const routeName = activeRoute ? document.querySelector(`nav a[href="${activeRoute}"]`)?.textContent : '';
document.title = (routeName || 'ytify') + ' - ytify';
}

}
15 changes: 4 additions & 11 deletions src/scripts/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import { miniPlayerRoutingHandler } from "../modules/miniPlayer";
import fetchList from "../modules/fetchList";
import { fetchCollection, superCollectionLoader } from "../lib/libraryUtils";


const nav = document.querySelector('nav') as HTMLDivElement;
const anchors = document.querySelectorAll('nav a') as NodeListOf<HTMLAnchorElement>;
const sections = document.querySelectorAll('section') as NodeListOf<HTMLDivElement>;
const routes = ['/', '/upcoming', '/search', '/library', '/settings', '/list'];
const queueParam = params.get('a');



function upcomingInjector(param: string) {
loadingScreen.showModal();

Expand All @@ -29,10 +27,10 @@ function upcomingInjector(param: string) {
if (queueParam)
upcomingInjector(queueParam);

let prevPageIdx = routes.indexOf(location.pathname);
let prevPageIdx = store.routes.indexOf(location.pathname);

function showSection(id: string) {
const routeIdx = routes.indexOf(id);
const routeIdx = store.routes.indexOf(id);
miniPlayerRoutingHandler(id === '/', nav.parentElement!.classList);

// Enables Reactivity to declare db modifications into UI
Expand All @@ -58,7 +56,6 @@ function showSection(id: string) {
prevPageIdx = routeIdx;
}


nav.addEventListener('click', (e: Event) => {
e.preventDefault();

Expand Down Expand Up @@ -91,7 +88,6 @@ nav.addEventListener('click', (e: Event) => {
showSection(anchor.id);
});


// load section if name found in address else load library
let route: string;
const errorParam = params.get('e');
Expand Down Expand Up @@ -122,7 +118,7 @@ if (errorParam) {
}
else {

route = routes.find(route => location.pathname === route) || '/';
route = store.routes.find(route => location.pathname === route) || '/';

const hasStreamQuery = params.has('s') || params.has('url') || params.has('text');

Expand Down Expand Up @@ -164,7 +160,4 @@ onpopstate = function() {

showSection(location.pathname);


}