From d6c98b49c325aea24673c05a27d6b97eef6fe83a Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 10 Jun 2023 06:55:21 -0600 Subject: [PATCH] frontend: move data types into Main.elm --- assets/main.js | 16 +++++----- src/Data.elm | 43 --------------------------- src/Main.elm | 81 +++++++++++++++++++++++++++++++++++++------------- 3 files changed, 69 insertions(+), 71 deletions(-) delete mode 100644 src/Data.elm diff --git a/assets/main.js b/assets/main.js index 5571a8b..10097f4 100644 --- a/assets/main.js +++ b/assets/main.js @@ -6125,7 +6125,7 @@ var $elm$http$Http$get = function (r) { 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}); }; -var $author$project$Data$Link = F6( +var $author$project$Main$Link = F6( function (id, createdAt, url, name, logoURL, shared) { 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 $author$project$Main$linkDecoder = A7( $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, 'created_at', $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) { return {$: 'GotWatches', a: a}; }; -var $author$project$Data$Watch = F6( +var $author$project$Main$Watch = F6( function (id, ownerId, name, repo, resultCount, 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) { return {createdAt: createdAt, number: number, repository: repository, title: title, url: url}; }); 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}; }; var $author$project$Main$repoInfoDecoder = A2( $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)); var $author$project$Main$resultsDecoder = A6( $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, 'createdAt', $elm$json$Json$Decode$string), 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)); var $author$project$Main$watchDecoder = A7( $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, 'owner_id', $elm$json$Json$Decode$int), A2($elm$json$Json$Decode$field, 'name', $elm$json$Json$Decode$string), diff --git a/src/Data.elm b/src/Data.elm deleted file mode 100644 index 703c36e..0000000 --- a/src/Data.elm +++ /dev/null @@ -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 - } diff --git a/src/Main.elm b/src/Main.elm index 88b0dac..dd883fb 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -1,7 +1,6 @@ module Main exposing (..) import Browser -import Data import Html exposing (..) import Html.Attributes exposing (checked, class, classList, href, name, placeholder, src, type_, value) import Html.Events exposing (..) @@ -20,6 +19,48 @@ import Json.Decode as Decode 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 = Browser.element @@ -37,10 +78,10 @@ type Msg | DeleteLink Int | DeletedWatch (Result Http.Error ()) | DeleteWatch Int - | GotLinks (Result Http.Error (List Data.Link)) + | GotLinks (Result Http.Error (List Link)) | GotNewLink NewLink | GotNewWatch NewWatch - | GotWatches (Result Http.Error (List Data.Watch)) + | GotWatches (Result Http.Error (List Watch)) | HideWatchedItem Int String | HidItem (Result Http.Error ()) | Reload @@ -52,8 +93,8 @@ type Msg type Status = Loading - | LoadedWatches (List Data.Watch) - | LoadedLinks (List Data.Link) + | LoadedWatches (List Watch) + | LoadedLinks (List Link) | Errored String @@ -72,8 +113,8 @@ type alias NewLink = type alias Model = - { watches : List Data.Watch - , links : List Data.Link + { watches : List Watch + , links : List Link , errors : List String , status : Status , newlink : NewLink @@ -337,19 +378,19 @@ getWatches = } -linkListDecoder : Decoder (List Data.Link) +linkListDecoder : Decoder (List Link) linkListDecoder = list linkDecoder -watchListDecoder : Decoder (List Data.Watch) +watchListDecoder : Decoder (List Watch) watchListDecoder = list watchDecoder -linkDecoder : Decoder Data.Link +linkDecoder : Decoder Link linkDecoder = - map6 Data.Link + map6 Link (field "id" int) (field "created_at" string) (field "url" string) @@ -358,9 +399,9 @@ linkDecoder = (field "shared" bool) -watchDecoder : Decoder Data.Watch +watchDecoder : Decoder Watch watchDecoder = - map6 Data.Watch + map6 Watch (field "id" int) (field "owner_id" int) (field "name" string) @@ -369,9 +410,9 @@ watchDecoder = (field "results" <| list resultsDecoder) -resultsDecoder : Decoder Data.Node +resultsDecoder : Decoder Node resultsDecoder = - map5 Data.Node + map5 Node (field "number" int) (field "createdAt" string) (field "repository" repoInfoDecoder) @@ -379,9 +420,9 @@ resultsDecoder = (field "url" string) -repoInfoDecoder : Decoder Data.RepoInfo +repoInfoDecoder : Decoder RepoInfo repoInfoDecoder = - Decode.map Data.RepoInfo + Decode.map RepoInfo (field "nameWithOwner" string) @@ -493,7 +534,7 @@ viewWatches model = ] -viewLink : Data.Link -> Html Msg +viewLink : Link -> Html Msg viewLink link = div [] [ div [ class "icon" ] @@ -511,7 +552,7 @@ viewLink link = ] -viewWatch : Data.Watch -> Html Msg +viewWatch : Watch -> Html Msg viewWatch watch = case watch.results of [] -> @@ -534,7 +575,7 @@ viewWatch watch = ] -displayResult : Data.Node -> Html Msg +displayResult : Node -> Html Msg displayResult node = li [] [ a [ href node.url ] [ text (String.fromInt node.number) ]