Added delay to example loading
This commit is contained in:
parent
8b3d2d525b
commit
f2fe410cc1
72
src/Main.elm
72
src/Main.elm
@ -81,6 +81,7 @@ type Msg
|
|||||||
| Msg_Autoscroll_Toggle
|
| Msg_Autoscroll_Toggle
|
||||||
| Msg_DEsmpl_Open Bool
|
| Msg_DEsmpl_Open Bool
|
||||||
| Msg_DEsmpl_EClick Int
|
| Msg_DEsmpl_EClick Int
|
||||||
|
| Msg_DEsmpl_LoadWithDelay Example
|
||||||
| Msg_DEsmpl_ExampleLoaded (Result Http.Error Model)
|
| Msg_DEsmpl_ExampleLoaded (Result Http.Error Model)
|
||||||
| Msg_DEsmpl_ListLoaded (Result Http.Error (List Example))
|
| Msg_DEsmpl_ListLoaded (Result Http.Error (List Example))
|
||||||
| Msg_DEsmpl_Download
|
| Msg_DEsmpl_Download
|
||||||
@ -88,6 +89,7 @@ type Msg
|
|||||||
| Msg_DrgDrp_Hover Bool
|
| Msg_DrgDrp_Hover Bool
|
||||||
| Msg_DrgDrp_GotFiles File (List File)
|
| Msg_DrgDrp_GotFiles File (List File)
|
||||||
| Msg_DrgDrp_DecodedFiles String
|
| Msg_DrgDrp_DecodedFiles String
|
||||||
|
| Msg_Nothing
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
@ -138,16 +140,23 @@ update msg model =
|
|||||||
Msg_DEsmpl_EClick i -> -- User chose example. Load it.
|
Msg_DEsmpl_EClick i -> -- User chose example. Load it.
|
||||||
case valueAt i model.examples of
|
case valueAt i model.examples of
|
||||||
Just example ->
|
Just example ->
|
||||||
( model
|
( { model | dragDrop = { old_dragDrop | state = DS_Processing } }
|
||||||
, Http.get
|
, Task.perform
|
||||||
{ url = example.url
|
(\_ -> Msg_DEsmpl_LoadWithDelay example)
|
||||||
, expect = Http.expectJson Msg_DEsmpl_ExampleLoaded modelDecoder
|
<| Process.sleep 500
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
( model, Cmd.none )
|
( model, Cmd.none )
|
||||||
|
|
||||||
|
Msg_DEsmpl_LoadWithDelay example ->
|
||||||
|
( model
|
||||||
|
, Http.get
|
||||||
|
{ url = example.url
|
||||||
|
, expect = Http.expectJson Msg_DEsmpl_ExampleLoaded modelDecoder
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
Msg_DEsmpl_ExampleLoaded result -> -- When a single example is loaded
|
Msg_DEsmpl_ExampleLoaded result -> -- When a single example is loaded
|
||||||
case result of
|
case result of
|
||||||
Ok example_model ->
|
Ok example_model ->
|
||||||
@ -157,11 +166,16 @@ update msg model =
|
|||||||
| pc_model = example_model.pc_model
|
| pc_model = example_model.pc_model
|
||||||
, exampleLoaderStatus = Success
|
, exampleLoaderStatus = Success
|
||||||
, exampleChooserOpen = False
|
, exampleChooserOpen = False
|
||||||
|
, dragDrop = { old_dragDrop | state = DS_Sucess }
|
||||||
}
|
}
|
||||||
in
|
in
|
||||||
( new_model, cmd_up_lStorage_n_Scroller new_model )
|
( new_model
|
||||||
|
, cmd_up_lStorage_n_Scroller new_model
|
||||||
|
)
|
||||||
Err err ->
|
Err err ->
|
||||||
( { model | exampleLoaderStatus = Failure <| printHttpError err }
|
( { model | exampleLoaderStatus = Failure <| printHttpError err
|
||||||
|
, dragDrop = { old_dragDrop | state = DS_Sucess }
|
||||||
|
}
|
||||||
, Cmd.none )
|
, Cmd.none )
|
||||||
|
|
||||||
|
|
||||||
@ -243,6 +257,8 @@ update msg model =
|
|||||||
, sendProcessing "Done"
|
, sendProcessing "Done"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Msg_Nothing -> (model, Cmd.none)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- ###############################################################################
|
-- ###############################################################################
|
||||||
@ -453,10 +469,10 @@ viewDragDrop model =
|
|||||||
, p
|
, p
|
||||||
[]
|
[]
|
||||||
[ case (model.dragDrop.hover, model.dragDrop.state) of
|
[ case (model.dragDrop.hover, model.dragDrop.state) of
|
||||||
(_,DS_Failure) -> text <| "Oh no, that didn't work. " ++ Debug.toString model.dragDrop
|
(_,DS_Failure) -> text <| "Oh no, that didn't work. "
|
||||||
(_,DS_Processing) -> text "Processing. Hold on tight."
|
(_,DS_Processing) -> text "Loading. Hold on tight."
|
||||||
(True,_) -> text "Let go to load the file."
|
(True,_) -> text "Let go to load the file."
|
||||||
(_,DS_Sucess) -> text <| "Success" ++ Debug.toString model.dragDrop
|
(_,DS_Sucess) -> text <| "Success"
|
||||||
(_,DS_Ready) -> text "Let go to load the file."
|
(_,DS_Ready) -> text "Let go to load the file."
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
@ -513,17 +529,29 @@ subscriptions model =
|
|||||||
|
|
||||||
|
|
||||||
-- TODO: Make it load localStorage when starting
|
-- TODO: Make it load localStorage when starting
|
||||||
init : () -> ( Model, Cmd Msg )
|
init : String -> ( Model, Cmd Msg )
|
||||||
init flags =
|
init mayLocalStorage =
|
||||||
({ pc_model = PC.init
|
case doDecodeModel mayLocalStorage of
|
||||||
, autoscroll = True
|
Just init_model ->
|
||||||
, examples = []
|
({ pc_model = init_model.pc_model
|
||||||
, exampleChooserOpen = False
|
, autoscroll = init_model.autoscroll
|
||||||
, examplesListStatus = Waiting
|
, examples = []
|
||||||
, exampleLoaderStatus = Waiting
|
, exampleChooserOpen = False
|
||||||
, dragDrop = initDragDrop
|
, examplesListStatus = Waiting
|
||||||
}
|
, exampleLoaderStatus = Waiting
|
||||||
, Cmd.none )
|
, dragDrop = initDragDrop
|
||||||
|
}
|
||||||
|
, Cmd.none )
|
||||||
|
Nothing ->
|
||||||
|
({ pc_model = PC.init
|
||||||
|
, autoscroll = True
|
||||||
|
, examples = []
|
||||||
|
, exampleChooserOpen = False
|
||||||
|
, examplesListStatus = Waiting
|
||||||
|
, exampleLoaderStatus = Waiting
|
||||||
|
, dragDrop = initDragDrop
|
||||||
|
}
|
||||||
|
, Cmd.none )
|
||||||
|
|
||||||
initDragDrop : DragDrop
|
initDragDrop : DragDrop
|
||||||
initDragDrop =
|
initDragDrop =
|
||||||
@ -535,7 +563,7 @@ initDragDrop =
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
main : Program () Model Msg
|
main : Program String Model Msg
|
||||||
main =
|
main =
|
||||||
Browser.element
|
Browser.element
|
||||||
{ init = init
|
{ init = init
|
||||||
|
Loading…
x
Reference in New Issue
Block a user