elm-format
This commit is contained in:
@@ -1,21 +1,28 @@
|
||||
module Color exposing (..)
|
||||
|
||||
import Element exposing (rgb, rgba)
|
||||
import Element
|
||||
|
||||
|
||||
white : Element.Color
|
||||
white =
|
||||
Element.rgb 1 1 1
|
||||
|
||||
|
||||
grey : Element.Color
|
||||
grey =
|
||||
Element.rgb 0.9 0.9 0.9
|
||||
|
||||
|
||||
blue : Element.Color
|
||||
blue =
|
||||
Element.rgb 0 0 0.8
|
||||
|
||||
|
||||
red : Element.Color
|
||||
red =
|
||||
Element.rgb 0.8 0 0
|
||||
|
||||
|
||||
darkBlue : Element.Color
|
||||
darkBlue =
|
||||
Element.rgb 0 0 0.9
|
||||
|
||||
@@ -1,58 +1,54 @@
|
||||
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)
|
||||
import Html exposing (Html)
|
||||
import MainPage
|
||||
|
||||
|
||||
|
||||
|
||||
type Model
|
||||
= PageMain MainPage.Model
|
||||
|
||||
|
||||
type Msg
|
||||
= MsgMain MainPage.Msg
|
||||
|
||||
|
||||
initModel : Model
|
||||
initModel =
|
||||
PageMain MainPage.initModel
|
||||
|
||||
|
||||
combineModel : ( MainPage.Model, Cmd MainPage.Msg ) -> ( Model, Cmd Msg )
|
||||
combineModel ( mainPageModell, cmd ) =
|
||||
( PageMain mainPageModell, Cmd.map MsgMain cmd )
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case ( msg, model ) of
|
||||
( MsgMain l_msg, PageMain l_model ) ->
|
||||
combineModel (MainPage.update l_msg l_model)
|
||||
|
||||
|
||||
|
||||
-- ( _, _ ) ->
|
||||
-- Debug.todo "branch '( Decrement, _ )' not implemented"
|
||||
|
||||
|
||||
view : Model -> Html Msg
|
||||
view model =
|
||||
Element.layout
|
||||
[
|
||||
Font.size 20
|
||||
[ Font.size 20
|
||||
]
|
||||
<| case (model) of
|
||||
(PageMain mainModell) ->
|
||||
<|
|
||||
case model of
|
||||
PageMain mainModell ->
|
||||
MainPage.view mainModell |> Element.map MsgMain
|
||||
|
||||
|
||||
|
||||
-- (_) ->
|
||||
-- el
|
||||
-- [ Region.heading 1
|
||||
@@ -62,7 +58,7 @@ view model =
|
||||
main : Program () Model Msg
|
||||
main =
|
||||
Browser.element
|
||||
{ init = \flags -> (initModel, Cmd.none)
|
||||
{ init = \_ -> ( initModel, Cmd.none )
|
||||
, view = view
|
||||
, update = update
|
||||
, subscriptions = \_ -> Sub.none
|
||||
|
||||
@@ -1,44 +1,52 @@
|
||||
module MainPage exposing (..)
|
||||
|
||||
import Http
|
||||
import Json.Decode exposing (Decoder, bool, int, list, string, succeed)
|
||||
import Json.Decode.Pipeline exposing(optional, required)
|
||||
import Json.Encode as Encode
|
||||
|
||||
module MainPage exposing (Model, Msg, initModel, update, view)
|
||||
|
||||
import Color exposing (..)
|
||||
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)
|
||||
import Http
|
||||
import Json.Decode exposing (Decoder, int, string, succeed)
|
||||
import Json.Decode.Pipeline exposing (required)
|
||||
import Json.Encode as Encode
|
||||
|
||||
import Color exposing (..)
|
||||
|
||||
type alias Form =
|
||||
{ url : String
|
||||
, test : Bool
|
||||
}
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ form : Form
|
||||
}
|
||||
|
||||
type alias Model
|
||||
= { form: Form }
|
||||
|
||||
initModel : Model
|
||||
initModel
|
||||
= { form =
|
||||
initModel =
|
||||
{ form =
|
||||
{ url = ""
|
||||
, test = True
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
type Msg
|
||||
= UpdateForm Form
|
||||
| PostForm Form
|
||||
| PostResult (Result Http.Error PostFormResponse)
|
||||
| None
|
||||
|
||||
|
||||
|
||||
-- -- Request -- --
|
||||
|
||||
type alias PostFormResponse = { id: Int, status: String }
|
||||
|
||||
type alias PostFormResponse =
|
||||
{ id : Int, status : String }
|
||||
|
||||
|
||||
formDecoder : Decoder PostFormResponse
|
||||
formDecoder =
|
||||
@@ -46,19 +54,25 @@ formDecoder =
|
||||
|> required "id" int
|
||||
|> required "status" string
|
||||
|
||||
|
||||
formPostEncoder : Form -> Encode.Value
|
||||
formPostEncoder form = Encode.object
|
||||
formPostEncoder form =
|
||||
Encode.object
|
||||
[ ( "url", Encode.string form.url )
|
||||
]
|
||||
|
||||
|
||||
|
||||
-- -- Update -- --
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case (msg) of
|
||||
(UpdateForm new_form) ->
|
||||
case msg of
|
||||
UpdateForm new_form ->
|
||||
( { model | form = new_form }, Cmd.none )
|
||||
|
||||
(PostForm form) ->
|
||||
PostForm form ->
|
||||
( model
|
||||
, Http.post
|
||||
{ url = "http://127.0.0.1/api/add"
|
||||
@@ -67,10 +81,23 @@ update msg model =
|
||||
}
|
||||
)
|
||||
|
||||
(_) -> ( model, Cmd.none )
|
||||
_ ->
|
||||
( model, Cmd.none )
|
||||
|
||||
|
||||
|
||||
-- -- Update -- --
|
||||
|
||||
|
||||
updateUrl : Form -> String -> Form
|
||||
updateUrl form new_url =
|
||||
{ form | url = new_url }
|
||||
|
||||
|
||||
|
||||
-- -- view -- --
|
||||
|
||||
|
||||
view : Model -> Element Msg
|
||||
view model =
|
||||
Element.column
|
||||
@@ -94,13 +121,14 @@ view model =
|
||||
[ Font.color red
|
||||
, Font.size 14
|
||||
, alignRight
|
||||
, moveDown 6]
|
||||
, moveDown 6
|
||||
]
|
||||
(text "This one is wrong")
|
||||
)
|
||||
]
|
||||
{ text = model.form.url
|
||||
, placeholder = Just (Input.placeholder [] (text "http://youtube.com"))
|
||||
, onChange = \new -> UpdateForm { model | form = { url = new } }.form
|
||||
, onChange = \new -> updateUrl model.form new |> UpdateForm
|
||||
, label = Input.labelAbove [ Font.size 14 ] (text "Video Url")
|
||||
}
|
||||
, Input.button
|
||||
@@ -113,4 +141,11 @@ view model =
|
||||
{ onPress = Just (PostForm model.form)
|
||||
, label = Element.text "Download"
|
||||
}
|
||||
, Input.checkbox
|
||||
[]
|
||||
{ checked = model.form.test
|
||||
, icon = Input.defaultCheckbox
|
||||
, label = Input.labelRight [] (text "Test")
|
||||
, onChange = \_ -> None
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user