Use page reload port to reload data without refresh in todo example.

This commit is contained in:
Dillon Kearns 2022-01-25 11:20:34 -08:00
parent 21d9ae9e35
commit 5342859ecd

View File

@ -18,6 +18,7 @@ import Html exposing (Html)
import Html.Attributes as Attr import Html.Attributes as Attr
import Http import Http
import Page exposing (Page, PageWithState, StaticPayload) import Page exposing (Page, PageWithState, StaticPayload)
import Pages
import Pages.PageUrl exposing (PageUrl) import Pages.PageUrl exposing (PageUrl)
import Pages.Url import Pages.Url
import Path exposing (Path) import Path exposing (Path)
@ -86,7 +87,7 @@ update pageUrl maybeNavigationKey sharedModel static msg model =
ReloadPage -> ReloadPage ->
( model ( model
, reloadDataSource maybeNavigationKey , Pages.reloadData
) )
MakeHttpRequest items -> MakeHttpRequest items ->
@ -129,14 +130,6 @@ update pageUrl maybeNavigationKey sharedModel static msg model =
) )
reloadDataSource : Maybe Browser.Navigation.Key -> Cmd msg
reloadDataSource maybeNavigationKey =
--maybeNavigationKey
-- |> Maybe.map (\key -> Browser.Navigation.pushUrl key "/todos")
-- |> Maybe.withDefault Cmd.none
Browser.Navigation.reload
subscriptions : Maybe PageUrl -> RouteParams -> Path -> Shared.Model -> Model -> Sub Msg subscriptions : Maybe PageUrl -> RouteParams -> Path -> Shared.Model -> Model -> Sub Msg
subscriptions maybePageUrl routeParams path sharedModel model = subscriptions maybePageUrl routeParams path sharedModel model =
Sub.none Sub.none
@ -280,33 +273,39 @@ view maybeUrl sharedModel model static =
[ Html.text item.description [ Html.text item.description
, deleteItemForm item.id , deleteItemForm item.id
|> Form.toHtml2 |> Form.toHtml2
{ makeHttpRequest = MakeHttpRequest { makeHttpRequest = MakeHttpRequest }
}
Html.form Html.form
(Form.init (deleteItemForm item.id)) (Form.init (deleteItemForm item.id))
] ]
) )
) )
, newItemForm , newItemForm
|> Form.toHtml { pageReloadSubmit = True } |> Form.toHtml2
{ makeHttpRequest = MakeHttpRequest }
Html.form Html.form
(Form.init newItemForm) (Form.init newItemForm)
|> Html.map FormMsg
] ]
} }
newItemForm : Form String TodoInput (Html Form.Msg) newItemForm : Form String TodoInput (Html Msg)
newItemForm = newItemForm =
Form.succeed (\description () -> TodoInput description) Form.succeed (\description () -> TodoInput description)
|> Form.with |> Form.with
(Form.text "description" (Form.text "description"
(\{ toInput } -> (\{ toInput } ->
Html.input (Attr.autofocus True :: toInput) [] Html.input (Attr.autofocus True :: toInput) []
|> Html.map (\_ -> NoOp)
) )
|> Form.required "Required" |> Form.required "Required"
) )
|> Form.with (Form.submit (\{ attrs } -> Html.button attrs [ Html.text "Submit" ])) |> Form.with
(Form.submit
(\{ attrs } ->
Html.button attrs [ Html.text "Submit" ]
|> Html.map (\_ -> NoOp)
)
)
deleteItemForm : String -> Form String String (Html Msg) deleteItemForm : String -> Form String String (Html Msg)