frontend: move data types into Main.elm

This commit is contained in:
Aaron Bieber 2023-06-10 06:55:21 -06:00
parent e1ce889da1
commit d6c98b49c3
No known key found for this signature in database
3 changed files with 69 additions and 71 deletions

View File

@ -6125,7 +6125,7 @@ var $elm$http$Http$get = function (r) {
return $elm$http$Http$request( return $elm$http$Http$request(
{body: $elm$http$Http$emptyBody, expect: r.expect, headers: _List_Nil, method: 'GET', timeout: $elm$core$Maybe$Nothing, tracker: $elm$core$Maybe$Nothing, url: r.url}); {body: $elm$http$Http$emptyBody, expect: r.expect, headers: _List_Nil, method: 'GET', timeout: $elm$core$Maybe$Nothing, tracker: $elm$core$Maybe$Nothing, url: r.url});
}; };
var $author$project$Data$Link = F6( var $author$project$Main$Link = F6(
function (id, createdAt, url, name, logoURL, shared) { function (id, createdAt, url, name, logoURL, shared) {
return {createdAt: createdAt, id: id, logoURL: logoURL, name: name, shared: shared, url: url}; return {createdAt: createdAt, id: id, logoURL: logoURL, name: name, shared: shared, url: url};
}); });
@ -6136,7 +6136,7 @@ var $elm$json$Json$Decode$map6 = _Json_map6;
var $elm$json$Json$Decode$string = _Json_decodeString; var $elm$json$Json$Decode$string = _Json_decodeString;
var $author$project$Main$linkDecoder = A7( var $author$project$Main$linkDecoder = A7(
$elm$json$Json$Decode$map6, $elm$json$Json$Decode$map6,
$author$project$Data$Link, $author$project$Main$Link,
A2($elm$json$Json$Decode$field, 'id', $elm$json$Json$Decode$int), A2($elm$json$Json$Decode$field, 'id', $elm$json$Json$Decode$int),
A2($elm$json$Json$Decode$field, 'created_at', $elm$json$Json$Decode$string), A2($elm$json$Json$Decode$field, 'created_at', $elm$json$Json$Decode$string),
A2($elm$json$Json$Decode$field, 'url', $elm$json$Json$Decode$string), A2($elm$json$Json$Decode$field, 'url', $elm$json$Json$Decode$string),
@ -6153,25 +6153,25 @@ var $author$project$Main$getLinks = $elm$http$Http$get(
var $author$project$Main$GotWatches = function (a) { var $author$project$Main$GotWatches = function (a) {
return {$: 'GotWatches', a: a}; return {$: 'GotWatches', a: a};
}; };
var $author$project$Data$Watch = F6( var $author$project$Main$Watch = F6(
function (id, ownerId, name, repo, resultCount, results) { function (id, ownerId, name, repo, resultCount, results) {
return {id: id, name: name, ownerId: ownerId, repo: repo, resultCount: resultCount, results: results}; return {id: id, name: name, ownerId: ownerId, repo: repo, resultCount: resultCount, results: results};
}); });
var $author$project$Data$Node = F5( var $author$project$Main$Node = F5(
function (number, createdAt, repository, title, url) { function (number, createdAt, repository, title, url) {
return {createdAt: createdAt, number: number, repository: repository, title: title, url: url}; return {createdAt: createdAt, number: number, repository: repository, title: title, url: url};
}); });
var $elm$json$Json$Decode$map5 = _Json_map5; var $elm$json$Json$Decode$map5 = _Json_map5;
var $author$project$Data$RepoInfo = function (nameWithOwner) { var $author$project$Main$RepoInfo = function (nameWithOwner) {
return {nameWithOwner: nameWithOwner}; return {nameWithOwner: nameWithOwner};
}; };
var $author$project$Main$repoInfoDecoder = A2( var $author$project$Main$repoInfoDecoder = A2(
$elm$json$Json$Decode$map, $elm$json$Json$Decode$map,
$author$project$Data$RepoInfo, $author$project$Main$RepoInfo,
A2($elm$json$Json$Decode$field, 'nameWithOwner', $elm$json$Json$Decode$string)); A2($elm$json$Json$Decode$field, 'nameWithOwner', $elm$json$Json$Decode$string));
var $author$project$Main$resultsDecoder = A6( var $author$project$Main$resultsDecoder = A6(
$elm$json$Json$Decode$map5, $elm$json$Json$Decode$map5,
$author$project$Data$Node, $author$project$Main$Node,
A2($elm$json$Json$Decode$field, 'number', $elm$json$Json$Decode$int), A2($elm$json$Json$Decode$field, 'number', $elm$json$Json$Decode$int),
A2($elm$json$Json$Decode$field, 'createdAt', $elm$json$Json$Decode$string), A2($elm$json$Json$Decode$field, 'createdAt', $elm$json$Json$Decode$string),
A2($elm$json$Json$Decode$field, 'repository', $author$project$Main$repoInfoDecoder), A2($elm$json$Json$Decode$field, 'repository', $author$project$Main$repoInfoDecoder),
@ -6179,7 +6179,7 @@ var $author$project$Main$resultsDecoder = A6(
A2($elm$json$Json$Decode$field, 'url', $elm$json$Json$Decode$string)); A2($elm$json$Json$Decode$field, 'url', $elm$json$Json$Decode$string));
var $author$project$Main$watchDecoder = A7( var $author$project$Main$watchDecoder = A7(
$elm$json$Json$Decode$map6, $elm$json$Json$Decode$map6,
$author$project$Data$Watch, $author$project$Main$Watch,
A2($elm$json$Json$Decode$field, 'id', $elm$json$Json$Decode$int), A2($elm$json$Json$Decode$field, 'id', $elm$json$Json$Decode$int),
A2($elm$json$Json$Decode$field, 'owner_id', $elm$json$Json$Decode$int), A2($elm$json$Json$Decode$field, 'owner_id', $elm$json$Json$Decode$int),
A2($elm$json$Json$Decode$field, 'name', $elm$json$Json$Decode$string), A2($elm$json$Json$Decode$field, 'name', $elm$json$Json$Decode$string),

View File

@ -1,43 +0,0 @@
module Data exposing (Link, Links, Node, RepoInfo, Watch, Watches)
type alias Watches =
List Watch
type alias Links =
List Link
type alias Link =
{ id : Int
, createdAt : String
, url : String
, name : String
, logoURL : String
, shared : Bool
}
type alias Watch =
{ id : Int
, ownerId : Int
, name : String
, repo : String
, resultCount : Int
, results : List Node
}
type alias Node =
{ number : Int
, createdAt : String
, repository : RepoInfo
, title : String
, url : String
}
type alias RepoInfo =
{ nameWithOwner : String
}

View File

@ -1,7 +1,6 @@
module Main exposing (..) module Main exposing (..)
import Browser import Browser
import Data
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (checked, class, classList, href, name, placeholder, src, type_, value) import Html.Attributes exposing (checked, class, classList, href, name, placeholder, src, type_, value)
import Html.Events exposing (..) import Html.Events exposing (..)
@ -20,6 +19,48 @@ import Json.Decode as Decode
import Json.Encode as Encode import Json.Encode as Encode
type alias Watches =
List Watch
type alias Links =
List Link
type alias Link =
{ id : Int
, createdAt : String
, url : String
, name : String
, logoURL : String
, shared : Bool
}
type alias Watch =
{ id : Int
, ownerId : Int
, name : String
, repo : String
, resultCount : Int
, results : List Node
}
type alias Node =
{ number : Int
, createdAt : String
, repository : RepoInfo
, title : String
, url : String
}
type alias RepoInfo =
{ nameWithOwner : String
}
main : Program () Model Msg main : Program () Model Msg
main = main =
Browser.element Browser.element
@ -37,10 +78,10 @@ type Msg
| DeleteLink Int | DeleteLink Int
| DeletedWatch (Result Http.Error ()) | DeletedWatch (Result Http.Error ())
| DeleteWatch Int | DeleteWatch Int
| GotLinks (Result Http.Error (List Data.Link)) | GotLinks (Result Http.Error (List Link))
| GotNewLink NewLink | GotNewLink NewLink
| GotNewWatch NewWatch | GotNewWatch NewWatch
| GotWatches (Result Http.Error (List Data.Watch)) | GotWatches (Result Http.Error (List Watch))
| HideWatchedItem Int String | HideWatchedItem Int String
| HidItem (Result Http.Error ()) | HidItem (Result Http.Error ())
| Reload | Reload
@ -52,8 +93,8 @@ type Msg
type Status type Status
= Loading = Loading
| LoadedWatches (List Data.Watch) | LoadedWatches (List Watch)
| LoadedLinks (List Data.Link) | LoadedLinks (List Link)
| Errored String | Errored String
@ -72,8 +113,8 @@ type alias NewLink =
type alias Model = type alias Model =
{ watches : List Data.Watch { watches : List Watch
, links : List Data.Link , links : List Link
, errors : List String , errors : List String
, status : Status , status : Status
, newlink : NewLink , newlink : NewLink
@ -337,19 +378,19 @@ getWatches =
} }
linkListDecoder : Decoder (List Data.Link) linkListDecoder : Decoder (List Link)
linkListDecoder = linkListDecoder =
list linkDecoder list linkDecoder
watchListDecoder : Decoder (List Data.Watch) watchListDecoder : Decoder (List Watch)
watchListDecoder = watchListDecoder =
list watchDecoder list watchDecoder
linkDecoder : Decoder Data.Link linkDecoder : Decoder Link
linkDecoder = linkDecoder =
map6 Data.Link map6 Link
(field "id" int) (field "id" int)
(field "created_at" string) (field "created_at" string)
(field "url" string) (field "url" string)
@ -358,9 +399,9 @@ linkDecoder =
(field "shared" bool) (field "shared" bool)
watchDecoder : Decoder Data.Watch watchDecoder : Decoder Watch
watchDecoder = watchDecoder =
map6 Data.Watch map6 Watch
(field "id" int) (field "id" int)
(field "owner_id" int) (field "owner_id" int)
(field "name" string) (field "name" string)
@ -369,9 +410,9 @@ watchDecoder =
(field "results" <| list resultsDecoder) (field "results" <| list resultsDecoder)
resultsDecoder : Decoder Data.Node resultsDecoder : Decoder Node
resultsDecoder = resultsDecoder =
map5 Data.Node map5 Node
(field "number" int) (field "number" int)
(field "createdAt" string) (field "createdAt" string)
(field "repository" repoInfoDecoder) (field "repository" repoInfoDecoder)
@ -379,9 +420,9 @@ resultsDecoder =
(field "url" string) (field "url" string)
repoInfoDecoder : Decoder Data.RepoInfo repoInfoDecoder : Decoder RepoInfo
repoInfoDecoder = repoInfoDecoder =
Decode.map Data.RepoInfo Decode.map RepoInfo
(field "nameWithOwner" string) (field "nameWithOwner" string)
@ -493,7 +534,7 @@ viewWatches model =
] ]
viewLink : Data.Link -> Html Msg viewLink : Link -> Html Msg
viewLink link = viewLink link =
div [] div []
[ div [ class "icon" ] [ div [ class "icon" ]
@ -511,7 +552,7 @@ viewLink link =
] ]
viewWatch : Data.Watch -> Html Msg viewWatch : Watch -> Html Msg
viewWatch watch = viewWatch watch =
case watch.results of case watch.results of
[] -> [] ->
@ -534,7 +575,7 @@ viewWatch watch =
] ]
displayResult : Data.Node -> Html Msg displayResult : Node -> Html Msg
displayResult node = displayResult node =
li [] li []
[ a [ href node.url ] [ text (String.fromInt node.number) ] [ a [ href node.url ] [ text (String.fromInt node.number) ]