From 8800654b9dd0832f1bcff8cbac32a83c9aa79b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20S=C3=B3crate?= Date: Mon, 18 Oct 2021 23:43:10 +0200 Subject: [PATCH] Redirect on deck save --- client/src/API/Decklist.elm | 5 +++-- client/src/Pages/Build.elm | 11 +++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/src/API/Decklist.elm b/client/src/API/Decklist.elm index 29cfea4f..f61509aa 100644 --- a/client/src/API/Decklist.elm +++ b/client/src/API/Decklist.elm @@ -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 @@ -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) } diff --git a/client/src/Pages/Build.elm b/client/src/Pages/Build.elm index db3c51ca..1bb2edd6 100644 --- a/client/src/Pages/Build.elm +++ b/client/src/Pages/Build.elm @@ -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) @@ -47,6 +49,7 @@ type alias Model = , showCollectionImages : Bool , deck : Decklist , deckName : DeckName + , key : Key } @@ -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 @@ -82,6 +85,7 @@ init _ = , showCollectionImages = False , deck = Deck.empty , deckName = Unnamed + , key = req.key } , Effect.none ) @@ -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 ->