This commit is contained in:
Dillon Kearns 2022-04-04 14:45:14 -07:00
parent fc62058f63
commit 4ab29c6b0f
2 changed files with 12 additions and 12 deletions

View File

@ -11,7 +11,7 @@ type Effect msg
| Cmd (Cmd msg)
| Batch (List (Effect msg))
| GetStargazers (Result Http.Error Int -> msg)
| FetchPageData
| FetchRouteData
{ body : Maybe { contentType : String, body : String }
, path : Maybe String
, toMsg : Result Http.Error Url -> msg
@ -54,8 +54,8 @@ map fn effect =
GetStargazers toMsg ->
GetStargazers (toMsg >> fn)
FetchPageData fetchInfo ->
FetchPageData
FetchRouteData fetchInfo ->
FetchRouteData
{ body = fetchInfo.body
, path = fetchInfo.path
, toMsg = fetchInfo.toMsg >> fn
@ -74,7 +74,7 @@ perform :
-> Browser.Navigation.Key
-> Effect pageMsg
-> Cmd msg
perform info fromPageMsg key effect =
perform helpers fromPageMsg key effect =
case effect of
None ->
Cmd.none
@ -83,7 +83,7 @@ perform info fromPageMsg key effect =
Cmd.map fromPageMsg cmd
Batch list ->
Cmd.batch (List.map (perform info fromPageMsg key) list)
Cmd.batch (List.map (perform helpers fromPageMsg key) list)
GetStargazers toMsg ->
Http.get
@ -92,8 +92,8 @@ perform info fromPageMsg key effect =
, expect = Http.expectJson (toMsg >> fromPageMsg) (Decode.field "stargazers_count" Decode.int)
}
FetchPageData fetchInfo ->
info.fetchRouteData
FetchRouteData fetchInfo ->
helpers.fetchRouteData
{ body = fetchInfo.body
, path = fetchInfo.path
, toMsg = fetchInfo.toMsg

View File

@ -40,7 +40,7 @@ type alias Model =
type Msg
= FormMsg Form.Msg
| NoOp
| MakeHttpRequest { contentType : String, body : String }
| FormSubmitted { contentType : String, body : String }
| SubmitComplete
@ -86,9 +86,9 @@ update pageUrl sharedModel static msg model =
NoOp ->
( model, Effect.none )
MakeHttpRequest info ->
FormSubmitted info ->
( { model | submitting = True }
, Effect.FetchPageData
, Effect.FetchRouteData
{ body = Just info
, path = Nothing
, toMsg = \_ -> SubmitComplete
@ -234,7 +234,7 @@ view maybeUrl sharedModel model static =
[ Html.text item.description
, deleteItemForm item.id
|> Form.toHtml2
{ onSubmit = MakeHttpRequest }
{ onSubmit = FormSubmitted }
Html.form
(Form.init (deleteItemForm item.id))
]
@ -242,7 +242,7 @@ view maybeUrl sharedModel model static =
)
, newItemForm model.submitting
|> Form.toHtml2
{ onSubmit = MakeHttpRequest }
{ onSubmit = FormSubmitted }
Html.form
(Form.init (newItemForm model.submitting))
]