organize elm code a bit

This commit is contained in:
Aaron Bieber 2023-06-12 08:02:49 -06:00
parent 007330eff7
commit e01f85142a
No known key found for this signature in database

View File

@ -378,54 +378,6 @@ getWatches =
} }
linkListDecoder : Decoder (List Link)
linkListDecoder =
list linkDecoder
watchListDecoder : Decoder (List Watch)
watchListDecoder =
list watchDecoder
linkDecoder : Decoder Link
linkDecoder =
map6 Link
(field "id" int)
(field "created_at" string)
(field "url" string)
(field "name" string)
(field "logo_url" string)
(field "shared" bool)
watchDecoder : Decoder Watch
watchDecoder =
map6 Watch
(field "id" int)
(field "owner_id" int)
(field "name" string)
(field "repo" string)
(field "result_count" int)
(field "results" <| list resultsDecoder)
resultsDecoder : Decoder Node
resultsDecoder =
map5 Node
(field "number" int)
(field "createdAt" string)
(field "repository" repoInfoDecoder)
(field "title" string)
(field "url" string)
repoInfoDecoder : Decoder RepoInfo
repoInfoDecoder =
Decode.map RepoInfo
(field "nameWithOwner" string)
watchForm : Model -> NewWatch -> Html Msg watchForm : Model -> NewWatch -> Html Msg
watchForm model newwatch = watchForm model newwatch =
div [] div []
@ -498,8 +450,8 @@ createForm action content =
] ]
bar : Html Msg -> Html Msg -> Html Msg viewBar : Html Msg -> Html Msg -> Html Msg
bar left right = viewBar left right =
header [ class "bar" ] header [ class "bar" ]
[ div [ class "bar-left" ] [ left ] [ div [ class "bar-left" ] [ left ]
, div [ class "bar-right" ] [ right ] , div [ class "bar-right" ] [ right ]
@ -509,7 +461,7 @@ bar left right =
viewLinks : Model -> Html Msg viewLinks : Model -> Html Msg
viewLinks model = viewLinks model =
div [] div []
[ bar (linkForm model model.newlink) (a [ onClick ReloadLinks ] [ text " " ]) [ viewBar (linkForm model model.newlink) (a [ onClick ReloadLinks ] [ text " " ])
, case model.links of , case model.links of
_ :: _ -> _ :: _ ->
div div
@ -524,7 +476,7 @@ viewLinks model =
viewWatches : Model -> Html Msg viewWatches : Model -> Html Msg
viewWatches model = viewWatches model =
div [] div []
[ bar (watchForm model model.newwatch) (a [ onClick ReloadWatches ] [ text " " ]) [ viewBar (watchForm model model.newwatch) (a [ onClick ReloadWatches ] [ text " " ])
, case model.watches of , case model.watches of
_ :: _ -> _ :: _ ->
ul [] (List.map viewWatch model.watches) ul [] (List.map viewWatch model.watches)
@ -569,14 +521,14 @@ viewWatch watch =
, text watch.name , text watch.name
, span [ onClick (DeleteWatch watch.id) ] [ text " ×" ] , span [ onClick (DeleteWatch watch.id) ] [ text " ×" ]
] ]
, ul [] (List.map displayResult watch.results) , ul [] (List.map viewResult watch.results)
] ]
] ]
] ]
displayResult : Node -> Html Msg viewResult : Node -> Html Msg
displayResult node = viewResult node =
li [] li []
[ a [ href node.url ] [ text (String.fromInt node.number) ] [ a [ href node.url ] [ text (String.fromInt node.number) ]
, text " :: " , text " :: "
@ -584,3 +536,55 @@ displayResult node =
, text " :: " , text " :: "
, text node.title , text node.title
] ]
-- DECODERS
linkListDecoder : Decoder (List Link)
linkListDecoder =
list linkDecoder
linkDecoder : Decoder Link
linkDecoder =
map6 Link
(field "id" int)
(field "created_at" string)
(field "url" string)
(field "name" string)
(field "logo_url" string)
(field "shared" bool)
watchListDecoder : Decoder (List Watch)
watchListDecoder =
list watchDecoder
watchDecoder : Decoder Watch
watchDecoder =
map6 Watch
(field "id" int)
(field "owner_id" int)
(field "name" string)
(field "repo" string)
(field "result_count" int)
(field "results" <| list resultsDecoder)
resultsDecoder : Decoder Node
resultsDecoder =
map5 Node
(field "number" int)
(field "createdAt" string)
(field "repository" repoInfoDecoder)
(field "title" string)
(field "url" string)
repoInfoDecoder : Decoder RepoInfo
repoInfoDecoder =
Decode.map RepoInfo
(field "nameWithOwner" string)