diff --git a/src/searchpal.ts b/src/searchpal.ts index 1bd9623..95c3e92 100644 --- a/src/searchpal.ts +++ b/src/searchpal.ts @@ -229,59 +229,6 @@ class SearchPalette { }) } - /** - * Handle a cached track - * - * @private - * @param key The key of the cached track - * @memberof SearchPalette - */ - private async handleCachedTrack (key: string): Promise { - const data: CachedData | null = await this.localForage.getItem(key) - if (data == null || (data.image == null || data.track == null || data.track.name == null || data.track.artists == null)) return - - const item = new HTML('div').classOn('item').attr({ tabindex: '0' }) - const icon = new HTML('img').classOn('image').attr({ src: data.image, alt: `${data.track.name} by ${data.track.artists.map(artist => artist.name).join(', ')}` }) - const meta = new HTML('span').text( - `${data.track.name}\n${data.track.artists - .map(artist => artist.name) - .join(', ')}` - ) - const icons = new HTML('div').classOn('icons') - - const add = new HTML('button') - .classOn('material-symbols-sharp') - .text('playlist_add') - .appendTo(icons) - - const remove = new HTML('button') - .classOn('material-symbols-sharp') - .text('delete') - .appendTo(icons) - - remove.on('click', e => { - e.preventDefault() - e.stopPropagation() - this.localForage.removeItem(key).catch(console.error) - item.cleanup() - }) - - add.on('click', e => { - e.preventDefault() - e.stopPropagation() - this.queue.add(data.track) - }) - - item.appendMany(icon, meta, icons) - item.appendTo(this.container) - - item.on('click', () => { - this.queue.load(data.track) - this.player.start().catch(console.error) - this.hide() - }) - } - /** * Render the search results * @@ -342,22 +289,6 @@ class SearchPalette { }) } - /** - * Render the cached data - * - * @private - * @memberof SearchPalette - */ - private renderCached (): void { - this.container.html('') - this.container.append(new HTML('div').id('tracks')) - this.localForage.keys().then(keys => { - keys.forEach(key => { - this.handleCachedTrack(key).catch(console.error) - }) - }).catch(console.error) - } - /** * Register the events * @@ -398,18 +329,13 @@ class SearchPalette { }) ) } - - opened = false + /** * Show the search palette * * @memberof SearchPalette */ show (): void { - if (!this.opened && window.isSafari === false) { - // Fill the search palette with cached data - this.localForage.ready(() => this.renderCached()).catch(console.error) - } this.element.classOn('show') }