Skip to content
This repository has been archived by the owner on Oct 28, 2019. It is now read-only.

Commit

Permalink
Update main
Browse files Browse the repository at this point in the history
  • Loading branch information
rl-king committed Jul 3, 2018
1 parent ad1454e commit 7c136d3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions elm-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
],
"exposed-modules": [],
"dependencies": {
"NoRedInk/elm-decode-pipeline": "3.0.0 <= v < 4.0.0",
"elm-lang/core": "5.0.0 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"elm-lang/http": "1.0.0 <= v < 2.0.0",
"elm-lang/navigation": "2.1.0 <= v < 3.0.0",
"evancz/url-parser": "2.0.1 <= v < 3.0.0"
},
Expand Down
29 changes: 26 additions & 3 deletions src/Main.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module Main exposing (main)

import Ginger.Media as Media
import Ginger.Resource exposing (Resource)
import Ginger.Rest
import Html exposing (..)
import Html.Attributes exposing (..)
import Http
import Navigation
import Route exposing (Route)

Expand All @@ -25,6 +30,7 @@ main =
type alias Model =
{ route : Route
, page : Page
, data : Maybe Resource
}


Expand All @@ -40,6 +46,7 @@ init location =
updatePage
{ route = Route.fromLocation location
, page = Loading
, data = Nothing
}


Expand All @@ -50,6 +57,7 @@ init location =
type Msg
= OnNavigation Navigation.Location
| PushUrl Route
| GotResource (Result Http.Error Resource)


update : Msg -> Model -> ( Model, Cmd Msg )
Expand All @@ -61,6 +69,13 @@ update msg model =
PushUrl route ->
( model, Navigation.newUrl (Route.toUrl route) )

GotResource result ->
let
_ =
Debug.log "data" result
in
( { model | data = Result.toMaybe result }, Cmd.none )


updatePage : Model -> ( Model, Cmd Msg )
updatePage model =
Expand All @@ -76,14 +91,22 @@ updatePage model =
Route.NotFound ->
( Unknown, Cmd.none )
in
( { model | page = page }, cmds )
( { model | page = page }
, Http.send GotResource <|
Ginger.Rest.requestResourceByPath "/"
)



-- VIEW


view : Model -> Html Msg
view _ =
view model =
let
imageUrl =
Maybe.andThen (Media.depiction Media.Small) model.data
|> Maybe.withDefault "fallbackurl"
in
main_ []
[ Route.link PushUrl Route.Root [] [ h1 [] [ text "Hello" ] ] ]
[ h1 [] [ text "hello world" ], img [ src imageUrl ] [] ]

0 comments on commit 7c136d3

Please sign in to comment.