module LoggedIn.Home.Update exposing ( update ) import Form exposing (Form) import LoggedData exposing (LoggedData) 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 = case msg of Home.NoOp -> ( model , Cmd.none ) Home.UpdatePage page -> ( updatePage page model , Cmd.none ) Home.SearchMsg formMsg -> let newModel = case formMsg of 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