|
|
@@ -9,22 +9,29 @@ import { TracksApiService } from 'src/app/tracks-api.service';
|
|
|
styleUrls: ['./track-create.component.scss']
|
|
|
})
|
|
|
export class TrackCreateComponent {
|
|
|
+ public fileName: string = '';
|
|
|
+ public file: File | undefined;
|
|
|
+
|
|
|
public constructor(
|
|
|
private readonly tracksApi: TracksApiService,
|
|
|
private readonly router: Router
|
|
|
) { }
|
|
|
|
|
|
- public uploadFile(event: SubmitEvent, form: NgForm): void {
|
|
|
-
|
|
|
- const file: File | undefined = ((event.target as HTMLFormElement).elements.namedItem('trackFile') as HTMLInputElement).files?.[0];
|
|
|
+ public fileSelectionChange(event: Event): void {
|
|
|
+ this.file = (event.target as HTMLInputElement).files?.[0];
|
|
|
+ this.fileName = this.file?.name ?? '';
|
|
|
+ }
|
|
|
|
|
|
- if (file) {
|
|
|
+ public uploadFile(form: NgForm): void {
|
|
|
+ if (this.file) {
|
|
|
const formData = new FormData();
|
|
|
- formData.append("file", file);
|
|
|
+ formData.append("file", this.file);
|
|
|
|
|
|
this.tracksApi.createTrack(formData).then(track =>
|
|
|
{
|
|
|
form.resetForm();
|
|
|
+ this.file = undefined;
|
|
|
+ this.fileName = '';
|
|
|
this.router.navigateByUrl(`tracks/edit/${track.trackId}`, );
|
|
|
});
|
|
|
}
|