feat: add minibuffer actions to spine-index-model for selected books
This commit is contained in:
@@ -173,7 +173,40 @@ SELECTED-ID expands the matching book's detail section."
|
|||||||
(cl-loop for (date text) in notes
|
(cl-loop for (date text) in notes
|
||||||
collect (ht
|
collect (ht
|
||||||
("date" (format "[%s]" date))
|
("date" (format "[%s]" date))
|
||||||
("text" text)))))))))))
|
("text" text))))))))
|
||||||
|
("minibuffer"
|
||||||
|
(when selected
|
||||||
|
(let ((status (plist-get book :status)))
|
||||||
|
(ht ("actions"
|
||||||
|
(append
|
||||||
|
(cond
|
||||||
|
((equal status "WANT")
|
||||||
|
(list
|
||||||
|
(ht ("command" "status") ("label" "Mark reading")
|
||||||
|
("href" (format "/edit?id=%s&action=status&value=READING" id)))
|
||||||
|
(ht ("command" "note") ("label" "Add note")
|
||||||
|
("href" (format "/edit?id=%s&action=note" id)))))
|
||||||
|
((equal status "READING")
|
||||||
|
(list
|
||||||
|
(ht ("command" "status") ("label" "Mark read")
|
||||||
|
("href" (format "/edit?id=%s&action=status&value=READ" id)))
|
||||||
|
(ht ("command" "status") ("label" "Abandon")
|
||||||
|
("href" (format "/edit?id=%s&action=status&value=ABANDONED" id)))
|
||||||
|
(ht ("command" "note") ("label" "Add note")
|
||||||
|
("href" (format "/edit?id=%s&action=note" id)))))
|
||||||
|
((equal status "READ")
|
||||||
|
(list
|
||||||
|
(ht ("command" "status") ("label" "Read again")
|
||||||
|
("href" (format "/edit?id=%s&action=status&value=READING" id)))
|
||||||
|
(ht ("command" "note") ("label" "Add note")
|
||||||
|
("href" (format "/edit?id=%s&action=note" id)))))
|
||||||
|
((equal status "ABANDONED")
|
||||||
|
(list
|
||||||
|
(ht ("command" "status") ("label" "Try again")
|
||||||
|
("href" (format "/edit?id=%s&action=status&value=READING" id)))))
|
||||||
|
(t nil))
|
||||||
|
nil))))))
|
||||||
|
)))
|
||||||
(push model book-models)))
|
(push model book-models)))
|
||||||
(push (ht ("label" (cdr (assoc status status-labels)))
|
(push (ht ("label" (cdr (assoc status status-labels)))
|
||||||
("count" (length group-books))
|
("count" (length group-books))
|
||||||
|
|||||||
@@ -105,3 +105,30 @@
|
|||||||
(ert-deftest spine-set-status-missing-id ()
|
(ert-deftest spine-set-status-missing-id ()
|
||||||
"spine-set-status signals error for unknown ID."
|
"spine-set-status signals error for unknown ID."
|
||||||
(should-error (spine-set-status "nonexistent-id" "READING")))
|
(should-error (spine-set-status "nonexistent-id" "READING")))
|
||||||
|
|
||||||
|
(ert-deftest spine-edit-model-minibuffer-want ()
|
||||||
|
"Selected WANT book has Mark reading and Add note actions."
|
||||||
|
(spine-edit-test--cleanup)
|
||||||
|
(unwind-protect
|
||||||
|
(progn
|
||||||
|
(spine-edit-test--setup)
|
||||||
|
(let* ((books (spine-books))
|
||||||
|
(book (car books))
|
||||||
|
(id (plist-get book :id))
|
||||||
|
(model (spine-index-model books nil id))
|
||||||
|
(groups (ht-get model "groups")))
|
||||||
|
(cl-labels ((find-book-model (groups id)
|
||||||
|
(cl-block nil
|
||||||
|
(dolist (g groups)
|
||||||
|
(dolist (b (ht-get g "books"))
|
||||||
|
(when (string= (ht-get b "title") "Edit Test Book")
|
||||||
|
(cl-return b)))))))
|
||||||
|
(let ((bm (find-book-model groups id)))
|
||||||
|
(should bm)
|
||||||
|
(let ((mb (ht-get bm "minibuffer")))
|
||||||
|
(should mb)
|
||||||
|
(let ((actions (ht-get mb "actions")))
|
||||||
|
(should (= (length actions) 2))
|
||||||
|
(should (string= (ht-get (nth 0 actions) "label") "Mark reading"))
|
||||||
|
(should (string= (ht-get (nth 1 actions) "label") "Add note"))))))))
|
||||||
|
(spine-edit-test--cleanup)))
|
||||||
|
|||||||
Reference in New Issue
Block a user