diff --git a/Modules/Website/src/Color.elm b/Modules/Website/src/Color.elm index 7cebf0c..3ea7467 100644 --- a/Modules/Website/src/Color.elm +++ b/Modules/Website/src/Color.elm @@ -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 diff --git a/Modules/Website/src/Main.elm b/Modules/Website/src/Main.elm index 18679d5..b7e3777 100644 --- a/Modules/Website/src/Main.elm +++ b/Modules/Website/src/Main.elm @@ -1,69 +1,65 @@ 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 +type Model = PageMain MainPage.Model -type Msg + +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) +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) -> + 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) -> - MainPage.view mainModell |> Element.map MsgMain - --- (_) -> --- el + <| + case model of + PageMain mainModell -> + MainPage.view mainModell |> Element.map MsgMain + + + +-- (_) -> +-- el -- [ Region.heading 1 -- , Font.size 36](text "Non") -main: Program () Model Msg +main : Program () Model Msg main = Browser.element - { init = \flags -> (initModel, Cmd.none) + { init = \_ -> ( initModel, Cmd.none ) , view = view , update = update , subscriptions = \_ -> Sub.none - } \ No newline at end of file + } diff --git a/Modules/Website/src/MainPage.elm b/Modules/Website/src/MainPage.elm index bbcc348..e16209d 100644 --- a/Modules/Website/src/MainPage.elm +++ b/Modules/Website/src/MainPage.elm @@ -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 + { url : String + , test : Bool + } + + +type alias Model = + { form : Form } -type alias Model - = { form: Form } initModel : Model -initModel - = { form = - { url = "" - } +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 - [ ("url", Encode.string form.url) - ] +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) -> - ( {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 , 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,14 +121,15 @@ 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 - , label = Input.labelAbove [ Font.size 14 ](text "Video Url") + , onChange = \new -> updateUrl model.form new |> UpdateForm + , label = Input.labelAbove [ Font.size 14 ] (text "Video Url") } , Input.button [ Background.color blue @@ -110,7 +138,14 @@ view model = , paddingXY 32 16 , Border.rounded 3 ] - { onPress = Just (PostForm model.form) + { 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 + } ]