Added delay to example loading

This commit is contained in:
Christian 2021-05-09 19:05:32 +02:00
parent 8e6d974ed9
commit fd78e1b7b7

View File

@ -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,6 +140,16 @@ 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 | dragDrop = { old_dragDrop | state = DS_Processing } }
, Task.perform
(\_ -> Msg_DEsmpl_LoadWithDelay example)
<| Process.sleep 500
)
Nothing ->
( model, Cmd.none )
Msg_DEsmpl_LoadWithDelay example ->
( model ( model
, Http.get , Http.get
{ url = example.url { url = example.url
@ -145,9 +157,6 @@ update msg model =
} }
) )
Nothing ->
( model, Cmd.none )
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,8 +529,20 @@ 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 =
case doDecodeModel mayLocalStorage of
Just init_model ->
({ pc_model = init_model.pc_model
, autoscroll = init_model.autoscroll
, examples = []
, exampleChooserOpen = False
, examplesListStatus = Waiting
, exampleLoaderStatus = Waiting
, dragDrop = initDragDrop
}
, Cmd.none )
Nothing ->
({ pc_model = PC.init ({ pc_model = PC.init
, autoscroll = True , autoscroll = True
, examples = [] , examples = []
@ -535,7 +563,7 @@ initDragDrop =
main : Program () Model Msg main : Program String Model Msg
main = main =
Browser.element Browser.element
{ init = init { init = init