             "Sign up"]]]]))))
 
 (defn events-page []
-  (let [leave-event (fn [attendee-id]
-                      ; TODO: this doesn't delete schedules
-                      (attendees-endpoint :delete
-                                          (d/entity @attendees-db attendee-id)
-                                          nil))]
-    (fn []
-      (if (:token @session)
-        (let [attending-events
-              (doall (map (fn [[event-id attendee-id]]
-                            (assoc
-                              (into {} (d/entity @events-db event-id))
-                              :AttendeeId attendee-id))
-                          (d/q '[:find ?event-id ?attendee-id
-                                 :in $ ?user-id
-                                 :where
-                                 [?attendee-id :UserId  ?user-id]
-                                 [?attendee-id :EventId ?event-id]]
-                               @attendees-db
-                               (get-in @session [:user :UserId]))))]
-          [:div.sixteen.wide.column
-           [:div.ui.top.attached.tabular.menu
-            [:a.active.item {:href (events-route)}
-             "Events"]
-            [:a.item {:href (events-explore-route)}
-             "Explore"]
-            [:a.item {:href (events-owned-route)}
-             "Owned"]
-            [:a.item {:href (event-add-route)}
-             "Add"]]
-           [:div.ui.bottom.attached.segment
-            [:div
-             [:div.ui.vertical.segment
-              [:h1.ui.header "Events You're Attending"]]
-             [:div.ui.vertical.segment
-              (if (seq attending-events)
-                [:div.ui.divided.items
-                 (for [event attending-events]
-                   ^{:key (:EventId event)}
-                   [:div.item
-                    [:div.content
-                     [:a.header {:href (event-route event)}
-                      (:Name event)]
-                     [:div.meta
-                      [:strong "Date:"]
-                      (let [start (from-string (:StartDate event))
-                            end   (from-string (:EndDate   event))]
-                        (str (unparse datetime-formatter start)
-                             (when (after? end start)
-                               (str " to " (unparse datetime-formatter end)))))]
-                     [:div.meta
-                      [:strong "Venue:"]
-                      (:Venue event)]
-                     [:div.description
-                      (:Description event)]
-                     [:div.extra
-                      [:a.ui.right.floated.small.button
-                       {:href (event-schedule-route event)}
-                       "Your activities"
-                       [:i.right.chevron.icon]]
-                      [:a.ui.right.floated.small.button
-                       {:on-click #(leave-event (:AttendeeId event))}
-                       [:i.red.remove.icon]
-                       "Leave event"]]]])]
-                [:p "You aren't attending any events."])]]
-            [:div.ui.dimmer {:class (when (empty? @events) :active)}
-             [:div.ui.loader]]]])
-        (do
-          (js/location.replace (events-explore-route))
-          [:div])))))
+  (fn []
+    (if (:token @session)
+      (let [attending-events
+            (doall (map (fn [[event-id attendee-id]]
+                          (merge
+                            (into {} (d/entity @events-db event-id))
+                            {:AttendeeId attendee-id}))
+                        (d/q '[:find ?event-id ?attendee-id
+                               :in $ ?user-id
+                               :where
+                               [?attendee-id :UserId  ?user-id]
+                               [?attendee-id :EventId ?event-id]]
+                             @attendees-db
+                             (get-in @session [:user :UserId]))))]
+        [:div.sixteen.wide.column
+         [:div.ui.top.attached.tabular.menu
+          [:a.active.item {:href (events-route)}
+           "Events"]
+          [:a.item {:href (events-explore-route)}
+           "Explore"]
+          [:a.item {:href (events-owned-route)}
+           "Owned"]
+          [:a.item {:href (event-add-route)}
+           "Add"]]
+         [:div.ui.bottom.attached.segment
+          [:div
+           [:div.ui.vertical.segment
+            [:h1.ui.header "Events You're Attending"]]
+           [:div.ui.vertical.segment
+            (if (seq attending-events)
+              [:div.ui.divided.items
+               (for [event attending-events]
+                 ^{:key (:EventId event)}
+                 [:div.item
+                  [:div.content
+                   [:a.header {:href (event-route event)}
+                    (:Name event)]
+                   [:div.meta
+                    [event-details-component event]
+                   [:div.extra
+                    [:a.ui.right.floated.small.button {:href (event-schedule-route event)}
+                     "Your activities"
+                     [:i.right.chevron.icon]]]]]])]
+              [:p "You aren't attending any events."])]]
+          [:div.ui.dimmer {:class (when (empty? @events) "active")}
+           [:div.ui.loader]]]])
+      (do
+        (js/location.replace (events-explore-route))
+        [:div]))))
 
 (defn events-explore-page []
   (let [unattending-events

                                           [?a :EventId ?event-id]
                                           [?a :UserId ?e]]
                                         @attendees-db
                                         event-id))))]
    (when (seq event)
      [:div.sixteen.wide.column
       [:div.ui.segment
        [:div.ui.vertical.segment
         [:h1.ui.dividing.header
          (:Name event)]
         [:div.ui.right.floated.small.labeled.icon.button
          [:i.edit.icon]
          "Edit"]
         [:div
          [:b "Date: "]
          (when (and (:StartDate event)
                     (:EndDate event))
            (let [start (from-string (:StartDate event))
                  end   (from-string (:EndDate   event))]
              (str (unparse datetime-formatter start)
                   (when (after? end start)
                     (str " to "
                          (unparse datetime-formatter end))))))]
         [:div
          [:b "Venue: "] (:Venue event)]
         [:p (:Description event)]]
        (when-let [attendee-id (first (d/q '[:find [?attendee-id ...]
                                             :in $ ?event-id ?user-id
                                             :where
                                             [?attendee-id :EventId ?event-id]
                                             [?attendee-id :UserId ?user-id]]
                                           @attendees-db
                                           event-id
                                           (:UserId (:user @session))))]
          [:div.ui.vertical.segment
           [:h2 "QR-Code"]
           [qr-code
            {:text (event-attendee-route (into {} (d/entity @attendees-db
                                                            attendee-id)))}]])
        [:div.ui.vertical.segment
         [:h2.ui.header
          "Activities"]
         [activity-table-component event-id]]
        [:div.ui.vertical.segment
         [:h2.ui.header
          "Attendees"
          [:a.ui.right.floated.small.button
           {:href (event-attendees-route event)}
           "View"]]
         [:table.ui.table
          [:thead
           [:tr
            [:th "Name"]
            [:th]]]
          [:tbody
           (for [attendee attendees]
             ^{:key (:AttendeeId attendee)}
             [:tr
              [:td (str (:FirstName attendee) " " (:LastName attendee))]
              [:td [:a.ui.right.floated.small.labeled.button
                    {:href (event-attendee-route
                             {:EventId (:EventId event)
                              :AttendeeId (:AttendeeId attendee)})
                     :class (when (:CheckinTime attendee) :green)}
                    (if (:CheckinTime attendee)
                      "Checked in"
                      "Check in")]]])]
          [:tfoot
           [:tr
            [:th {:colSpan "4"}
             [:div.ui.right.floated.small.labeled.icon.button
              [:i.edit.icon]
              "Edit"]]]]]]]])))

(defn event-edit-page []
  (let [form (atom {})

          [:div.sixteen.wide.column
           [:div.ui.segment
            [:div.ui.vertical.segment
             [:h2.ui.dividing.header
              (:Name event)]
             [event-details-component event]]
            [:div.ui.vertical.segment
             [:h2.ui.header
              (if activity-id "Edit" "Add") " activity"]
