Permalink
Browse files

Update artist listing to use new service api

  • Loading branch information...
rundis committed Nov 18, 2016
1 parent 2a8f8db commit 2c7ced33102f54ee974034c20a5eaa7198da9c49
Showing with 25 additions and 18 deletions.
  1. +25 −18 frontend/src/ArtistListing.elm
@@ -16,11 +16,9 @@ type alias Model =
type Msg
= Show
| HandleArtistsRetrieved (List Artist)
| FetchArtistsFailed Http.Error
| HandleArtistsRetrieved (Result Http.Error (List Artist))
| DeleteArtist Int
| HandleArtistDeleted
| DeleteFailed
| HandleArtistDeleted (Result Http.Error String)
init : Model
@@ -30,7 +28,7 @@ init =
mountCmd : Cmd Msg
mountCmd =
ServerApi.getArtists FetchArtistsFailed HandleArtistsRetrieved
ServerApi.getArtists HandleArtistsRetrieved
update : Msg -> Model -> ( Model, Cmd Msg )
@@ -39,24 +37,33 @@ update action model =
Show ->
( model, mountCmd )
HandleArtistsRetrieved artists ->
( { model | artists = artists }
, Cmd.none
)
HandleArtistsRetrieved res ->
case res of
Result.Ok artists ->
( { model | artists = artists }
, Cmd.none
)
Result.Err err ->
let _ = Debug.log "Error retrieving artist" err
in
(model, Cmd.none)
-- Handle error
FetchArtistsFailed err ->
( model, Cmd.none )
DeleteArtist id ->
( model, deleteArtist id DeleteFailed HandleArtistDeleted )
( model, deleteArtist id HandleArtistDeleted )
HandleArtistDeleted res ->
case res of
Result.Ok _ ->
update Show model
Result.Err err ->
let _ = Debug.log "Error deleting artist" err
in
(model, Cmd.none)
HandleArtistDeleted ->
update Show model
-- Show generic error
DeleteFailed ->
( model, Cmd.none )

0 comments on commit 2c7ced3

Please sign in to comment.