yagcdn/frontend/src/Main.elm

111 lines
2.5 KiB
Elm
Raw Normal View History

2019-07-27 16:24:13 +02:00
module Main exposing (Model, Msg(..), init, main, update, view)
import Browser
2019-07-29 21:16:33 +02:00
import Data exposing (Url, hostname, repository, servicename, toUrl)
import Html exposing (Html, a, article, div, h1, input, li, nav, small, text, ul)
import Html.Attributes exposing (disabled, href, placeholder, style, value)
2019-07-27 16:24:13 +02:00
import Html.Events exposing (onInput)
import Parse exposing (parseUrl)
2019-07-27 20:07:22 +02:00
import Ribbon exposing (ribbon)
2019-07-27 16:24:13 +02:00
type Msg
= UrlChange String
type alias Model =
{ url : String
, parsed : Maybe Url
}
init : Model
init =
{ url = ""
, parsed = Nothing
}
update : Msg -> Model -> Model
update msg state =
case msg of
UrlChange newUrl ->
{ state | url = newUrl, parsed = parseUrl newUrl }
displayMUrl : Maybe Url -> String
displayMUrl mUrl =
mUrl
|> Maybe.map toUrl
2019-07-28 21:42:49 +02:00
|> Maybe.withDefault (hostname ++ "<service>/<user>/<repo>/<gitref>/<file>")
2019-07-27 16:24:13 +02:00
myStyle : List (Html.Attribute msg)
myStyle =
[ style "width" "100%" ]
myStyle2 : List (Html.Attribute msg) -> List (Html.Attribute msg)
myStyle2 =
List.append myStyle
view : Model -> Html Msg
view state =
2019-07-28 21:42:49 +02:00
div myStyle
2019-07-29 21:16:33 +02:00
[ header
, body state
, footer
]
header : Html msg
header =
Html.header []
[ h1 myStyle [ text servicename ]
, ribbon repository
]
footer : Html msg
footer =
Html.footer myStyle
[ nav []
[ ul []
[ li []
[ small []
[ text "Created by "
, a [ href "https://www.vbrandl.net/" ] [ text "Valentin Brandl" ]
, text "."
]
]
]
]
2019-07-29 22:12:54 +02:00
, nav []
[ ul []
[ li []
[ small []
[ a [ href repository ] [ text "Repository" ] ]
]
, li []
[ small []
[ a [ href "https://opensource.org/licenses/MIT" ] [ text "MIT License" ] ]
]
]
]
2019-07-29 21:16:33 +02:00
]
body : Model -> Html Msg
body state =
article myStyle
[ input (myStyle2 [ placeholder "GitHub/GitLab/Bitbucket URL", value state.url, onInput UrlChange ])
2019-07-28 21:42:49 +02:00
[]
, input (myStyle2 [ disabled True, value (displayMUrl state.parsed) ]) []
2019-07-27 16:24:13 +02:00
]
main : Program () Model Msg
main =
Browser.sandbox { init = init, update = update, view = view }