Decoding of all watch data in place

This commit is contained in:
Aaron Bieber 2023-04-24 19:44:18 -06:00
parent 69246c500c
commit 874ad42e4e
No known key found for this signature in database
5 changed files with 48 additions and 44 deletions

View File

@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.16.0
// sqlc v1.17.2
package data

View File

@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.16.0
// sqlc v1.17.2
package data

View File

@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.16.0
// sqlc v1.17.2
// source: queries.sql
package data

View File

@ -1,34 +1,24 @@
module Data exposing (Edge, Link, Node, Watch, WatchData)
module Data exposing (Node, RepoInfo, Watch)
type alias Watch =
{ owner_id : Int
{ ownerId : Int
, name : String
, repo : String
, result_count : Int
, resultCount : Int
, results : Maybe (List Node)
}
type alias Node =
{ number : Int
}
type alias Edge =
{ node : Node
}
type alias WatchData =
{ search : List Edge
}
type alias Link =
{ id : Int
, owner_id : Int
, created_at : String
, name : String
, createdAt : String
, repository : RepoInfo
, title : String
, url : String
, logo_url : String
}
type alias RepoInfo =
{ nameWithOwner : String
}

View File

@ -6,7 +6,20 @@ import Html exposing (..)
import Html.Attributes exposing (style)
import Html.Events exposing (..)
import Http
import Json.Decode exposing (Decoder, field, int, list, map3, map4, map5, maybe, string)
import Json.Decode as Decode
exposing
( Decoder
, decodeString
, field
, float
, int
, list
, map
, map4
, map5
, maybe
, string
)
main =
@ -83,22 +96,6 @@ viewWatches model =
(List.map viewWatch watches)
viewLinks : Model -> Html Msg
viewLinks model =
case model of
Failure ->
div []
[ text "I can't load the links"
, button [ onClick MorePlease ] [ text "Try agan!" ]
]
Loading ->
text "Loading..."
Success links ->
text "success links..."
getWatches : Cmd Msg
getWatches =
Http.get
@ -114,16 +111,33 @@ watchListDecoder =
watchDecoder : Decoder Data.Watch
watchDecoder =
map4 Data.Watch
map5 Data.Watch
(field "owner_id" int)
(field "name" string)
(field "repo" string)
(field "result_count" int)
(field "results" <| maybe (list resultsDecoder))
resultsDecoder : Decoder Data.Node
resultsDecoder =
map5 Data.Node
(field "number" int)
(field "createdAt" string)
(field "repository" repoInfoDecoder)
(field "title" string)
(field "url" string)
repoInfoDecoder : Decoder Data.RepoInfo
repoInfoDecoder =
Decode.map Data.RepoInfo
(field "nameWithOwner" string)
viewWatch : Data.Watch -> Html Msg
viewWatch watch =
li []
[ text (String.fromInt watch.result_count ++ " " ++ watch.name)
[ text (String.fromInt watch.resultCount ++ " " ++ watch.name)
, li [] [ text "butter" ]
]