aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-10-28 07:15:52 -0500
committerColin Okay <colin@cicadas.surf>2022-10-28 07:15:52 -0500
commit578e2fa0790a7c749e0f597bcdc6b5e4f776dfa2 (patch)
tree1db5347263817aa19723af8a9066457fae11bdbe
parent5b0c8784305b9a2bf34816b264a8d9c6968d0bcc (diff)
Add: collaborator/editor managment on playlists
-rw-r--r--home.lisp4
-rw-r--r--model.lisp9
-rw-r--r--playlist.lisp40
3 files changed, 50 insertions, 3 deletions
diff --git a/home.lisp b/home.lisp
index d1de0c0..90fce4e 100644
--- a/home.lisp
+++ b/home.lisp
@@ -28,8 +28,8 @@
(url-to-playlist pl)))
(with-clog-create parent
(div ()
- (section (:h4)
- (a (:link url :content (playlist-title pl) :bind pl-link))))
+ (p ()
+ (a (:link url :content (playlist-title pl) :bind pl-link))))
(set-on-click
pl-link
(thunk*
diff --git a/model.lisp b/model.lisp
index a866088..b8f564c 100644
--- a/model.lisp
+++ b/model.lisp
@@ -110,6 +110,15 @@
(hash-string pw (user-pwsalt user)))
user))))
+(defun remove-editor (playlist editor)
+ (with-transaction ()
+ (setf (playlist-editors playlist)
+ (delete editor (playlist-editors playlist)))))
+
+(defun add-editor (playlist editor)
+ (with-transaction ()
+ (pushnew editor (playlist-editors playlist) :test #'eq)))
+
(defun destroy-invite (invite)
(with-transaction ()
(bknr.datastore:delete-object invite)))
diff --git a/playlist.lisp b/playlist.lisp
index 938972c..dbe982f 100644
--- a/playlist.lisp
+++ b/playlist.lisp
@@ -301,6 +301,43 @@
(format nil "Error while fetching track at: ~a~%"
url)))))))))))
+(defun create-editor-managment (parent playlist)
+ (when (eq (session-user parent) (playlist-user playlist))
+ (with-clog-create parent
+ (div ()
+ (section (:h3 :content "Collaborators"))
+ (unordered-list (:bind editor-list))
+ (button (:content "Add Contributor" :bind addbtn))
+ (form-element (:text :bind userinput))
+ (span (:bind username-status)))
+ (setf (place-holder userinput) "who?"
+ (width userinput ) 140)
+ (flet ((create-editor-item (editor)
+ (with-clog-create editor-list
+ (p (:content (user-name editor) :bind editor-elem)
+ (button (:content "remove" :bind delbtn)))
+ (set-on-click
+ delbtn
+ (thunk*
+ (remove-editor playlist editor)
+ (destroy editor-elem))))))
+ (set-on-key-press
+ userinput
+ (thunk*
+ (setf (text username-status)
+ (if (user-with-name (value userinput))
+ "✔" "No user with that name"))))
+ (set-on-click
+ addbtn
+ (thunk*
+ (when-let (user (user-with-name (value userinput)))
+ (add-editor playlist user)
+ (setf (value userinput) ""
+ (text username-status) "")
+ (create-editor-item user))))
+ (dolist (editor (playlist-editors playlist))
+ (create-editor-item editor))))))
+
(defun playlist-key-from-url (url)
(first (last (ppcre:split "/" (nth 4 (multiple-value-list (quri:parse-uri url)))))))
@@ -322,7 +359,8 @@
(now-playing-display (ctl))
(track-listing (pl))
- (new-track-form (pl)))
+ (new-track-form (pl))
+ (editor-managment (pl)))
(setf (pl-title ctl) title-elem
(pl-dur ctl) dur-elem
(display input) "none"