aboutsummaryrefslogtreecommitdiffhomepage
path: root/home.lisp
blob: 5df6aedc66e71f3d1f41de70a9d91b203bc2cc8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
;;;; user.lisp

(in-package :vampire)

;;; CLIENT UI

(defun create-new-playlist-form (parent)
  (with-clog-create parent
      (form ()
           (section (:h3 :content "Create New Playlist"))
           (label (:content "Playlist Title:"))
           (form-element (:text :bind pl-title))
           (button (:content "Create" :bind btn)))
    (set-on-click
     btn
     (thunk*
       (new-playlist (session-user parent) :title (value pl-title))
       (reload (location (connection-body parent)))))))

(defun url-to-playlist (pl)
  (format nil "/playlist/~a"
          (key pl)))

(defun create-playlist-listing (parent &optional user)
  (dolist (pl (user-playlists (or user (session-user parent))))
    (with-clog-create parent
        (div (:bind pl-item)
             (div ()
                  (playlist-explore-card (pl))
                  (button (:content "delete" :bind btn))))
      (cond
        ((eq user (session-user parent)) 
         (set-on-click
          btn
          (thunk*
            (destroy-playlist pl)
            (destroy pl-item))))
        (t
         (destroy btn))))))

(defun create-invite-list-item (invite-list invite)
  (with-clog-create invite-list
      (list-item (:bind item)
                 (button (:bind delbtn :content "delete"))
                 (p ()
                    (span (:content "Code: "))
                    (span (:content (key invite))))
                 (p ()
                    (span (:content "Uses Remaining: "))
                    (span (:content
                           (format nil "~a"
                                   (or (uses-remaining invite) "unlimited"))))))
    (set-on-click delbtn (thunk*
                           (destroy-invite invite)
                           (destroy item))))  )

(defun create-invite-control (parent)
  (let* ((user (session-user parent))
         (container (create-div parent))
         (invite-list (create-unordered-list parent)))
    (place-after (create-section container :h3 :content "Your Invites")
                 invite-list)
    ;; list invites
    (dolist (invite (invites-by-maker user))
      (create-invite-list-item invite-list invite))

    (with-clog-create container
        (form ()
             (button (:bind createbtn :content "Create Invite"))
             (form-element (:number :bind count))
             (p (:content "Uses are optional. Blank or Zero means unlimited use.")))
      (setf (minimum count) 0
            (place-holder count) "Uses"
            (width count) 70)
      (set-on-click
       createbtn
       (thunk*
         (let ((invite (make-invite user (parse-integer (value count) :junk-allowed t))))
           (create-invite-list-item invite-list invite)))))))


(defun user-home-page (body)
  (include-style body)
  (with-clog-create body
      (div ()
           (navigation-header ())
           (div (:class "row")
                (div () 
                     (section  (:pre :content (format nil "Welcome ~a" (user-name (session-user body)))))
                     (section (:h3 :content "Your Playlists"))
                     (div (:class "row") (playlist-listing ()))
                     (new-playlist-form ())
                     (invite-control ()))))))

(defun user-key-from-url (url)
  (first (last (ppcre:split "/" (nth 4 (multiple-value-list (quri:parse-uri url)))))))

(defun user-listing-page (body)
  (when-let* ((user-id
               (user-key-from-url (url (location body))))
              (user
               (object-with-key user-id)))
    (include-style body)
    (with-clog-create body
        (div ()
             (navigation-header ())
             (div (:class "row")
                  (div ()
                       (section (:h3 :content (format nil "Playlists by ~a"
                                                      (user-name user))))
                       (div (:class "row")
                            (playlist-listing (user)))))))))