Skip to content

Commit

Permalink
Ask for confirmation before deletion/data removal
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenceWarne committed Jul 23, 2023
1 parent c8143ff commit 0da8032
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
32 changes: 19 additions & 13 deletions finito.el
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ request is successful"
(insert (format "\n- You gave an average rating of %s." rating-str))
(overlay-put
(make-overlay (- (point) (length (number-to-string .read)) 1)
(- (point) 1))
(1- (point)))
'face 'finito-summary-average-rating))
(when finito-summary-show-recommended
(insert (concat "\n\n" finito--summary-recommended-text)))
Expand Down Expand Up @@ -763,16 +763,18 @@ maximum of MAX-RESULTS results."
(interactive)
(finito--wait-for-server-then
(let* ((book (finito--book-at-point))
(title (alist-get 'title book))
(isbn (alist-get 'isbn book))
(line (line-number-at-pos))
(buf (current-buffer)))
(finito--make-request
(finito--remove-book-request-plist finito--collection isbn)
(lambda (_)
(message "Removed '%s' from %s"
(alist-get 'title book)
finito--collection)
(finito--goto-buffer-line-and-remove-book-at-point buf line))))))
(when (y-or-n-p (format "Remove '%s' from %s?" title finito--collection))
(finito--make-request
(finito--remove-book-request-plist finito--collection isbn)
(lambda (_)
(message "Removed '%s' from %s"
(alist-get 'title book)
finito--collection)
(finito--goto-buffer-line-and-remove-book-at-point buf line)))))))

(defun finito-collection-revert (&optional _ignore-auto _noconfirm)
"Refresh the current collection, _IGNORE-AUTO and _NOCONFIRM are ignored."
Expand Down Expand Up @@ -867,11 +869,15 @@ When DATE is specified, mark that as the date the book was finished."
(interactive)
(finito--wait-for-server-then
(let ((book (finito--book-at-point)))
(finito--make-request
(finito--delete-book-data-request-plist (alist-get 'isbn book))
(lambda (_)
(message "Deleted info held about '%s'" (alist-get 'title book))
(finito-collection-revert))))))
(when (y-or-n-p
(format
"Remove held data for '%s' (note this won't remove the book from any collections)?"
(alist-get 'title book)))
(finito--make-request
(finito--delete-book-data-request-plist (alist-get 'isbn book))
(lambda (_)
(message "Deleted info held about '%s'" (alist-get 'title book))
(finito-collection-revert)))))))

(defun finito-replay-search ()
"Open the search transient prefix with the last args that were used."
Expand Down
6 changes: 4 additions & 2 deletions test/finito-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,8 @@ GNU Emacs is awesome!
(funcall callback)))
(spy-on 'finito--make-request :and-return-value nil)
(spy-on 'finito--book-at-point :and-return-value book)
(spy-on 'finito--remove-book-request-plist :and-call-through))
(spy-on 'finito--remove-book-request-plist :and-call-through)
(spy-on 'y-or-n-p :and-return-value t))

(it "removes book"
(let ((finito--collection "collection to remove from"))
Expand Down Expand Up @@ -703,7 +704,8 @@ GNU Emacs is awesome!
(lambda (callback &rest _)
(funcall callback)))
(spy-on 'finito--book-at-point :and-return-value book)
(spy-on 'finito--delete-book-data-request-plist :and-call-through))
(spy-on 'finito--delete-book-data-request-plist :and-call-through)
(spy-on 'y-or-n-p :and-return-value t))

(it "finishes book"
(let ((finito--collection "collection to refresh"))
Expand Down

0 comments on commit 0da8032

Please sign in to comment.