From c6bfcaa305259a07a046b8bfa380419180f6be45 Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Wed, 22 Feb 2023 21:02:48 -0600 Subject: Add: WIP track info editing --- model.lisp | 7 +++++++ playlist.lisp | 29 ++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/model.lisp b/model.lisp index de1ea10..65968cb 100644 --- a/model.lisp +++ b/model.lisp @@ -178,3 +178,10 @@ (defun update-playlist-title (playlist title) (with-transaction () (setf (playlist-title playlist) title))) + +(defun update-track-info (track new-artist new-album new-title) + (with-transaction () + (with-slots (artist album title) track + (setf artist new-artist + album new-album + title new-title)))) diff --git a/playlist.lisp b/playlist.lisp index 3fad639..88da89e 100644 --- a/playlist.lisp +++ b/playlist.lisp @@ -17,10 +17,9 @@ (:documentation "Holds the complete state for this session's viewing of a particular playlist.")) (defclass/std track-ctl () - ((track audio container :std nil)) + ((track audio container info-edit-ctl edit-save-btn editing? :std nil)) (:documentation "The state of a particular track in this session's viewing of a playlist.")) - (defun audio-for-track (ctl track) "Return the audio element associated with the track" (when-let (trctl (find track (tracks ctl) :test #'eq :key #'track)) @@ -228,6 +227,24 @@ ;; swap list items in the dom (place-after (container cur) (container next))))))) +(defun toggle-track-editor (track-ctl) + (setf (editing? track-ctl) (not (editing? track-ctl))) + (if (editing? track-ctl) + (progn + (setf (text (edit-save-btn track-ctl)) "save ") + (with-clog-create (info-edit-ctl track-ctl) + (div (:class "track-edit-inputs") + (form-element (:text :bind artist-input)) + (form-element (:text :bind album-input)) + (form-element (:text :bind title-input))) + (set-on-click + (edit-save-btn track-ctl) + (thunk* (update-track-info + (track track-ctl) (value artist-input) (value album-input) (value title-input)) + (toggle-track-editor track-ctl))))) + (setf (display (info-edit-ctl track-ctl)) "none" + (text (print (edit-save-btn track-ctl))) "edit "))) + (defun add-zipped-playlist-link (pl-ctl playlist) "Adds the link to a zipped playlist to the DOM." (for-playlist-viewers (pl-download pl-ctl) ctl @@ -292,7 +309,9 @@ (div (:bind item :class "track-list-item") (section (:pre :content (track-listing-line track)))) + (div (:bind info-edit-ctl :class "track-list-edit")) (div (:bind edit-controls) + (button (:content "edit " :bind edit-save-btn)) (button (:content "delete " :bind delbtn)) (button (:content "↓" :bind downbtn)) (button (:content "↑" :bind upbtn))) @@ -301,13 +320,17 @@ (make-instance 'track-ctl :container container :audio audio - :track track))) + :track track + :info-edit-ctl info-edit-ctl + :edit-save-btn edit-save-btn + :editing? nil))) (setf (tracks ctl) (insert-nth track-ctl -1 (tracks ctl) t)) (cond ((editorp ctl) (setf (attribute downbtn "title") "move track down" (attribute upbtn "title") "move track up") + (set-on-click edit-save-btn (thunk* (toggle-track-editor track-ctl))) (set-on-click delbtn (thunk* (remove-track track-ctl))) (set-on-click downbtn (thunk* (move-track-down track-ctl))) (set-on-click upbtn (thunk* (move-track-up track-ctl)))) -- cgit v1.2.3