attempt :D

This commit is contained in:
Cadey Ratio 2020-01-15 22:40:17 +00:00
parent b36f2a3cf6
commit aac4592c53
3 changed files with 59 additions and 33 deletions

View File

@ -48,6 +48,12 @@ init flags url key =
) )
type Page
= NotFound
| Index
| SwitchData PSD.Model
type Msg type Msg
= LinkClicked Browser.UrlRequest = LinkClicked Browser.UrlRequest
| UrlChanged Url.Url | UrlChanged Url.Url
@ -113,8 +119,17 @@ update msg model =
, Nav.load "/" , Nav.load "/"
) )
_ -> GotSwitchDataMSG psd_msg ->
( model, Cmd.none ) 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 subscriptions : Model -> Sub Msg
@ -156,6 +171,9 @@ view model =
] ]
] ]
"/switch" ->
PSD.view model.switch_data_model
other -> other ->
template "Not found" template "Not found"
[ h1 [] [ text "Not found" ] [ h1 [] [ text "Not found" ]

View File

@ -29,12 +29,14 @@ type Data
| Error String | Error String
init : Model init : ( Model, Cmd Msg )
init = init =
Model ( Model
0 0
40 40
Init Init
, NeedData
)
type Msg type Msg
@ -45,38 +47,42 @@ type Msg
update : String -> Msg -> Model -> ( Model, Cmd Msg ) update : String -> Msg -> Model -> ( Model, Cmd Msg )
update token msg model = update token msg model =
case msg of if token == "" then
NeedData -> ( model, Cmd.none )
( model
, Mi.request
"GET"
token
(SwitchData.listURL model.limit model.page)
Http.emptyBody
(Mi.expectJson GotData (Json.Decode.list SwitchData.decoder))
)
Settings page limit -> else
( { model | page = page, limit = limit } case msg of
, Mi.request NeedData ->
"GET" ( model
token , Mi.request
(SwitchData.listURL model.limit model.page) "GET"
Http.emptyBody token
(Mi.expectJson GotData (Json.Decode.list SwitchData.decoder)) (SwitchData.listURL model.limit model.page)
) Http.emptyBody
(Mi.expectJson GotData (Json.Decode.list SwitchData.decoder))
)
GotData result -> Settings page limit ->
case result of ( { model | page = page, limit = limit }
Ok data -> , Mi.request
( { model | data = HaveData data } "GET"
, Cmd.none token
) (SwitchData.listURL model.limit model.page)
Http.emptyBody
(Mi.expectJson GotData (Json.Decode.list SwitchData.decoder))
)
Err _ -> GotData result ->
( { model | data = Error "got an error" } case result of
, Cmd.none Ok data ->
) ( { model | data = HaveData data }
, Cmd.none
)
Err _ ->
( { model | data = Error "got an error" }
, Cmd.none
)
view : Model -> Browser.Document msg view : Model -> Browser.Document msg

View File

@ -7,6 +7,8 @@ module SwitchData exposing
, switchURL , switchURL
) )
import Html exposing (..)
import Html.Attributes exposing (..)
import Iso8601 import Iso8601
import Json.Decode exposing (Decoder, field, int, map5, nullable, string) import Json.Decode exposing (Decoder, field, int, map5, nullable, string)
import Time exposing (Posix) import Time exposing (Posix)