Init
This commit is contained in:
29
Modules/Website/elm.json
Normal file
29
Modules/Website/elm.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"src"
|
||||
],
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"NoRedInk/elm-json-decode-pipeline": "1.0.0",
|
||||
"elm/browser": "1.0.2",
|
||||
"elm/core": "1.0.5",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/http": "2.0.0",
|
||||
"elm/json": "1.1.3",
|
||||
"mdgriffith/elm-ui": "1.1.8"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/bytes": "1.0.8",
|
||||
"elm/file": "1.0.5",
|
||||
"elm/time": "1.0.0",
|
||||
"elm/url": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.2"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
||||
19
Modules/Website/src/Color.elm
Normal file
19
Modules/Website/src/Color.elm
Normal file
@@ -0,0 +1,19 @@
|
||||
module Color exposing (..)
|
||||
|
||||
white =
|
||||
Element.rgb 1 1 1
|
||||
|
||||
grey =
|
||||
Element.rgb 0.9 0.9 0.9
|
||||
|
||||
|
||||
blue =
|
||||
Element.rgb 0 0 0.8
|
||||
|
||||
|
||||
red =
|
||||
Element.rgb 0.8 0 0
|
||||
|
||||
|
||||
darkBlue =
|
||||
Element.rgb 0 0 0.9
|
||||
157
Modules/Website/src/Main.elm
Normal file
157
Modules/Website/src/Main.elm
Normal file
@@ -0,0 +1,157 @@
|
||||
module Main exposing (main)
|
||||
|
||||
import Browser
|
||||
import Html exposing (Html)
|
||||
|
||||
import Http
|
||||
import Json.Decode exposing (Decoder, bool, int, list, string, succeed)
|
||||
import Json.Decode.Pipeline exposing(optional, required)
|
||||
import Json.Encode as Encode
|
||||
|
||||
import Element exposing (..)
|
||||
import Element.Background as Background
|
||||
import Element.Border as Border
|
||||
import Element.Font as Font
|
||||
import Element.Input as Input
|
||||
import Element.Region as Region
|
||||
import Html exposing (header)
|
||||
|
||||
white =
|
||||
Element.rgb 1 1 1
|
||||
|
||||
grey =
|
||||
Element.rgb 0.9 0.9 0.9
|
||||
|
||||
|
||||
blue =
|
||||
Element.rgb 0 0 0.8
|
||||
|
||||
|
||||
red =
|
||||
Element.rgb 0.8 0 0
|
||||
|
||||
|
||||
darkBlue =
|
||||
Element.rgb 0 0 0.9
|
||||
|
||||
type alias Form =
|
||||
{ url: String
|
||||
}
|
||||
|
||||
type Model
|
||||
= AddPage Form
|
||||
| Quere
|
||||
|
||||
type Msg
|
||||
= UpdateForm Form
|
||||
| AddUrl Form
|
||||
| UrlAdded (Result Http.Error UrlAddedResponse)
|
||||
|
||||
initModel : Model
|
||||
initModel =
|
||||
AddPage
|
||||
{ url = ""
|
||||
}
|
||||
|
||||
type alias UrlAddedResponse = { id: Int, status: String }
|
||||
urlAddDecoder : Decoder UrlAddedResponse
|
||||
urlAddDecoder =
|
||||
succeed UrlAddedResponse
|
||||
|> required "id" int
|
||||
|> required "status" string
|
||||
|
||||
urlAddEncode : Form -> Encode.Value
|
||||
urlAddEncode form = Encode.object
|
||||
[ ("url", Encode.string form.url)
|
||||
]
|
||||
|
||||
-- Http.header "Access-Control-Request-Method" "POST"
|
||||
-- ,
|
||||
update : Msg -> Model -> (Model, Cmd Msg)
|
||||
update msg model =
|
||||
case (msg, model) of
|
||||
(UpdateForm new_form, AddPage _) ->
|
||||
(AddPage new_form, Cmd.none)
|
||||
|
||||
(AddUrl form, AddPage _) ->
|
||||
( model
|
||||
, Http.request
|
||||
{ method = "POST"
|
||||
, headers =
|
||||
[
|
||||
]
|
||||
, url = "http://127.0.0.1/api/add"
|
||||
, body = Http.jsonBody (urlAddEncode form)
|
||||
, expect = Http.expectJson UrlAdded (urlAddDecoder)
|
||||
, timeout = Nothing
|
||||
, tracker = Nothing
|
||||
}
|
||||
)
|
||||
|
||||
( _, _ ) ->
|
||||
Debug.todo "branch '( Decrement, _ )' not implemented"
|
||||
|
||||
view : Model -> Html Msg
|
||||
view model =
|
||||
Element.layout
|
||||
[
|
||||
Font.size 20
|
||||
]
|
||||
<| case (model) of
|
||||
(AddPage form) ->
|
||||
Element.column
|
||||
[ width (px 800)
|
||||
, height shrink
|
||||
, centerX
|
||||
, centerY
|
||||
, spacing 36
|
||||
, padding 10
|
||||
]
|
||||
[ el
|
||||
[ Region.heading 1
|
||||
, alignLeft
|
||||
, Font.size 36
|
||||
]
|
||||
(text "localTube")
|
||||
, Input.text
|
||||
[ spacing 12
|
||||
, below
|
||||
(el
|
||||
[ Font.color red
|
||||
, Font.size 14
|
||||
, alignRight
|
||||
, moveDown 6]
|
||||
(text "This one is wrong")
|
||||
)
|
||||
]
|
||||
{ text = form.url
|
||||
, placeholder = Just (Input.placeholder [] (text "http://youtube.com"))
|
||||
, onChange = \new -> UpdateForm { form | url = new }
|
||||
, label = Input.labelAbove [ Font.size 14 ](text "Video Url")
|
||||
}
|
||||
, Input.button
|
||||
[ Background.color blue
|
||||
, Font.color white
|
||||
, Border.color darkBlue
|
||||
, paddingXY 32 16
|
||||
, Border.rounded 3
|
||||
]
|
||||
{ onPress = Just (AddUrl form)
|
||||
, label = Element.text "Add Link to Query"
|
||||
}
|
||||
]
|
||||
|
||||
(_) ->
|
||||
el
|
||||
[ Region.heading 1
|
||||
, Font.size 36](text "Non")
|
||||
|
||||
|
||||
main: Program () Model Msg
|
||||
main =
|
||||
Browser.element
|
||||
{ init = \flags -> (initModel, Cmd.none)
|
||||
, view = view
|
||||
, update = update
|
||||
, subscriptions = \_ -> Sub.none
|
||||
}
|
||||
Reference in New Issue
Block a user