mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-25 04:43:03 +03:00
Reorganize example.
This commit is contained in:
parent
9b51b26c72
commit
20632f90b2
@ -89,11 +89,16 @@ type alias ActionData =
|
||||
{}
|
||||
|
||||
|
||||
init :
|
||||
Maybe PageUrl
|
||||
-> Shared.Model
|
||||
-> StaticPayload Data ActionData RouteParams
|
||||
-> ( Model, Effect Msg )
|
||||
toOptimisticTodo : Data.Todo.Todo -> Entry
|
||||
toOptimisticTodo todo =
|
||||
{ description = todo.description
|
||||
, completed = todo.completed
|
||||
, isSaving = False
|
||||
, id = todo.id
|
||||
}
|
||||
|
||||
|
||||
init : Maybe PageUrl -> Shared.Model -> StaticPayload Data ActionData RouteParams -> ( Model, Effect Msg )
|
||||
init maybePageUrl sharedModel app =
|
||||
( { nextId = app.data.requestTime }
|
||||
, Effect.none
|
||||
@ -196,6 +201,39 @@ performAction requestTime actionInput userId =
|
||||
|> DataSource.map (\() -> Response.render {})
|
||||
|
||||
|
||||
data : RouteParams -> Request.Parser (DataSource (Response Data ErrorPage))
|
||||
data routeParams =
|
||||
Request.requestTime
|
||||
|> MySession.expectSessionDataOrRedirect (Session.get "sessionId")
|
||||
(\parsedSession requestTime session ->
|
||||
case visibilityFromRouteParams routeParams of
|
||||
Just visibility ->
|
||||
Data.Todo.findAllBySession parsedSession
|
||||
|> Request.Hasura.dataSource
|
||||
|> DataSource.map
|
||||
(\todos ->
|
||||
( session
|
||||
, Response.render
|
||||
{ entries =
|
||||
todos
|
||||
-- TODO add error handling for Nothing case
|
||||
|> Maybe.withDefault []
|
||||
|> List.map toOptimisticTodo
|
||||
, visibility = visibility
|
||||
, requestTime = requestTime
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
Nothing ->
|
||||
DataSource.succeed
|
||||
( session
|
||||
, Route.Visibility__ { visibility = Nothing }
|
||||
|> Route.redirectTo
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
action : RouteParams -> Request.Parser (DataSource (Response ActionData ErrorPage))
|
||||
action routeParams =
|
||||
MySession.withSession
|
||||
@ -275,48 +313,6 @@ visibilityFromRouteParams { visibility } =
|
||||
Nothing
|
||||
|
||||
|
||||
data : RouteParams -> Request.Parser (DataSource (Response Data ErrorPage))
|
||||
data routeParams =
|
||||
Request.requestTime
|
||||
|> MySession.expectSessionDataOrRedirect (Session.get "sessionId")
|
||||
(\parsedSession requestTime session ->
|
||||
case visibilityFromRouteParams routeParams of
|
||||
Just visibility ->
|
||||
Data.Todo.findAllBySession parsedSession
|
||||
|> Request.Hasura.dataSource
|
||||
|> DataSource.map
|
||||
(\todos ->
|
||||
( session
|
||||
, Response.render
|
||||
{ entries =
|
||||
todos
|
||||
-- TODO add error handling for Nothing case
|
||||
|> Maybe.withDefault []
|
||||
|> List.map toOptimisticTodo
|
||||
, visibility = visibility
|
||||
, requestTime = requestTime
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
Nothing ->
|
||||
DataSource.succeed
|
||||
( session
|
||||
, Route.Visibility__ { visibility = Nothing }
|
||||
|> Route.redirectTo
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
toOptimisticTodo : Data.Todo.Todo -> Entry
|
||||
toOptimisticTodo todo =
|
||||
{ description = todo.description
|
||||
, completed = todo.completed
|
||||
, id = todo.id
|
||||
, isSaving = False
|
||||
}
|
||||
|
||||
|
||||
view :
|
||||
Maybe PageUrl
|
||||
-> Shared.Model
|
||||
|
Loading…
Reference in New Issue
Block a user