feat(frontend): add Spotify URL validation to download input
This commit is contained in:
@@ -13,16 +13,23 @@
|
|||||||
<div class="hero-body">
|
<div class="hero-body">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<p class="subtitle">Download</p>
|
<p class="subtitle">Download</p>
|
||||||
|
<div>
|
||||||
<div class="is-flex">
|
<div class="is-flex">
|
||||||
<input class="input" type="text" [(ngModel)]="url" placeholder="Paste playlist/song/artist url"/>
|
<input class="input"
|
||||||
|
[class.is-danger]="url && !isValidSpotifyUrl"
|
||||||
|
type="text"
|
||||||
|
[(ngModel)]="url"
|
||||||
|
placeholder="Paste playlist/song/artist url"/>
|
||||||
<button class="button is-primary"
|
<button class="button is-primary"
|
||||||
[class.is-loading]="(createLoading$ | async)?.isLoading"
|
[class.is-loading]="(createLoading$ | async)?.isLoading"
|
||||||
(click)="download()"
|
(click)="download()"
|
||||||
[disabled]="!url"
|
[disabled]="!url || !isValidSpotifyUrl"
|
||||||
>
|
>
|
||||||
<i class="fa-solid fa-download"></i> Download
|
<i class="fa-solid fa-download"></i> Download
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<p *ngIf="url && !isValidSpotifyUrl" class="help is-danger">Please enter a valid Spotify URL (e.g. https://open.spotify.com/...)</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ import {map} from "rxjs";
|
|||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
|
|
||||||
url = ''
|
url = ''
|
||||||
|
private readonly spotifyUrlPattern = /^https:\/\/open\.spotify\.com\/(track|playlist|album|artist)\/[a-zA-Z0-9]+/;
|
||||||
|
|
||||||
|
get isValidSpotifyUrl(): boolean {
|
||||||
|
return this.spotifyUrlPattern.test(this.url);
|
||||||
|
}
|
||||||
createLoading$ = this.playlistService.createLoading$;
|
createLoading$ = this.playlistService.createLoading$;
|
||||||
playlists$ = this.playlistService.all$.pipe(map(items => items.filter(item => !item.isTrack)));
|
playlists$ = this.playlistService.all$.pipe(map(items => items.filter(item => !item.isTrack)));
|
||||||
songs$ = this.playlistService.all$.pipe(map(items => items.filter(item => item.isTrack)));
|
songs$ = this.playlistService.all$.pipe(map(items => items.filter(item => item.isTrack)));
|
||||||
|
|||||||
Reference in New Issue
Block a user