elm-format

This commit is contained in:
Simon Hardt
2021-05-28 22:15:56 +02:00
parent 91776d9591
commit cb63d33c56
3 changed files with 103 additions and 65 deletions

View File

@@ -1,21 +1,28 @@
module Color exposing (..) module Color exposing (..)
import Element exposing (rgb, rgba) import Element
white : Element.Color
white = white =
Element.rgb 1 1 1 Element.rgb 1 1 1
grey : Element.Color
grey = grey =
Element.rgb 0.9 0.9 0.9 Element.rgb 0.9 0.9 0.9
blue : Element.Color
blue = blue =
Element.rgb 0 0 0.8 Element.rgb 0 0 0.8
red : Element.Color
red = red =
Element.rgb 0.8 0 0 Element.rgb 0.8 0 0
darkBlue : Element.Color
darkBlue = darkBlue =
Element.rgb 0 0 0.9 Element.rgb 0 0 0.9

View File

@@ -1,69 +1,65 @@
module Main exposing (main) module Main exposing (main)
import Browser 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 exposing (..)
import Element.Background as Background
import Element.Border as Border
import Element.Font as Font import Element.Font as Font
import Element.Input as Input import Html exposing (Html)
import Element.Region as Region
import Html exposing (header)
import MainPage import MainPage
type Model
type Model
= PageMain MainPage.Model = PageMain MainPage.Model
type Msg
type Msg
= MsgMain MainPage.Msg = MsgMain MainPage.Msg
initModel : Model initModel : Model
initModel = initModel =
PageMain MainPage.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) 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 = update msg model =
case (msg, model) of case ( msg, model ) of
(MsgMain l_msg, PageMain l_model) -> ( MsgMain l_msg, PageMain l_model ) ->
combineModel (MainPage.update l_msg l_model) combineModel (MainPage.update l_msg l_model)
-- ( _, _ ) -> -- ( _, _ ) ->
-- Debug.todo "branch '( Decrement, _ )' not implemented" -- Debug.todo "branch '( Decrement, _ )' not implemented"
view : Model -> Html Msg view : Model -> Html Msg
view model = view model =
Element.layout Element.layout
[ [ Font.size 20
Font.size 20
] ]
<| case (model) of <|
(PageMain mainModell) -> case model of
MainPage.view mainModell |> Element.map MsgMain PageMain mainModell ->
MainPage.view mainModell |> Element.map MsgMain
-- (_) ->
-- el
-- (_) ->
-- el
-- [ Region.heading 1 -- [ Region.heading 1
-- , Font.size 36](text "Non") -- , Font.size 36](text "Non")
main: Program () Model Msg main : Program () Model Msg
main = main =
Browser.element Browser.element
{ init = \flags -> (initModel, Cmd.none) { init = \_ -> ( initModel, Cmd.none )
, view = view , view = view
, update = update , update = update
, subscriptions = \_ -> Sub.none , subscriptions = \_ -> Sub.none
} }

View File

@@ -1,44 +1,52 @@
module MainPage exposing (..) module MainPage exposing (Model, Msg, initModel, update, view)
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 Color exposing (..)
import Element exposing (..) import Element exposing (..)
import Element.Background as Background import Element.Background as Background
import Element.Border as Border import Element.Border as Border
import Element.Font as Font import Element.Font as Font
import Element.Input as Input import Element.Input as Input
import Element.Region as Region 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 = type alias Form =
{ url: String { url : String
, test : Bool
}
type alias Model =
{ form : Form
} }
type alias Model
= { form: Form }
initModel : Model initModel : Model
initModel initModel =
= { form = { form =
{ url = "" { url = ""
} , test = True
}
} }
type Msg type Msg
= UpdateForm Form = UpdateForm Form
| PostForm Form | PostForm Form
| PostResult (Result Http.Error PostFormResponse) | PostResult (Result Http.Error PostFormResponse)
| None
-- -- Request -- -- -- -- Request -- --
type alias PostFormResponse = { id: Int, status: String }
type alias PostFormResponse =
{ id : Int, status : String }
formDecoder : Decoder PostFormResponse formDecoder : Decoder PostFormResponse
formDecoder = formDecoder =
@@ -46,19 +54,25 @@ formDecoder =
|> required "id" int |> required "id" int
|> required "status" string |> required "status" string
formPostEncoder : Form -> Encode.Value formPostEncoder : Form -> Encode.Value
formPostEncoder form = Encode.object formPostEncoder form =
[ ("url", Encode.string form.url) Encode.object
] [ ( "url", Encode.string form.url )
]
-- -- Update -- -- -- -- Update -- --
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case (msg) of
(UpdateForm new_form) ->
( {model | form = new_form } , Cmd.none)
(PostForm form) ->
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
UpdateForm new_form ->
( { model | form = new_form }, Cmd.none )
PostForm form ->
( model ( model
, Http.post , Http.post
{ url = "http://127.0.0.1/api/add" { 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 -- --
view : Model -> Element Msg view : Model -> Element Msg
view model = view model =
Element.column Element.column
@@ -94,14 +121,15 @@ view model =
[ Font.color red [ Font.color red
, Font.size 14 , Font.size 14
, alignRight , alignRight
, moveDown 6] , moveDown 6
]
(text "This one is wrong") (text "This one is wrong")
) )
] ]
{ text = model.form.url { text = model.form.url
, placeholder = Just (Input.placeholder [] (text "http://youtube.com")) , 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") , label = Input.labelAbove [ Font.size 14 ] (text "Video Url")
} }
, Input.button , Input.button
[ Background.color blue [ Background.color blue
@@ -110,7 +138,14 @@ view model =
, paddingXY 32 16 , paddingXY 32 16
, Border.rounded 3 , Border.rounded 3
] ]
{ onPress = Just (PostForm model.form) { onPress = Just (PostForm model.form)
, label = Element.text "Download" , label = Element.text "Download"
} }
, Input.checkbox
[]
{ checked = model.form.test
, icon = Input.defaultCheckbox
, label = Input.labelRight [] (text "Test")
, onChange = \_ -> None
}
] ]