 
 
 
+
+(defn init-issuer-connection [issuer-id state]
+  (ajax/GET
+    (path-for (str "/obpv1/social/issuer_connected/" issuer-id))
+    {:handler (fn [data]
+                (swap! state assoc :connected data)
+                )}))
+
 (defn init-issuer-content [state issuer-id]
   (ajax/GET
     (path-for (str "/obpv1/badge/issuer/" issuer-id))
-    {:handler (fn [data] (reset! state data))}))
+    {:handler (fn [data]
+                (reset! state data)
+                (init-issuer-connection issuer-id state))
+     }))
 
 (defn init-creator-content [state creator-id]
   (ajax/GET
     (path-for (str "/obpv1/badge/creator/" creator-id))
     {:handler (fn [data]
-                (prn data)
                 (reset! state data))}))
+
+(defn add-issuer-to-favourites [issuer-id state]
+  (ajax/POST
+    (path-for (str "/obpv1/social/create_connection_issuer/" issuer-id))
+    {:handler (fn []
+                (init-issuer-connection issuer-id state))}))
+
+
+(defn remove-issuer-from-favourites [issuer-id state]
+  (ajax/POST
+    (path-for (str "/obpv1/social/delete_connection_issuer/" issuer-id))
+    {:handler (fn []
+                (init-issuer-connection issuer-id state))}))
 
 (defn- issuer-image [path]
   (when (not-empty path)

      :style {:width "50px"}}]))

(defn content [issuer-id]
  (let [state (atom {:issuer nil :endorsement []})]
    (init-issuer-content state issuer-id)
    (fn []
      (let [{:keys [name description email url image_file]} @state]
        [:div.row {:id "badge-contents"}
         [:div.col-xs-12
          [:h2.uppercase-header
           (issuer-image image_file)
           " "

(ns salava.badge.ui.issuer
  (:require [reagent.core :refer [atom cursor]]
            [salava.core.i18n :refer [t]]
            [salava.core.ui.ajax-utils :as ajax]
            [salava.core.ui.helper :refer [path-for private?]]
