From 64ff4707fdcd81c27c6be9903c3c82bc543ef016 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 27 Mar 2017 10:18:40 +0200 Subject: Modelize punctual and monthly payment pages --- src/client/LoggedIn/Home/Update.elm | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src/client/LoggedIn/Home/Update.elm') diff --git a/src/client/LoggedIn/Home/Update.elm b/src/client/LoggedIn/Home/Update.elm index b0ce256..06c2c7e 100644 --- a/src/client/LoggedIn/Home/Update.elm +++ b/src/client/LoggedIn/Home/Update.elm @@ -5,9 +5,9 @@ module LoggedIn.Home.Update exposing import Form exposing (Form) import LoggedData exposing (LoggedData) - -import LoggedIn.Home.Msg as Home import LoggedIn.Home.Model as Home +import LoggedIn.Home.Msg as Home +import Model.Frequency as Frequency exposing (Frequency(..)) update : LoggedData -> Home.Msg -> Home.Model -> (Home.Model, Cmd Home.Msg) update loggedData msg model = @@ -19,17 +19,26 @@ update loggedData msg model = ) Home.UpdatePage page -> - ( { model | currentPage = page } + ( updatePage page model , Cmd.none ) Home.SearchMsg formMsg -> - ( { model - | search = Form.update Home.validation formMsg model.search - , currentPage = + let newModel = case formMsg of - Form.Input "name" _ _ -> 1 - _ -> model.currentPage - } - , Cmd.none - ) + Form.Input "name" _ _ -> updatePage 1 model + _ -> model + in ( { model | search = Form.update Home.validation formMsg model.search } + , Cmd.none + ) + +updatePage : Int -> Home.Model -> Home.Model +updatePage page model = + let frequency = + Form.getFieldAsString "frequency" model.search + |> .value + |> Maybe.andThen Frequency.fromString + in case frequency of + Just Punctual -> { model | punctualPage = page } + Just Monthly -> { model | monthlyPage = page } + Nothing -> model -- cgit v1.2.3