mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-26 05:13:24 +03:00
Extract helper function.
This commit is contained in:
parent
564e410817
commit
2d912ffcb3
@ -152,42 +152,11 @@ action routeParams =
|
|||||||
in
|
in
|
||||||
case formResult of
|
case formResult of
|
||||||
Ok (Add newItemDescription) ->
|
Ok (Add newItemDescription) ->
|
||||||
okSessionThing
|
withUserSession session
|
||||||
|> Session.get "sessionId"
|
(\userId ->
|
||||||
|> Maybe.map Data.Session.get
|
|
||||||
|> Maybe.map Request.Hasura.dataSource
|
|
||||||
|> Maybe.map
|
|
||||||
(DataSource.andThen
|
|
||||||
(\maybeUserSession ->
|
|
||||||
let
|
|
||||||
bar : Maybe Uuid
|
|
||||||
bar =
|
|
||||||
maybeUserSession
|
|
||||||
|> Maybe.map .id
|
|
||||||
in
|
|
||||||
case bar of
|
|
||||||
Nothing ->
|
|
||||||
DataSource.succeed
|
|
||||||
( okSessionThing
|
|
||||||
, Response.render {}
|
|
||||||
)
|
|
||||||
|
|
||||||
Just userId ->
|
|
||||||
Data.Todo.create userId newItemDescription
|
Data.Todo.create userId newItemDescription
|
||||||
|> Request.Hasura.mutationDataSource
|
|> Request.Hasura.mutationDataSource
|
||||||
|> DataSource.map
|
|> DataSource.map (\_ -> Response.render {})
|
||||||
(\newItemId ->
|
|
||||||
( okSessionThing
|
|
||||||
, Response.render {}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|> Maybe.withDefault
|
|
||||||
(DataSource.succeed
|
|
||||||
( okSessionThing
|
|
||||||
, Response.render {}
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
Ok (CheckAll toggleTo) ->
|
Ok (CheckAll toggleTo) ->
|
||||||
@ -404,6 +373,51 @@ action routeParams =
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
withUserSession :
|
||||||
|
Result x (Maybe Session)
|
||||||
|
-> (Uuid -> DataSource (Response ActionData ErrorPage))
|
||||||
|
-> DataSource ( Session, Response ActionData ErrorPage )
|
||||||
|
withUserSession cookieSession continue =
|
||||||
|
let
|
||||||
|
okSessionThing : Session
|
||||||
|
okSessionThing =
|
||||||
|
cookieSession
|
||||||
|
|> Result.withDefault Nothing
|
||||||
|
|> Maybe.withDefault Session.empty
|
||||||
|
in
|
||||||
|
okSessionThing
|
||||||
|
|> Session.get "sessionId"
|
||||||
|
|> Maybe.map Data.Session.get
|
||||||
|
|> Maybe.map Request.Hasura.dataSource
|
||||||
|
|> Maybe.map
|
||||||
|
(DataSource.andThen
|
||||||
|
(\maybeUserSession ->
|
||||||
|
let
|
||||||
|
maybeUserId : Maybe Uuid
|
||||||
|
maybeUserId =
|
||||||
|
maybeUserSession
|
||||||
|
|> Maybe.map .id
|
||||||
|
in
|
||||||
|
case maybeUserId of
|
||||||
|
Nothing ->
|
||||||
|
DataSource.succeed
|
||||||
|
( okSessionThing
|
||||||
|
, Response.render {}
|
||||||
|
)
|
||||||
|
|
||||||
|
Just userId ->
|
||||||
|
continue userId
|
||||||
|
|> DataSource.map (Tuple.pair okSessionThing)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|> Maybe.withDefault
|
||||||
|
(DataSource.succeed
|
||||||
|
( okSessionThing
|
||||||
|
, Response.render {}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user