Skip to content

Commit

Permalink
Redirect on deck save
Browse files Browse the repository at this point in the history
  • Loading branch information
lsocrate committed Oct 18, 2021
1 parent c0afee2 commit 8800654
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions client/src/API/Decklist.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ module API.Decklist exposing (ResultCreate, ResultRead, create, read)

import Deck exposing (Deck)
import Http
import Json.Decode as Decode
import Json.Encode as Encode
import Shared
import Url exposing (Protocol(..))


type alias ResultCreate =
Result Http.Error ()
Result Http.Error String


create : (ResultCreate -> msg) -> Shared.Token -> Encode.Value -> Cmd msg
Expand All @@ -20,7 +21,7 @@ create msg token deck =
, timeout = Nothing
, tracker = Nothing
, body = Http.jsonBody deck
, expect = Http.expectWhatever msg
, expect = Http.expectJson msg (Decode.field "id" Decode.string)
}


Expand Down
11 changes: 9 additions & 2 deletions client/src/Pages/Build.elm
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module Pages.Build exposing (Model, Msg, page)

import API.Decklist
import Browser.Navigation as Navigation exposing (Key)
import Cards exposing (Card)
import Deck exposing (Decklist)
import Dict
import Effect exposing (Effect)
import Gen.Params.Build exposing (Params)
import Gen.Route as Route
import Html exposing (..)
import Html.Attributes exposing (checked, class, classList, name, placeholder, type_)
import Html.Events exposing (onClick, onInput, onSubmit)
Expand Down Expand Up @@ -47,6 +49,7 @@ type alias Model =
, showCollectionImages : Bool
, deck : Decklist
, deckName : DeckName
, key : Key
}


Expand All @@ -70,7 +73,7 @@ deckNameToString deckname =


init : Request.With Params -> ( Model, Effect Msg )
init _ =
init req =
( { stackFilters = UI.FilterSelection.stacks
, primaryFilters = UI.FilterSelection.primaryTraits
, secondaryFilters = UI.FilterSelection.secondaryTraits
Expand All @@ -82,6 +85,7 @@ init _ =
, showCollectionImages = False
, deck = Deck.empty
, deckName = Unnamed
, key = req.key
}
, Effect.none
)
Expand Down Expand Up @@ -185,7 +189,10 @@ update shared msg model =
( _, _ ) ->
( model, Effect.none )

SavedDecklist _ ->
SavedDecklist (Ok deckId) ->
( model, Route.toHref (Route.View__Id_ { id = deckId }) |> Navigation.pushUrl model.key |> Effect.fromCmd )

SavedDecklist (Err _) ->
( model, Effect.none )

StartRenameDeck ->
Expand Down

0 comments on commit 8800654

Please sign in to comment.