diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 13b2a86..2143304 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,6 +18,7 @@ jobs: emacs_version: - 27.2 - 28.2 + - 29.1 - 29.2 steps: diff --git a/README.md b/README.md index 301dc68..d527264 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ You can install it from melpa: :demand t ;; The main entry point for finito commands :bind ("C-c b" . finito) + ;; Optional, but can improve the aesthetics of book descriptions + :hook (finito-view-mode . visual-line-mode) :config ;; Downloads the server asynchronously, you can also download the server ;; jar manually from the releases page: diff --git a/finito-graphql.el b/finito-graphql.el index 58168ff..b23608a 100644 --- a/finito-graphql.el +++ b/finito-graphql.el @@ -188,6 +188,29 @@ } }") +(defconst finito--review-book-mutation + (graphql-mutation + (:arguments + (($review . String!) + ($book . BookInput!)) + (addBookReview + :arguments ((review . ($ review)) + (book . ($ book))) + title authors description isbn thumbnailUri + review startedReading lastRead)))) + +(defconst finito--review-book-mutation-variables + "{ + \"review\": \"%s\", + \"book\": { + \"title\": \"%s\", + \"authors\": %s, + \"description\": \"%s\", + \"isbn\": \"%s\", + \"thumbnailUri\": \"%s\" + } + }") + (defconst finito--start-reading-mutation (graphql-mutation (:arguments diff --git a/finito-request.el b/finito-request.el index b21d1ba..82819cf 100644 --- a/finito-request.el +++ b/finito-request.el @@ -185,6 +185,23 @@ BOOK should be the book (as an alist) to rate and RATING the rating." (s-replace "\"" "'" .isbn) (s-replace "\"" "'" .img-uri)))))) +(defun finito--review-book-request-plist (book review) + "Return a plist with headers and body for an add review request. + +BOOK should be the book (as an alist) to review and REVIEW the rating strin." + `(:headers ,finito--headers + :data ,(format "{\"query\":\"%s\", \"variables\": %s}" + finito--review-book-mutation + (let-alist book + (format + finito--review-book-mutation-variables + review + (s-replace "\"" "'" .title) + (finito--seq-to-json-list .authors) + (s-replace "\"" "'" .description) + (s-replace "\"" "'" .isbn) + (s-replace "\"" "'" .img-uri)))))) + (defun finito--start-reading-request-plist (book &optional start-date) "Return a plist with headers and body for a start reading request. diff --git a/finito.el b/finito.el index e69265e..80f26d2 100644 --- a/finito.el +++ b/finito.el @@ -820,6 +820,18 @@ maximum of MAX-RESULTS results." (alist-get 'title book) rating))))) +(defun finito-review-book-at-point () + "Add a review for the book at point. + +Note this overwrites any existing review." + (interactive) + (finito--wait-for-server-then + (let ((book (finito--book-at-point)) + (review (read-string "Review: "))) + (finito--replace-book-at-point-from-request + (finito--review-book-request-plist book review) + (format "Added review for '%s'" (alist-get 'title book)))))) + (defun finito-start-book-at-point (&optional date) "Mark the book at point as currently reading.