Rename to library

This commit is contained in:
Myx
2025-03-27 18:08:11 +01:00
committed by Myx
parent 50a69c9598
commit c0cfca39a2
13 changed files with 76 additions and 73 deletions

View File

@@ -0,0 +1,48 @@
import { Component, ElementRef, ViewChild } from '@angular/core'
import { DownloadService } from '../../../core/services/download.service'
import { LibraryService } from 'src-angular/app/core/services/library.service'
@Component({
selector: 'app-library-bar',
templateUrl: './library-bar.component.html',
standalone: false,
})
export class LibraryBarComponent {
@ViewChild('fileInput', { static: false }) libraryfileInput: ElementRef<HTMLInputElement>
constructor(public libraryService: LibraryService, public downloadService: DownloadService) { }
exportPlaylist() {
this.libraryService.storeLibrary()
}
exportSelected() {
this.libraryService.storeSelectedSongs()
}
importPlaylist() {
this.libraryfileInput.nativeElement.click()
}
onFileSelected(event: Event) {
const input = event.target as HTMLInputElement
if (input.files && input.files.length > 0) {
const file = input.files[0]
const reader = new FileReader()
reader.onload = () => {
try {
const importedTracks = JSON.parse(reader.result as string)
if (Array.isArray(importedTracks)) {
this.libraryService.downloadLibrary(importedTracks)
} else {
console.error('Invalid file format')
}
} catch (error) {
console.error('Error parsing file:', error)
}
}
reader.readAsText(file)
}
}
}