make watch item removal more instant

This commit is contained in:
Aaron Bieber 2023-06-07 11:57:17 -06:00
parent e4cce0b093
commit 22b5492f43
No known key found for this signature in database
3 changed files with 13 additions and 0 deletions

10
app.go
View File

@ -41,3 +41,13 @@ func (a *App) getOwner(r *http.Request) (*tailcfg.Node, error) {
return who.Node, nil
}
func (a *App) removeWatch(id int) {
newWatches := WatchResults{}
for _, w := range *a.watches {
if w.ID != int64(id) {
newWatches = append(newWatches, w)
}
}
a.watches = &newWatches
}

View File

@ -147,6 +147,7 @@ func watchitemDELETE(w http.ResponseWriter, r *http.Request) {
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
app.removeWatch(watchID)
}
func watchitemPOST(w http.ResponseWriter, r *http.Request) {

View File

@ -133,6 +133,7 @@ func UpdateWatches(ghToken string) (*WatchResults, error) {
wr.OwnerID = watch.OwnerID
wr.Name = watch.Name
wr.Repo = watch.Repo
wr.ID = watch.ID
for _, dr := range wr.Data.Search.Edges {
wr.Results = append(wr.Results, dr.Node)
}
@ -150,6 +151,7 @@ func UpdateWatches(ghToken string) (*WatchResults, error) {
}
type WatchResult struct {
ID int64 `json:"id"`
Data Data `json:"data"`
OwnerID int64 `json:"owner_id"`
Name string `json:"name"`