mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-25 12:52:27 +03:00
Use page reload port to reload data without refresh in todo example.
This commit is contained in:
parent
21d9ae9e35
commit
5342859ecd
@ -18,6 +18,7 @@ import Html exposing (Html)
|
||||
import Html.Attributes as Attr
|
||||
import Http
|
||||
import Page exposing (Page, PageWithState, StaticPayload)
|
||||
import Pages
|
||||
import Pages.PageUrl exposing (PageUrl)
|
||||
import Pages.Url
|
||||
import Path exposing (Path)
|
||||
@ -86,7 +87,7 @@ update pageUrl maybeNavigationKey sharedModel static msg model =
|
||||
|
||||
ReloadPage ->
|
||||
( model
|
||||
, reloadDataSource maybeNavigationKey
|
||||
, Pages.reloadData
|
||||
)
|
||||
|
||||
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 maybePageUrl routeParams path sharedModel model =
|
||||
Sub.none
|
||||
@ -280,33 +273,39 @@ view maybeUrl sharedModel model static =
|
||||
[ Html.text item.description
|
||||
, deleteItemForm item.id
|
||||
|> Form.toHtml2
|
||||
{ makeHttpRequest = MakeHttpRequest
|
||||
}
|
||||
{ makeHttpRequest = MakeHttpRequest }
|
||||
Html.form
|
||||
(Form.init (deleteItemForm item.id))
|
||||
]
|
||||
)
|
||||
)
|
||||
, newItemForm
|
||||
|> Form.toHtml { pageReloadSubmit = True }
|
||||
|> Form.toHtml2
|
||||
{ makeHttpRequest = MakeHttpRequest }
|
||||
Html.form
|
||||
(Form.init newItemForm)
|
||||
|> Html.map FormMsg
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
newItemForm : Form String TodoInput (Html Form.Msg)
|
||||
newItemForm : Form String TodoInput (Html Msg)
|
||||
newItemForm =
|
||||
Form.succeed (\description () -> TodoInput description)
|
||||
|> Form.with
|
||||
(Form.text "description"
|
||||
(\{ toInput } ->
|
||||
Html.input (Attr.autofocus True :: toInput) []
|
||||
|> Html.map (\_ -> NoOp)
|
||||
)
|
||||
|> 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)
|
||||
|
Loading…
Reference in New Issue
Block a user