This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parseToken : Parser (Maybe Token -> a) a | |
parseToken = | |
custom "ACCESS_TOKEN" <| | |
\segment -> | |
case String.split "&" segment |> List.map (String.split "=") of | |
[ [ "access_token", accessToken ] | |
, [ "expires_in", expires ] | |
, [ "token_type", type_ ] | |
, [ "state", state ] | |
, [ "id_token", idToken ] ] -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
OnLocationChange location -> | |
( { model | route = parseLocation location }, [] ) | |
|> andThen reroute | |
|> Tuple.mapSecond batch | |
UpdateRoute route -> | |
updateRoute route model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reroute : Model -> ( Model, List (Cmd msg) ) | |
reroute model = | |
case ( model.route, isSuccess model.user, isSuccess model.account) of | |
( SignUpRoute, False, True) -> | |
( { model | account = RemoteData.NotAsked }, [ Navigation.newUrl <| path LoginRoute ] ) | |
( LoginRoute, True, _) -> | |
( model, [ Navigation.modifyUrl <| path HomeRoute ] ) | |
( SignUpRoute, True, _) -> | |
( model, [ Navigation.modifyUrl <| path HomeRoute ] ) | |
( CreatePostRoute, False, _) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main : Program (Maybe Token) Model Msg | |
main = | |
Navigation.programWithFlags OnLocationChange | |
{ init = init | |
, view = Pages.view | |
, update = update | |
, subscriptions = \model -> Persistence.get OnLoadToken | |
} | |
init : Maybe Token -> Location -> ( Model, Cmd Msg ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
createPost : Model -> Html Msg | |
createPost model = | |
case model.user of | |
NotAsked -> | |
error "404 Not Found" | |
Loading -> | |
withLoader <| div [] [] | |
Success user -> | |
layout (userHeader user) (createPostBody model.form) | |
Failure err -> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
landing : Model -> Html Msg | |
landing model = | |
RemoteData.map userHeader model.user | |
|> RemoteData.withDefault authHeader | |
|> flip layout (landingBody model.posts) | |
readPost : String -> Model -> Html Msg | |
readPost id model = | |
case List.head <| List.filter (\post -> post.id == id) model.posts of | |
Just post -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.loading-wrapper { | |
position: fixed; | |
width: 100%; | |
height: 100%; | |
top: 0; | |
right: 0; | |
bottom: 0; | |
left: 0; | |
cursor: pointer; | |
z-index: 1000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
withLoader : Html msg -> Html msg | |
withLoader view = div [class "with-loader"] [view, loading] | |
loaderPart : String -> Html msg | |
loaderPart color = | |
div [ class ("spinner-layer spinner-" ++ color) ] | |
[ div [ class "circle-clipper left" ] | |
[ div [ class "circle" ] [] | |
] | |
, div [ class "gap-patch" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Api exposing (..) | |
import Decoders exposing (decodeToken, decodeUser) | |
import Encoders | |
import Http exposing (jsonBody) | |
import Json.Decode | |
import Messages exposing (Msg) | |
import Models exposing (Form, Token, User) | |
import RemoteData |