diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm index 658c60d..df1888f 100644 --- a/frontend/src/Main.elm +++ b/frontend/src/Main.elm @@ -1,4 +1,4 @@ -module Main exposing (..) +module Main exposing (main) import Browser import Browser.Navigation as Nav @@ -7,6 +7,7 @@ import Html.Attributes exposing (..) import Html.Events exposing (onInput) import Http import Json.Decode as D +import Skeleton exposing (..) import SwitchData import Url import Url.Builder @@ -208,56 +209,6 @@ view model = ] -viewInput : String -> String -> String -> (String -> msg) -> Html msg -viewInput t p v toMsg = - input [ type_ t, placeholder p, value v, onInput toMsg ] [] - - -viewLink : String -> String -> Html msg -viewLink path title = - a [ href path ] [ text title ] - - -template : String -> List (Html msg) -> Browser.Document msg -template title body = - { title = title - , body = - [ node "main" - [] - [ navBar - , div [] body - , footer - ] - ] - } - - -navBar : Html msg -navBar = - node "nav" - [] - [ p [] - [ viewLink "/" "Mi" - , text " - " - , viewLink "/switch" "Switch tracker" - , text " - " - , viewLink "/logout" "Logout" - ] - ] - - -footer : Html msg -footer = - node "footer" - [] - [ p [] - [ a [ href "https://within.website" ] [ text "From Within" ] - , text " - " - , a [ href "https://tulpa.dev/cadey/mi" ] [ text "Source code" ] - ] - ] - - expectJson : (Result Http.Error a -> msg) -> D.Decoder a -> Http.Expect msg expectJson toMsg decoder = Http.expectStringResponse toMsg <| diff --git a/frontend/src/Skeleton.elm b/frontend/src/Skeleton.elm new file mode 100644 index 0000000..8c5fc73 --- /dev/null +++ b/frontend/src/Skeleton.elm @@ -0,0 +1,56 @@ +module Skeleton exposing (footer, navBar, template, viewInput, viewLink) + +import Browser exposing (Document) +import Html exposing (Html, a, div, input, node, p, text) +import Html.Attributes exposing (href, placeholder, type_, value) +import Html.Events exposing (onInput) + + +template : String -> List (Html msg) -> Browser.Document msg +template title body = + { title = title + , body = + [ node "main" + [] + [ navBar + , div [] body + , footer + ] + ] + } + + +navBar : Html msg +navBar = + node "nav" + [] + [ p [] + [ viewLink "/" "Mi" + , text " - " + , viewLink "/switch" "Switch tracker" + , text " - " + , viewLink "/logout" "Logout" + ] + ] + + +footer : Html msg +footer = + node "footer" + [] + [ p [] + [ a [ href "https://within.website" ] [ text "From Within" ] + , text " - " + , a [ href "https://tulpa.dev/cadey/mi" ] [ text "Source code" ] + ] + ] + + +viewInput : String -> String -> String -> (String -> msg) -> Html msg +viewInput t p v toMsg = + input [ type_ t, placeholder p, value v, onInput toMsg ] [] + + +viewLink : String -> String -> Html msg +viewLink path title = + a [ href path ] [ text title ] diff --git a/frontend/src/SwitchData.elm b/frontend/src/SwitchData.elm index 9cd0f95..3465ba3 100644 --- a/frontend/src/SwitchData.elm +++ b/frontend/src/SwitchData.elm @@ -1,4 +1,8 @@ -module SwitchData exposing (..) +module SwitchData exposing + ( Switch + , dataURL + , decoder + ) import Iso8601 import Json.Decode exposing (Decoder, field, int, map5, nullable, string) @@ -27,4 +31,8 @@ decoder = dataURL : Int -> Int -> String dataURL limit page = - UB.absolute [ "switches" ] [ UB.int "limit" limit, UB.int "page" page ] + UB.absolute + [ "switches", "" ] + [ UB.int "limit" limit + , UB.int "page" page + ]