frontend: start refactoring

This commit is contained in:
Cadey Ratio 2020-01-13 00:02:11 +00:00
parent da98792d35
commit 1c6c0a44a2
3 changed files with 68 additions and 53 deletions

View File

@ -1,4 +1,4 @@
module Main exposing (..) module Main exposing (main)
import Browser import Browser
import Browser.Navigation as Nav import Browser.Navigation as Nav
@ -7,6 +7,7 @@ import Html.Attributes exposing (..)
import Html.Events exposing (onInput) import Html.Events exposing (onInput)
import Http import Http
import Json.Decode as D import Json.Decode as D
import Skeleton exposing (..)
import SwitchData import SwitchData
import Url import Url
import Url.Builder 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 : (Result Http.Error a -> msg) -> D.Decoder a -> Http.Expect msg
expectJson toMsg decoder = expectJson toMsg decoder =
Http.expectStringResponse toMsg <| Http.expectStringResponse toMsg <|

56
frontend/src/Skeleton.elm Normal file
View File

@ -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 ]

View File

@ -1,4 +1,8 @@
module SwitchData exposing (..) module SwitchData exposing
( Switch
, dataURL
, decoder
)
import Iso8601 import Iso8601
import Json.Decode exposing (Decoder, field, int, map5, nullable, string) import Json.Decode exposing (Decoder, field, int, map5, nullable, string)
@ -27,4 +31,8 @@ decoder =
dataURL : Int -> Int -> String dataURL : Int -> Int -> String
dataURL limit page = 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
]