mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-24 06:54:03 +03:00
Change nesting to minimize diff.
This commit is contained in:
parent
3c9d761d60
commit
c85936614f
@ -116,103 +116,83 @@ type Action
|
||||
| CheckAll Bool
|
||||
|
||||
|
||||
update :
|
||||
PageUrl
|
||||
-> Shared.Model
|
||||
-> StaticPayload Data ActionData RouteParams
|
||||
-> Msg
|
||||
-> Model
|
||||
-> ( Model, Effect Msg )
|
||||
update pageUrl sharedModel static msg model =
|
||||
case msg of
|
||||
NoOp ->
|
||||
( model, Effect.none )
|
||||
|
||||
ClearNewItemInput ->
|
||||
( model
|
||||
, Effect.SetField
|
||||
{ formId = "new-item"
|
||||
, name = "description"
|
||||
, value = ""
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
action : RouteParams -> Request.Parser (DataSource (Response ActionData ErrorPage))
|
||||
action routeParams =
|
||||
MySession.withSession
|
||||
(Request.formData [ newItemForm, completeItemForm, deleteItemForm, editItemForm, clearCompletedForm, toggleAllForm ])
|
||||
(\formResult session ->
|
||||
let
|
||||
okSessionThing : Session
|
||||
okSessionThing =
|
||||
session
|
||||
|> Result.withDefault Nothing
|
||||
|> Maybe.withDefault Session.empty
|
||||
in
|
||||
case formResult of
|
||||
Ok (Add newItemDescription) ->
|
||||
withUserSession session
|
||||
(\userId ->
|
||||
Data.Todo.create userId newItemDescription
|
||||
|> Request.Hasura.mutationDataSource
|
||||
|> DataSource.map (\_ -> Response.render {})
|
||||
)
|
||||
Ok actionInput ->
|
||||
case actionInput of
|
||||
Add newItemDescription ->
|
||||
withUserSession session
|
||||
(\userId ->
|
||||
Data.Todo.create userId newItemDescription
|
||||
|> Request.Hasura.mutationDataSource
|
||||
|> DataSource.map (\_ -> Response.render {})
|
||||
)
|
||||
|
||||
Ok (UpdateEntry ( itemId, newDescription )) ->
|
||||
withUserSession session
|
||||
(\userId ->
|
||||
Data.Todo.update
|
||||
{ userId = userId
|
||||
, todoId = Uuid itemId
|
||||
, newDescription = newDescription
|
||||
}
|
||||
|> Request.Hasura.mutationDataSource
|
||||
|> DataSource.map (\() -> Response.render {})
|
||||
)
|
||||
UpdateEntry ( itemId, newDescription ) ->
|
||||
withUserSession session
|
||||
(\userId ->
|
||||
Data.Todo.update
|
||||
{ userId = userId
|
||||
, todoId = Uuid itemId
|
||||
, newDescription = newDescription
|
||||
}
|
||||
|> Request.Hasura.mutationDataSource
|
||||
|> DataSource.map (\() -> Response.render {})
|
||||
)
|
||||
|
||||
Ok (Delete itemId) ->
|
||||
withUserSession session
|
||||
(\userId ->
|
||||
Data.Todo.delete
|
||||
{ userId = userId
|
||||
, itemId = Uuid itemId
|
||||
}
|
||||
|> Request.Hasura.mutationDataSource
|
||||
|> DataSource.map (\() -> Response.render {})
|
||||
)
|
||||
Delete itemId ->
|
||||
withUserSession session
|
||||
(\userId ->
|
||||
Data.Todo.delete
|
||||
{ userId = userId
|
||||
, itemId = Uuid itemId
|
||||
}
|
||||
|> Request.Hasura.mutationDataSource
|
||||
|> DataSource.map (\() -> Response.render {})
|
||||
)
|
||||
|
||||
Ok DeleteComplete ->
|
||||
withUserSession session
|
||||
(\userId ->
|
||||
Data.Todo.clearCompletedTodos userId
|
||||
|> Request.Hasura.mutationDataSource
|
||||
|> DataSource.map (\() -> Response.render {})
|
||||
)
|
||||
DeleteComplete ->
|
||||
withUserSession session
|
||||
(\userId ->
|
||||
Data.Todo.clearCompletedTodos userId
|
||||
|> Request.Hasura.mutationDataSource
|
||||
|> DataSource.map (\() -> Response.render {})
|
||||
)
|
||||
|
||||
Ok (Check ( newCompleteValue, itemId )) ->
|
||||
withUserSession session
|
||||
(\userId ->
|
||||
Data.Todo.setCompleteTo
|
||||
{ userId = userId
|
||||
, itemId = Uuid itemId
|
||||
, newCompleteValue = newCompleteValue
|
||||
}
|
||||
|> Request.Hasura.mutationDataSource
|
||||
|> DataSource.map (\() -> Response.render {})
|
||||
)
|
||||
Check ( newCompleteValue, itemId ) ->
|
||||
withUserSession session
|
||||
(\userId ->
|
||||
Data.Todo.setCompleteTo
|
||||
{ userId = userId
|
||||
, itemId = Uuid itemId
|
||||
, newCompleteValue = newCompleteValue
|
||||
}
|
||||
|> Request.Hasura.mutationDataSource
|
||||
|> DataSource.map (\() -> Response.render {})
|
||||
)
|
||||
|
||||
Ok (CheckAll toggleTo) ->
|
||||
withUserSession session
|
||||
(\userId ->
|
||||
Data.Todo.toggleAllTo userId toggleTo
|
||||
|> Request.Hasura.mutationDataSource
|
||||
|> DataSource.map (\() -> Response.render {})
|
||||
)
|
||||
CheckAll toggleTo ->
|
||||
withUserSession session
|
||||
(\userId ->
|
||||
Data.Todo.toggleAllTo userId toggleTo
|
||||
|> Request.Hasura.mutationDataSource
|
||||
|> DataSource.map (\() -> Response.render {})
|
||||
)
|
||||
|
||||
Err _ ->
|
||||
let
|
||||
okSession : Session
|
||||
okSession =
|
||||
session
|
||||
|> Result.withDefault Nothing
|
||||
|> Maybe.withDefault Session.empty
|
||||
in
|
||||
DataSource.succeed
|
||||
( okSessionThing
|
||||
( okSession
|
||||
, Response.render {}
|
||||
)
|
||||
)
|
||||
@ -263,6 +243,28 @@ withUserSession cookieSession continue =
|
||||
)
|
||||
|
||||
|
||||
update :
|
||||
PageUrl
|
||||
-> Shared.Model
|
||||
-> StaticPayload Data ActionData RouteParams
|
||||
-> Msg
|
||||
-> Model
|
||||
-> ( Model, Effect Msg )
|
||||
update pageUrl sharedModel static msg model =
|
||||
case msg of
|
||||
NoOp ->
|
||||
( model, Effect.none )
|
||||
|
||||
ClearNewItemInput ->
|
||||
( model
|
||||
, Effect.SetField
|
||||
{ formId = "new-item"
|
||||
, name = "description"
|
||||
, value = ""
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
subscriptions : Maybe PageUrl -> RouteParams -> Path -> Shared.Model -> Model -> Sub Msg
|
||||
subscriptions maybePageUrl routeParams path sharedModel model =
|
||||
Sub.none
|
||||
|
Loading…
Reference in New Issue
Block a user