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
= 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" ]

View File

@ -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

View File

@ -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)