yagcdn/frontend/src/Main.elm

155 lines
3.2 KiB
Elm
Raw Normal View History

2019-07-29 23:17:41 +02:00
module Main exposing
( Model
, Msg(..)
, init
, main
, update
, view
)
2019-07-27 16:24:13 +02:00
import Browser
2019-07-29 21:16:33 +02:00
import Data exposing (Url, hostname, repository, servicename, toUrl)
2019-07-29 23:17:41 +02:00
import Html
exposing
( Html
, a
, article
, h1
2019-08-04 23:25:17 +02:00
, h2
2019-07-29 23:17:41 +02:00
, input
, li
, nav
2019-08-04 23:25:17 +02:00
, p
2019-07-29 23:17:41 +02:00
, section
, small
, text
, ul
)
import Html.Attributes exposing (href, placeholder, readonly, style, value)
2019-07-27 16:24:13 +02:00
import Html.Events exposing (onInput)
import Parse exposing (parseUrl)
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-29 22:31:11 +02:00
section myStyle
2019-07-29 21:16:33 +02:00
[ header
, body state
, footer
]
header : Html msg
header =
Html.header []
[ h1 myStyle [ text servicename ]
]
footer : Html msg
footer =
Html.footer myStyle
[ nav []
[ ul []
[ li []
[ small []
[ text "Created by "
2019-07-29 23:17:41 +02:00
, a [ href "https://www.vbrandl.net/" ]
[ text "Valentin Brandl" ]
2019-07-29 21:16:33 +02:00
, text "."
]
]
]
]
2019-07-29 22:12:54 +02:00
, nav []
[ ul []
[ li []
[ small []
2019-07-29 23:17:41 +02:00
[ a [ href repository ]
[ text "Repository" ]
]
2019-07-29 22:12:54 +02:00
]
, li []
[ small []
2019-07-29 23:17:41 +02:00
[ a [ href "https://opensource.org/licenses/MIT" ]
[ text "MIT License" ]
]
2019-07-29 22:12:54 +02:00
]
]
]
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 [ readonly True, value (displayMUrl state.parsed) ]) []
2019-08-04 23:25:17 +02:00
, h2 myStyle
[ text "Caching" ]
, p myStyle
[ text "Files are cached in the CDN for about one year" ]
, h2 myStyle
[ text "Invalidating the Cache" ]
, p myStyle
[ text "To delete a file from the cache, just request the file via HTTP "
, code "DELETE"
]
2019-07-27 16:24:13 +02:00
]
2019-08-04 23:25:17 +02:00
code : String -> Html msg
code msg =
Html.code [] [ text msg ]
2019-07-27 16:24:13 +02:00
main : Program () Model Msg
main =
2019-07-29 23:17:41 +02:00
Browser.sandbox
{ init = init
, update = update
, view = view
}