Skip to content

Commit

Permalink
fixed multi selection of artists/albums
Browse files Browse the repository at this point in the history
  • Loading branch information
tgambet committed Dec 22, 2018
1 parent f9c6368 commit 3278092
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 9 deletions.
7 changes: 7 additions & 0 deletions web/src/app/library/actions/albums.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Album} from '@app/model';

export enum AlbumsActionTypes {
LoadAlbums = 'library/albums/load',
SelectAlbum = 'library/albums/select-add',
SelectAlbums = 'library/albums/select',
SelectAlbumsByIds = 'library/albums/select-by-id',
DeselectAlbum = 'library/albums/deselect',
Expand All @@ -14,6 +15,11 @@ export class LoadAlbums implements Action {
constructor(public payload: Album[]) {}
}

export class SelectAlbum implements Action {
readonly type = AlbumsActionTypes.SelectAlbum;
constructor(public payload: Album) {}
}

export class SelectAlbums implements Action {
readonly type = AlbumsActionTypes.SelectAlbums;
constructor(public payload: Album[]) {}
Expand All @@ -35,6 +41,7 @@ export class DeselectAllAlbums implements Action {

export type AlbumsActionsUnion =
LoadAlbums |
SelectAlbum |
SelectAlbums |
SelectAlbumsByIds |
DeselectAlbum |
Expand Down
7 changes: 7 additions & 0 deletions web/src/app/library/actions/artists.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Artist} from '@app/model';

export enum ArtistsActionTypes {
LoadArtists = 'library/artists/load',
SelectArtist = 'library/artists/select-add',
SelectArtists = 'library/artists/select',
SelectArtistsByIds = 'library/artists/select-by-id',
DeselectArtist = 'library/artists/deselect',
Expand All @@ -14,6 +15,11 @@ export class LoadArtists implements Action {
constructor(public payload: Artist[]) {}
}

export class SelectArtist implements Action {
readonly type = ArtistsActionTypes.SelectArtist;
constructor(public payload: Artist) {}
}

export class SelectArtists implements Action {
readonly type = ArtistsActionTypes.SelectArtists;
constructor(public payload: Artist[]) {}
Expand All @@ -36,6 +42,7 @@ export class DeselectAllArtists implements Action {
export type ArtistsActionsUnion =
LoadArtists |
DeselectArtist |
SelectArtist |
SelectArtists |
SelectArtistsByIds |
DeselectAllArtists;
2 changes: 1 addition & 1 deletion web/src/app/library/components/albums.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class AlbumsComponent implements OnChanges {
}

select(album: Album) {
this.library.selectAlbums([album]);
this.library.selectAlbum(album);
}

isSelected(album: Album): Observable<boolean> {
Expand Down
12 changes: 6 additions & 6 deletions web/src/app/library/components/artists.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ import {SettingsService} from '@app/settings/services/settings.service';
[primaryHTML]="artist.name | sgSearch:search"
[secondaryHTML]="getSecondaryHTML(artist)"
[tooltip]="artist.name"
(click)="select(artist); next.emit()"
(arrowClicked)="add(artist); next.emit()"
(checked)="$event ? add(artist) : deselect(artist)">
(click)="selectOnly(artist); next.emit()"
(arrowClicked)="select(artist); next.emit()"
(checked)="$event ? select(artist) : deselect(artist)">
</app-list-item>
</mat-list>
</div>
Expand Down Expand Up @@ -214,13 +214,13 @@ export class ArtistsComponent implements OnChanges {
this.library.selectArtists(this.artists);
}

select(artist: Artist) {
selectOnly(artist: Artist) {
this.library.selectArtists([artist]);
this.showChipList = false;
}

add(artist: Artist) {
this.library.selectArtists([artist]);
select(artist: Artist) {
this.library.selectArtist(artist);
}

isSelected(artist: Artist): Observable<boolean> {
Expand Down
11 changes: 11 additions & 0 deletions web/src/app/library/reducers/albums.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ export function reducer(
};
}

case AlbumsActionTypes.SelectAlbum: {
if (state.selectedIds.indexOf(getAlbumId(action.payload)) === -1) {
return {
...state,
selectedIds: [...state.selectedIds, getAlbumId(action.payload)]
};
} else {
return state;
}
}

case AlbumsActionTypes.SelectAlbums: {
return {
...state,
Expand Down
11 changes: 11 additions & 0 deletions web/src/app/library/reducers/artists.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ export function reducer(
};
}

case ArtistsActionTypes.SelectArtist: {
if (state.selectedIds.indexOf(action.payload.name) === -1) {
return {
...state,
selectedIds: [...state.selectedIds, action.payload.name]
};
} else {
return state;
}
}

case ArtistsActionTypes.SelectArtists: {
return {
...state,
Expand Down
12 changes: 10 additions & 2 deletions web/src/app/library/services/library.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {AudioService} from '@app/core/services/audio.service';
import {LoaderService} from '@app/core/services/loader.service';

import {AddToPlaylist, DeletePlaylist, LoadPlaylist, LoadPlaylists, RemoveFromPlaylist, SavePlaylist} from '../actions/playlists.actions';
import {DeselectAllArtists, DeselectArtist, SelectArtists, SelectArtistsByIds} from '../actions/artists.actions';
import {DeselectAlbum, DeselectAllAlbums, SelectAlbums, SelectAlbumsByIds} from '../actions/albums.actions';
import {DeselectAllArtists, DeselectArtist, SelectArtist, SelectArtists, SelectArtistsByIds} from '../actions/artists.actions';
import {DeselectAlbum, DeselectAllAlbums, SelectAlbum, SelectAlbums, SelectAlbumsByIds} from '../actions/albums.actions';
import {
AddToCurrentPlaylist,
PlayTrackNext,
Expand Down Expand Up @@ -177,6 +177,10 @@ export class LibraryService {
return this.store.select(fromLibrary.getCurrentPlaylist);
}

selectArtist(artist: Artist) {
this.store.dispatch(new SelectArtist(artist));
}

selectArtists(artists: Artist[]) {
this.store.dispatch(new SelectArtists(artists));
}
Expand All @@ -193,6 +197,10 @@ export class LibraryService {
return this.store.select(fromLibrary.isSelectedArtist(artist));
}

selectAlbum(album: Album) {
this.store.dispatch(new SelectAlbum(album));
}

selectAlbums(albums: Album[]) {
this.store.dispatch(new SelectAlbums(albums));
}
Expand Down

0 comments on commit 3278092

Please sign in to comment.