[READ-ONLY] Mirror of https://github.com/probablykasper/ferrum. Music library app for Mac, Linux and Windows ferrum.kasper.space
electron linux macos music music-library music-player napi windows
0

Configure Feed

Select the types of activity you want to include in your feed.

Show Songs & Artists on quicknav

Kasper (Sep 15, 2024, 5:51 PM +0200) 409abc8c 16eb70ce

+42 -16
+23 -6
src/components/QuickNav.svelte
··· 3 3 import { checkShortcut } from '../lib/helpers' 4 4 import { ipcListen } from '@/lib/window' 5 5 import fuzzysort from 'fuzzysort' 6 - import { page, trackListsDetailsMap } from '@/lib/data' 7 - import type { TrackListDetails } from '../../ferrum-addon/addon' 6 + import { page, trackListsDetailsMap, view_as_artists, view_as_songs } from '@/lib/data' 7 + import type { TrackListDetails, ViewAs } from '../../ferrum-addon/addon' 8 8 import Modal from './Modal.svelte' 9 + import { special_playlists_nav } from './Sidebar.svelte' 10 + 11 + type Result = TrackListDetails & { view_as?: ViewAs } 9 12 10 13 let value = '' 11 - let playlists: TrackListDetails[] = [] 14 + let playlists: Result[] = [] 12 15 let show = false 13 16 $: if (show) { 14 - playlists = Object.values($trackListsDetailsMap).sort((a, b) => a.name.localeCompare(b.name)) 17 + playlists = get_playlists() 18 + } 19 + function get_playlists() { 20 + const playlists: Result[] = special_playlists_nav 21 + for (const playlist of Object.values($trackListsDetailsMap)) { 22 + if (playlist.kind === 'playlist' || playlist.kind === 'folder') { 23 + playlists.push(playlist) 24 + } 25 + } 26 + playlists.push({ id: 'root', name: 'Songs', kind: 'special', view_as: view_as_songs }) 27 + playlists.push({ id: 'root', name: 'Artists', kind: 'special', view_as: view_as_artists }) 28 + return playlists 15 29 } 16 30 17 31 let filteredItems = fuzzysort.go(value, playlists, { key: 'name', all: true }) ··· 39 53 show = false 40 54 value = '' 41 55 } else if (checkShortcut(e, 'Enter')) { 42 - page.openPlaylist(filteredItems[selectedIndex].obj.id) 56 + page.openPlaylist( 57 + filteredItems[selectedIndex].obj.id, 58 + filteredItems[selectedIndex].obj.view_as ?? view_as_songs, 59 + ) 43 60 show = false 44 61 } else if (checkShortcut(e, 'ArrowUp')) { 45 62 selectedIndex-- ··· 85 102 bind:this={listItems[i]} 86 103 type="button" 87 104 on:click={() => { 88 - page.openPlaylist(item.obj.id) 105 + page.openPlaylist(item.obj.id, item.obj.view_as ?? view_as_songs) 89 106 show = false 90 107 }} 91 108 class:selected={selectedIndex === i}
+16 -10
src/components/Sidebar.svelte
··· 1 + <script lang="ts" context="module"> 2 + export const special_playlists_nav = [ 3 + { id: 'root', name: 'Songs', kind: 'special', view_as: 0 }, 4 + { id: 'root', name: 'Artists', kind: 'special', view_as: 1 }, 5 + ] 6 + </script> 7 + 1 8 <script lang="ts"> 2 9 import SidebarItems, { type SidebarItemHandle } from './SidebarItems.svelte' 3 10 import Filter from './Filter.svelte' 4 - import { isMac, trackListsDetailsMap, page, movePlaylist } from '../lib/data' 11 + import { isMac, trackListsDetailsMap, page, movePlaylist, view_as_songs } from '../lib/data' 5 12 import { ipcListen, ipcRenderer } from '../lib/window' 6 13 import { writable } from 'svelte/store' 7 14 import { onDestroy, setContext, tick } from 'svelte' 8 15 import { dragged } from '../lib/drag-drop' 9 16 import { tracklist_actions } from '@/lib/page' 10 17 11 - const special = [ 12 - { id: 'root', name: 'Songs', kind: 'special', view_as: 0 }, 13 - { id: 'root', name: 'Artists', kind: 'special', view_as: 1 }, 14 - ] 15 18 let viewport: HTMLElement 16 19 const itemHandle = setContext('itemHandle', writable(null as SidebarItemHandle | null)) 17 20 ··· 126 129 <div class="spacer" /> 127 130 <SidebarItems 128 131 parentId={null} 129 - children={special} 132 + children={special_playlists_nav} 130 133 on_open={(item) => { 131 - page.openPlaylist('root', item.view_as ?? 0) 134 + page.openPlaylist('root', item.view_as ?? view_as_songs) 132 135 }} 133 136 on_select_down={() => { 134 137 if ($trackListsDetailsMap.root.children && $trackListsDetailsMap.root.children[0]) { 135 - page.openPlaylist($trackListsDetailsMap.root.children[0], 0) 138 + page.openPlaylist($trackListsDetailsMap.root.children[0], view_as_songs) 136 139 } 137 140 }} 138 141 /> ··· 145 148 on_open={(item) => { 146 149 if ($page.id !== item.id) { 147 150 if (item.id === 'root') { 148 - page.openPlaylist('root', item.view_as ?? special[special.length - 1].view_as) 151 + page.openPlaylist( 152 + 'root', 153 + item.view_as ?? special_playlists_nav[special_playlists_nav.length - 1].view_as, 154 + ) 149 155 } else { 150 - page.openPlaylist(item.id, item.view_as ?? 0) 156 + page.openPlaylist(item.id, item.view_as ?? view_as_songs) 151 157 } 152 158 } 153 159 }}
+3
src/lib/data.ts
··· 20 20 21 21 call((addon) => addon.load_data(isDev, libraryPath)) 22 22 23 + export const view_as_songs: ViewAs.Songs = 0 24 + export const view_as_artists: ViewAs.Artists = 1 25 + 23 26 function getErrorMessage(err: unknown): string { 24 27 if (typeof err === 'object' && err !== null) { 25 28 const obj = err as { [key: string]: unknown }