feat: use number inputs for SongEdit form

This commit is contained in:
Phan An 2022-07-21 10:08:17 +02:00
parent d7210f7d52
commit c6aeda1730
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC
5 changed files with 20 additions and 19 deletions

View file

@ -26,8 +26,8 @@ final class SongUpdateData implements Arrayable
artistName: $request->input('data.artist_name'),
albumName: $request->input('data.album_name'),
albumArtistName: $request->input('data.album_artist_name'),
track: $request->input('data.track'),
disc: $request->input('data.disc'),
track: (int) $request->input('data.track'),
disc: (int) $request->input('data.disc'),
lyrics: $request->input('data.lyrics'),
);
}

View file

@ -58,8 +58,8 @@ new class extends UnitTestCase {
artist_name: 'AC/DC',
album_artist_name: 'AC/DC',
lyrics: 'I\'m gonna make him an offer he can\'t refuse',
track: '10',
disc: '1'
track: 10,
disc: 1
})
expect(alertMock).toHaveBeenCalledWith('Updated 1 song.')
@ -87,8 +87,8 @@ new class extends UnitTestCase {
album_name: 'Back in Black',
artist_name: 'AC/DC',
album_artist_name: 'AC/DC',
track: '10',
disc: '1'
track: 10,
disc: 1
})
expect(alertMock).toHaveBeenCalledWith('Updated 3 songs.')

View file

@ -108,10 +108,9 @@
v-model="formData.track"
:placeholder="inputPlaceholder"
data-testid="track-input"
min="1"
name="track"
pattern="\d*"
title="Empty or a number"
type="text"
type="number"
>
</div>
<div>
@ -120,10 +119,9 @@
v-model="formData.disc"
:placeholder="inputPlaceholder"
data-testid="disc-input"
min="1"
name="disc"
pattern="\d*"
title="Empty or a number"
type="text"
type="number"
>
</div>
</div>
@ -174,8 +172,8 @@ type EditFormData = {
artist_name?: string
album_name?: string
album_artist_name?: string
track?: string | null
disc?: string | null
track?: number | null
disc?: number | null
lyrics?: string
}
@ -252,8 +250,12 @@ const open = async () => {
}
formData.lyrics = editingOnlyOneSong.value ? firstSong.lyrics : ''
formData.track = allSongsShareSameValue('track') ? firstSong.track : null
formData.track = formData.track || null // if 0, just don't show it
formData.disc = allSongsShareSameValue('disc') ? firstSong.disc : null
formData.disc = formData.disc || null // if 0, just don't show it
if (!editingOnlyOneSong.value) {
delete formData.title

View file

@ -20,8 +20,8 @@ exports[`edits a single song 1`] = `
<div class="form-row" data-v-5f0f6176=""><label data-v-5f0f6176="">Album Artist</label><input placeholder="" data-testid="albumArtist-input" name="album_artist" type="text" data-v-5f0f6176=""></div>
<div class="form-row" data-v-5f0f6176="">
<div class="cols" data-v-5f0f6176="">
<div data-v-5f0f6176=""><label data-v-5f0f6176="">Track</label><input placeholder="" data-testid="track-input" name="track" pattern="\\d*" title="Empty or a number" type="text" data-v-5f0f6176=""></div>
<div data-v-5f0f6176=""><label data-v-5f0f6176="">Disc</label><input placeholder="" data-testid="disc-input" name="disc" pattern="\\d*" title="Empty or a number" type="text" data-v-5f0f6176=""></div>
<div data-v-5f0f6176=""><label data-v-5f0f6176="">Track</label><input placeholder="" data-testid="track-input" min="1" name="track" type="number" data-v-5f0f6176=""></div>
<div data-v-5f0f6176=""><label data-v-5f0f6176="">Disc</label><input placeholder="" data-testid="disc-input" min="1" name="disc" type="number" data-v-5f0f6176=""></div>
</div>
</div>
</div>
@ -57,8 +57,8 @@ exports[`edits multiple songs 1`] = `
<div class="form-row" data-v-5f0f6176=""><label data-v-5f0f6176="">Album Artist</label><input placeholder="Leave unchanged" data-testid="albumArtist-input" name="album_artist" type="text" data-v-5f0f6176=""></div>
<div class="form-row" data-v-5f0f6176="">
<div class="cols" data-v-5f0f6176="">
<div data-v-5f0f6176=""><label data-v-5f0f6176="">Track</label><input placeholder="Leave unchanged" data-testid="track-input" name="track" pattern="\\d*" title="Empty or a number" type="text" data-v-5f0f6176=""></div>
<div data-v-5f0f6176=""><label data-v-5f0f6176="">Disc</label><input placeholder="Leave unchanged" data-testid="disc-input" name="disc" pattern="\\d*" title="Empty or a number" type="text" data-v-5f0f6176=""></div>
<div data-v-5f0f6176=""><label data-v-5f0f6176="">Track</label><input placeholder="Leave unchanged" data-testid="track-input" min="1" name="track" type="number" data-v-5f0f6176=""></div>
<div data-v-5f0f6176=""><label data-v-5f0f6176="">Disc</label><input placeholder="Leave unchanged" data-testid="disc-input" min="1" name="disc" type="number" data-v-5f0f6176=""></div>
</div>
</div>
</div>

View file

@ -112,7 +112,6 @@ export const songStore = {
scrobble: async (song: Song) => await httpService.post(`${song.id}/scrobble`, { timestamp: song.play_start_time }),
async update (songsToUpdate: Song[], data: any) {
console.log(data)
const { songs, artists, albums, removed } = await httpService.put<SongUpdateResult>('songs', {
data,
songs: songsToUpdate.map(song => song.id)