Add a step to verify everything is set up properly.

This commit is contained in:
Richard Feldman
2016-04-02 08:37:13 -07:00
parent c5c51cdcfe
commit 597a87e70d
6 changed files with 278 additions and 0 deletions

131
Main.elm Normal file
View File

@@ -0,0 +1,131 @@
module Main (..) where
{-| THIS FILE IS NOT PART OF THE WORKSHOP! It is only to verify that you
have everything set up properly.
-}
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Auth
import StartApp
import Http
import Task exposing (Task)
import Effects exposing (Effects)
import Json.Decode exposing (Decoder, (:=))
import Json.Encode
import Signal exposing (Address)
main : Signal Html
main =
app.html
app : StartApp.App Model
app =
StartApp.start
{ view = view
, update = update
, init = ( initialModel, Effects.task searchFeed )
, inputs = []
}
initialModel : Model
initialModel =
{ status = "Verifying setup..."
}
type alias Model =
{ status : String }
port tasks : Signal (Task Effects.Never ())
port tasks =
app.tasks
searchFeed : Task x Action
searchFeed =
let
url =
"https://api.github.com/search/repositories?q=test&access_token="
++ Auth.token
in
performAction
(\_ -> ItWorked)
(\err -> ItFailed err)
(Http.get (Json.Decode.succeed "") url)
performAction : (a -> b) -> (y -> b) -> Task y a -> Task x b
performAction successToAction errorToAction task =
let
successTask =
Task.map successToAction task
in
Task.onError successTask (\err -> Task.succeed (errorToAction err))
view : Address Action -> Model -> Html
view address model =
div
[ class "content" ]
[ header [] [ h1 [] [ text "Elm Workshop" ] ]
, div
[ style
[ ( "font-size", "48px" )
, ( "text-align", "center" )
, ( "padding", "48px" )
]
]
[ text model.status ]
]
onInput address wrap =
on "input" targetValue (\val -> Signal.message address (wrap val))
defaultValue str =
property "defaultValue" (Json.Encode.string str)
type Action
= ItWorked
| ItFailed Http.Error
update : Action -> Model -> ( Model, Effects Action )
update action model =
case action of
ItWorked ->
( { status = "You're all set!" }, Effects.none )
ItFailed err ->
let
status =
case err of
Http.Timeout ->
"Timed out trying to contact GitHub. Check your Internet connection?"
Http.NetworkError ->
"Network error. Check your Internet connection?"
Http.UnexpectedPayload msg ->
"Something is misconfigured: " ++ msg
Http.BadResponse code msg ->
case code of
401 ->
"Auth.elm does not have a valid token. :( Try recreating Auth.elm by following the steps in the README under the section Create a GitHub Personal Access Token."
_ ->
"GitHub's Search API returned an error: "
++ (toString code)
++ " "
++ msg
in
( { status = status }, Effects.none )

View File

@@ -49,6 +49,17 @@ token =
still important! `Auth.elm` is in `.gitignore` to avoid accidentally checking in still important! `Auth.elm` is in `.gitignore` to avoid accidentally checking in
an API secret, and you should [delete this token](https://github.com/settings/tokens) when the workshop is over. an API secret, and you should [delete this token](https://github.com/settings/tokens) when the workshop is over.
## Verify Setup
```bash
elm package install
```
```bash
elm live Main.elm --open --output=elm.js
```
## Start with Part 1 ## Start with Part 1
Run this at the terminal: Run this at the terminal:

BIN
elm-hub.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

18
elm-package.json Normal file
View File

@@ -0,0 +1,18 @@
{
"version": "1.0.0",
"summary": "Like GitHub, but for Elm stuff.",
"repository": "https://github.com/rtfeldman/elm-workshop.git",
"license": "BSD-3-Clause",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "3.0.0 <= v < 4.0.0",
"evancz/elm-effects": "2.0.0 <= v < 3.0.0",
"evancz/elm-html": "4.0.0 <= v < 5.0.0",
"evancz/elm-http": "3.0.0 <= v < 4.0.0",
"evancz/start-app": "2.0.0 <= v < 3.0.0"
},
"elm-version": "0.16.0 <= v < 0.17.0"
}

26
index.html Normal file
View File

@@ -0,0 +1,26 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Elm Workshop</title>
<script type="text/javascript" src="elm.js"></script>
<!-- Uncomment the below line to enable elm-reactor support. -->
<!-- <script type="text/javascript" src="/_reactor/debug.js"></script> -->
<link rel="stylesheet" href="style.css">
<link rel="icon" type="image/png" href="elm-hub.png">
</head>
<body>
</body>
<script type="text/javascript">
var app = Elm.fullscreen(Elm.Main, {});
// Uncomment this line and comment out the above to enable elm-reactor support.
// var app = Elm.fullscreenDebug("ElmHub", "ElmHub.elm");
</script>
</html>

92
style.css Normal file
View File

@@ -0,0 +1,92 @@
.content {
width: 960px;
margin: 0 auto;
padding: 30px;
font-family: Helvetica, Arial, serif;
}
header {
position: relative;
padding: 6px 12px;
height: 36px;
background-color: rgb(96, 181, 204);
}
h1 {
color: white;
font-weight: normal;
margin: 0;
}
.tagline {
color: #eee;
position: absolute;
right: 16px;
top: 12px;
font-size: 24px;
font-style: italic;
}
.results {
list-style-image: url('http://img-cache.cdn.gaiaonline.com/76bd5c99d8f2236e9d3672510e933fdf/http://i278.photobucket.com/albums/kk81/d3m3nt3dpr3p/Tiny-Star-Icon.png');
list-style-position: inside;
padding: 0;
}
.results li {
font-size: 18px;
margin-bottom: 16px;
}
.star-count {
font-weight: bold;
margin-right: 16px;
}
a {
color: rgb(96, 181, 204);
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.search-query {
padding: 8px;
font-size: 24px;
margin-bottom: 18px;
margin-top: 36px;
}
.search-button {
padding: 8px 16px;
font-size: 24px;
color: white;
border: 1px solid #ccc;
background-color: rgb(96, 181, 204);
margin-left: 12px
}
.search-button:hover {
color: rgb(96, 181, 204);
background-color: white;
}
.hide-result {
background-color: transparent;
border: 0;
font-weight: bold;
font-size: 18px;
margin-left: 18px;
cursor: pointer;
}
.hide-result:hover {
color: rgb(96, 181, 204);
}
button:focus, input:focus {
outline: none;
}