diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm index 5f10542..9d455e3 100644 --- a/frontend/src/Main.elm +++ b/frontend/src/Main.elm @@ -48,6 +48,12 @@ init flags url key = ) +type Page + = NotFound + | Index + | SwitchData PSD.Model + + type Msg = LinkClicked Browser.UrlRequest | UrlChanged Url.Url @@ -113,8 +119,17 @@ update msg model = , Nav.load "/" ) - _ -> - ( model, Cmd.none ) + GotSwitchDataMSG psd_msg -> + let + ( psd_model, cmd ) = + PSD.update + (Maybe.withDefault "" model.token) + psd_msg + model.switch_data_model + in + ( { model | switch_data_model = psd_model } + , Cmd.map GotSwitchDataMSG cmd + ) subscriptions : Model -> Sub Msg @@ -156,6 +171,9 @@ view model = ] ] + "/switch" -> + PSD.view model.switch_data_model + other -> template "Not found" [ h1 [] [ text "Not found" ] diff --git a/frontend/src/Page/SwitchData.elm b/frontend/src/Page/SwitchData.elm index ea0613f..7a629f9 100644 --- a/frontend/src/Page/SwitchData.elm +++ b/frontend/src/Page/SwitchData.elm @@ -29,12 +29,14 @@ type Data | Error String -init : Model +init : ( Model, Cmd Msg ) init = - Model + ( Model 0 40 Init + , NeedData + ) type Msg @@ -45,38 +47,42 @@ type Msg update : String -> Msg -> Model -> ( Model, Cmd Msg ) update token msg model = - case msg of - NeedData -> - ( model - , Mi.request - "GET" - token - (SwitchData.listURL model.limit model.page) - Http.emptyBody - (Mi.expectJson GotData (Json.Decode.list SwitchData.decoder)) - ) + if token == "" then + ( model, Cmd.none ) - Settings page limit -> - ( { model | page = page, limit = limit } - , Mi.request - "GET" - token - (SwitchData.listURL model.limit model.page) - Http.emptyBody - (Mi.expectJson GotData (Json.Decode.list SwitchData.decoder)) - ) + else + case msg of + NeedData -> + ( model + , Mi.request + "GET" + token + (SwitchData.listURL model.limit model.page) + Http.emptyBody + (Mi.expectJson GotData (Json.Decode.list SwitchData.decoder)) + ) - GotData result -> - case result of - Ok data -> - ( { model | data = HaveData data } - , Cmd.none - ) + Settings page limit -> + ( { model | page = page, limit = limit } + , Mi.request + "GET" + token + (SwitchData.listURL model.limit model.page) + Http.emptyBody + (Mi.expectJson GotData (Json.Decode.list SwitchData.decoder)) + ) - Err _ -> - ( { model | data = Error "got an error" } - , Cmd.none - ) + GotData result -> + case result of + Ok data -> + ( { model | data = HaveData data } + , Cmd.none + ) + + Err _ -> + ( { model | data = Error "got an error" } + , Cmd.none + ) view : Model -> Browser.Document msg diff --git a/frontend/src/SwitchData.elm b/frontend/src/SwitchData.elm index a5447fd..2d524ab 100644 --- a/frontend/src/SwitchData.elm +++ b/frontend/src/SwitchData.elm @@ -7,6 +7,8 @@ module SwitchData exposing , switchURL ) +import Html exposing (..) +import Html.Attributes exposing (..) import Iso8601 import Json.Decode exposing (Decoder, field, int, map5, nullable, string) import Time exposing (Posix)