frontend: add the ability to remove watch items

This commit is contained in:
Aaron Bieber 2023-06-07 11:59:19 -06:00
parent dbcf63674c
commit aabc5a7ee5
No known key found for this signature in database
3 changed files with 83 additions and 9 deletions

View File

@ -6153,15 +6153,15 @@ 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 = F5(
function (ownerId, name, repo, resultCount, results) {
return {name: name, ownerId: ownerId, repo: repo, resultCount: resultCount, results: results};
var $author$project$Data$Watch = F6(
function (id, ownerId, name, repo, resultCount, results) {
return {id: id, name: name, ownerId: ownerId, repo: repo, resultCount: resultCount, results: results};
});
var $elm$json$Json$Decode$map5 = _Json_map5;
var $author$project$Data$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) {
return {nameWithOwner: nameWithOwner};
};
@ -6177,9 +6177,10 @@ var $author$project$Main$resultsDecoder = A6(
A2($elm$json$Json$Decode$field, 'repository', $author$project$Main$repoInfoDecoder),
A2($elm$json$Json$Decode$field, 'title', $elm$json$Json$Decode$string),
A2($elm$json$Json$Decode$field, 'url', $elm$json$Json$Decode$string));
var $author$project$Main$watchDecoder = A6(
$elm$json$Json$Decode$map5,
var $author$project$Main$watchDecoder = A7(
$elm$json$Json$Decode$map6,
$author$project$Data$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),
A2($elm$json$Json$Decode$field, 'repo', $elm$json$Json$Decode$string),
@ -6331,6 +6332,21 @@ var $author$project$Main$deleteLink = function (linkId) {
url: '/links/' + $elm$core$String$fromInt(linkId)
});
};
var $author$project$Main$DeletedWatch = function (a) {
return {$: 'DeletedWatch', a: a};
};
var $author$project$Main$deleteWatch = function (watchId) {
return $elm$http$Http$request(
{
body: $elm$http$Http$emptyBody,
expect: $elm$http$Http$expectWhatever($author$project$Main$DeletedWatch),
headers: _List_Nil,
method: 'DELETE',
timeout: $elm$core$Maybe$Nothing,
tracker: $elm$core$Maybe$Nothing,
url: '/watches/' + $elm$core$String$fromInt(watchId)
});
};
var $author$project$Main$HidItem = function (a) {
return {$: 'HidItem', a: a};
};
@ -6364,6 +6380,11 @@ var $author$project$Main$update = F2(
return _Utils_Tuple2(
model,
$author$project$Main$deleteLink(linkId));
case 'DeleteWatch':
var watchId = msg.a;
return _Utils_Tuple2(
model,
$author$project$Main$deleteWatch(watchId));
case 'GotNewWatch':
var newwatch = msg.a;
return _Utils_Tuple2(
@ -6422,6 +6443,18 @@ var $author$project$Main$update = F2(
}),
$elm$core$Platform$Cmd$none);
}
case 'DeletedWatch':
if (msg.a.$ === 'Ok') {
return _Utils_Tuple2(model, $author$project$Main$getWatches);
} else {
return _Utils_Tuple2(
_Utils_update(
model,
{
status: $author$project$Main$Errored('Server error deleting watch!')
}),
$elm$core$Platform$Cmd$none);
}
case 'HidItem':
if (msg.a.$ === 'Err') {
return _Utils_Tuple2(
@ -6961,6 +6994,9 @@ var $author$project$Main$viewLinks = function (model) {
};
var $author$project$Main$ReloadWatches = {$: 'ReloadWatches'};
var $elm$html$Html$ul = _VirtualDom_node('ul');
var $author$project$Main$DeleteWatch = function (a) {
return {$: 'DeleteWatch', a: a};
};
var $elm$html$Html$b = _VirtualDom_node('b');
var $author$project$Main$HideWatchedItem = F2(
function (a, b) {
@ -7027,7 +7063,18 @@ var $author$project$Main$viewWatch = function (watch) {
[
$elm$html$Html$text(watch.repo),
$elm$html$Html$text(' -> '),
$elm$html$Html$text(watch.name)
$elm$html$Html$text(watch.name),
A2(
$elm$html$Html$span,
_List_fromArray(
[
$elm$html$Html$Events$onClick(
$author$project$Main$DeleteWatch(watch.id))
]),
_List_fromArray(
[
$elm$html$Html$text(' ×')
]))
])),
A2(
$elm$html$Html$ul,

View File

@ -20,7 +20,8 @@ type alias Link =
type alias Watch =
{ ownerId : Int
{ id : Int
, ownerId : Int
, name : String
, repo : String
, resultCount : Int

View File

@ -35,6 +35,8 @@ type Msg
| AddedWatch (Result Http.Error ())
| DeletedLink (Result Http.Error ())
| DeleteLink Int
| DeletedWatch (Result Http.Error ())
| DeleteWatch Int
| GotLinks (Result Http.Error (List Data.Link))
| GotNewLink NewLink
| GotNewWatch NewWatch
@ -169,12 +171,28 @@ deleteLink linkId =
}
deleteWatch : Int -> Cmd Msg
deleteWatch watchId =
Http.request
{ url = "/watches/" ++ String.fromInt watchId
, method = "DELETE"
, timeout = Nothing
, tracker = Nothing
, headers = []
, body = Http.emptyBody
, expect = Http.expectWhatever DeletedWatch
}
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
DeleteLink linkId ->
( model, deleteLink linkId )
DeleteWatch watchId ->
( model, deleteWatch watchId )
GotNewWatch newwatch ->
( { model | newwatch = newwatch }, Cmd.none )
@ -199,6 +217,12 @@ update msg model =
DeletedLink (Err _) ->
( { model | status = Errored "Server error deleting link!" }, Cmd.none )
DeletedWatch (Ok _) ->
( model, getWatches )
DeletedWatch (Err _) ->
( { model | status = Errored "Server error deleting watch!" }, Cmd.none )
HidItem (Err _) ->
( { model | status = Errored "Server error when hiding a watch item!" }, Cmd.none )
@ -336,7 +360,8 @@ linkDecoder =
watchDecoder : Decoder Data.Watch
watchDecoder =
map5 Data.Watch
map6 Data.Watch
(field "id" int)
(field "owner_id" int)
(field "name" string)
(field "repo" string)
@ -501,6 +526,7 @@ viewWatch watch =
[ text watch.repo
, text " -> "
, text watch.name
, span [ onClick (DeleteWatch watch.id) ] [ text " ×" ]
]
, ul [] (List.map displayResult watch.results)
]