From 7fadc22ce04a678579dc25b9079346a6a4079f45 Mon Sep 17 00:00:00 2001 From: Azizul Karim Date: Fri, 31 Jan 2025 00:51:11 +0600 Subject: [PATCH] port forwarding is working --- frontend/Makefile | 9 ++- frontend/src/Page/Landing.elm | 137 ++++++++++++++++++++-------------- 2 files changed, 90 insertions(+), 56 deletions(-) diff --git a/frontend/Makefile b/frontend/Makefile index 20a5341..753cc99 100644 --- a/frontend/Makefile +++ b/frontend/Makefile @@ -23,9 +23,14 @@ serve: ifeq ($(DEBUG),1) elm-go src/Main.elm \ --dir=../public \ - --start-page=index.html \ + --port=8000 \ + --start-page=../public/index.html \ --host=localhost \ - -- --debug + --proxy-prefix=/ \ + --proxy-host=http://localhost:8080 \ + -- \ + --debug \ + --output=../public/elm.min.js else ifeq ($(RELEASE),1) $(error Cannot use serve target with RELEASE=1) endif diff --git a/frontend/src/Page/Landing.elm b/frontend/src/Page/Landing.elm index e7cda21..e4b58c1 100644 --- a/frontend/src/Page/Landing.elm +++ b/frontend/src/Page/Landing.elm @@ -1,28 +1,30 @@ module Page.Landing exposing ( Model , Msg - , view , init - , update , subscriptions + , update + , view ) + import Element exposing (Element) -import Websockets -import Ports +import Element.Background +import Element.Input +import EncodeDecode +import Html.Attributes exposing (placeholder) import Json.Decode as Decode import Json.Encode as Encode exposing (Value) -import Html.Attributes exposing (placeholder) -import Element.Input -import Element.Background +import Ports +import Websockets -import EncodeDecode -type alias Model = { - time : String, - greetWidgetText : String, - greeting : String +type alias Model = + { time : String + , greetWidgetText : String + , greeting : String } + type Msg = DownMsg EncodeDecode.DownMsg | UpMsg EncodeDecode.LandingUpMsg @@ -30,15 +32,17 @@ type Msg | GreetWidgetText String | NoOp -init : () -> (Model, Cmd Msg) -init flags = ( - { time = "time not yet set" - , greetWidgetText = "" - , greeting = "" - }, - Cmd.none + +init : () -> ( Model, Cmd Msg ) +init flags = + ( { time = "time not yet set" + , greetWidgetText = "" + , greeting = "" + } + , Cmd.none ) + subscriptions : Model -> Sub Msg subscriptions model = Ports.socketOnEvent @@ -48,66 +52,91 @@ subscriptions model = (\_ -> NoOp) (\message -> case Decode.decodeString EncodeDecode.downMsgDecoder message.data of - Ok msg -> DownMsg msg - Err err -> DecodeError err + Ok msg -> + DownMsg msg + + Err err -> + DecodeError err ) (\_ -> NoOp) ) -update : Msg -> Model -> (Model, Cmd Msg) + +update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of DownMsg (EncodeDecode.LandingDownMsg (EncodeDecode.TimeUpdate time)) -> - ( {model | time = time}, Cmd.none ) - DownMsg (EncodeDecode.LandingDownMsg (EncodeDecode.Greeting greeting)) -> - ( {model | greeting = greeting}, Cmd.none) - UpMsg upMsg -> - let cmd = Ports.socketSend <| EncodeDecode.upMsgEncoder <| EncodeDecode.LandingUpMsg upMsg - in - (model, cmd) + ( { model | time = time }, Cmd.none ) + + DownMsg (EncodeDecode.LandingDownMsg (EncodeDecode.Greeting greeting)) -> + ( { model | greeting = greeting }, Cmd.none ) + + UpMsg upMsg -> + let + cmd = + Ports.socketSend <| EncodeDecode.upMsgEncoder <| EncodeDecode.LandingUpMsg upMsg + in + ( model, cmd ) + + GreetWidgetText text -> + ( { model | greetWidgetText = text }, Cmd.none ) + + _ -> + ( model, Cmd.none ) - GreetWidgetText text -> ( {model | greetWidgetText = text}, Cmd.none ) - _ -> (model, Cmd.none) greetWidget : Model -> Element Msg greetWidget model = let - idleBlue = Element.rgb255 18 147 217 - focusBlue = Element.rgb255 18 125 184 + idleBlue = + Element.rgb255 18 147 217 + + focusBlue = + Element.rgb255 18 125 184 + + myButton = + Element.Input.button + [ Element.Background.color idleBlue + , Element.mouseOver [ Element.Background.color focusBlue ] + , Element.width (Element.fill |> Element.maximum 100) + , Element.height (Element.fill |> Element.maximum 50) + ] + { onPress = Just <| UpMsg <| EncodeDecode.RequestGreet model.greetWidgetText + , label = Element.text "Greet" + } + + placeholder = + case model.greetWidgetText of + "" -> + Just <| Element.Input.placeholder [] <| Element.text "Type Your Name" + + _ -> + Just <| Element.Input.placeholder [] <| Element.text "" - myButton = Element.Input.button - [ Element.Background.color idleBlue - , Element.mouseOver [Element.Background.color focusBlue] - , Element.width (Element.fill |> Element.maximum 100) - , Element.height (Element.fill |> Element.maximum 50) - ] - { onPress = Just <| UpMsg <| EncodeDecode.RequestGreet model.greetWidgetText - , label = Element.text "Greet" - } - placeholder = case model.greetWidgetText of - "" -> Just <| Element.Input.placeholder [] <| Element.text "Type Your Name" - _ -> Just <| Element.Input.placeholder [] <| Element.text "" textInput = Element.Input.text - [ Element.width (Element.fill |> Element.maximum 400) - , Element.height Element.fill - ] + [ Element.width (Element.fill |> Element.maximum 400) + , Element.height Element.fill + ] { onChange = GreetWidgetText , text = model.greetWidgetText , placeholder = placeholder , label = Element.Input.labelHidden "Enter your name" } - nameInput = Element.row [] [ textInput , myButton] + + nameInput = + Element.row [] [ textInput, myButton ] in - Element.column [] - [ nameInput - , Element.text model.greeting - ] + Element.column [] + [ nameInput + , Element.text model.greeting + ] + view : Model -> Element Msg view model = Element.column [] - [ Element.text "Landing" + [ Element.text "Landing..." , Element.text <| "Current time is : " ++ model.time , greetWidget model ]