mirror of
https://github.com/edufeed-org/edufeed-web.git
synced 2025-12-10 00:34:34 +00:00
add list view for npub page
This commit is contained in:
parent
36dad21f43
commit
2f16dfa1f1
10 changed files with 1842 additions and 64 deletions
1487
resources/public/css/output.css
Normal file
1487
resources/public/css/output.css
Normal file
File diff suppressed because it is too large
Load diff
16
resources/public/index.html
Normal file
16
resources/public/index.html
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8'>
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
<link rel="stylesheet" href="/css/output.css" />
|
||||||
|
<title>ied</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>
|
||||||
|
ied is a JavaScript app. Please enable JavaScript to continue.
|
||||||
|
</noscript>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script src="/js/compiled/app.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -2,3 +2,4 @@
|
||||||
|
|
||||||
(def debug?
|
(def debug?
|
||||||
^boolean goog.DEBUG)
|
^boolean goog.DEBUG)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,5 +20,6 @@
|
||||||
(defn init []
|
(defn init []
|
||||||
(routes/start!)
|
(routes/start!)
|
||||||
(re-frame/dispatch-sync [::events/initialize-db])
|
(re-frame/dispatch-sync [::events/initialize-db])
|
||||||
|
(re-frame/dispatch [::events/connect-to-default-relays])
|
||||||
(dev-setup)
|
(dev-setup)
|
||||||
(mount-root))
|
(mount-root))
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,26 @@
|
||||||
|
|
||||||
(def default-db
|
(def default-db
|
||||||
{:name "re-frame"
|
{:name "re-frame"
|
||||||
|
:current-path nil
|
||||||
:show-add-event false
|
:show-add-event false
|
||||||
:events nil
|
:events nil
|
||||||
:pk nil
|
:pk nil
|
||||||
|
:lists nil
|
||||||
|
:default-relays [{:name "strfry-1"
|
||||||
|
:uri "http://localhost:7777"
|
||||||
|
:id (random-uuid)
|
||||||
|
:status "disconnected"}
|
||||||
|
{:name "strfry-2"
|
||||||
|
:uri "http://localhost:7778"
|
||||||
|
:id (random-uuid)
|
||||||
|
:status "disconnected"}
|
||||||
|
{:name "rust-relay"
|
||||||
|
:uri "http://localhost:4445"
|
||||||
|
:id (random-uuid)
|
||||||
|
:status "disconnected"}
|
||||||
|
; {:name "damus"
|
||||||
|
; :uri "wss://relay.damus.io"
|
||||||
|
; :status "disconnected"}
|
||||||
|
]
|
||||||
|
:selected-events nil
|
||||||
:sockets []})
|
:sockets []})
|
||||||
|
|
|
||||||
|
|
@ -25,46 +25,100 @@
|
||||||
(fn-traced [{:keys [db]} [_ active-panel]]
|
(fn-traced [{:keys [db]} [_ active-panel]]
|
||||||
{:db (assoc db :active-panel active-panel)}))
|
{:db (assoc db :active-panel active-panel)}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::set-route
|
||||||
|
(fn-traced [{:keys [db]} [_ route]]
|
||||||
|
{:db (assoc db :route route)}))
|
||||||
|
|
||||||
;; Database Event?
|
;; Database Event?
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::save-event
|
::save-event
|
||||||
;; TODO if EOSE retrieved end connection identified by uri
|
;; TODO if EOSE retrieved end connection identified by uri
|
||||||
;; TODO make events a set (?)
|
;; TODO make events a set (?)
|
||||||
(fn-traced [{:keys [db]} [_ [uri event]]]
|
(fn-traced [{:keys [db]} [_ [uri raw-event]]]
|
||||||
(println uri event)
|
(let [event (nth raw-event 2 raw-event)]
|
||||||
(when (= (first event) "EVENT")
|
(println uri raw-event event)
|
||||||
{:db (update db :events conj event)})))
|
(when (and
|
||||||
|
(= (first raw-event) "EVENT")
|
||||||
|
(not (some #(= (:id event) (:id %)) (get db :events {}))))
|
||||||
|
{:db (update db :events conj event)}))))
|
||||||
|
|
||||||
(defn handlers
|
(defn handlers
|
||||||
[ws-uri]
|
[ws-uri]
|
||||||
{:on-message (fn [e] (re-frame/dispatch [::save-event [ws-uri (-> (.-data e)
|
{:on-message (fn [e] (re-frame/dispatch [::save-event [ws-uri (-> (.-data e)
|
||||||
js/JSON.parse
|
js/JSON.parse
|
||||||
(js->clj :keywordize-keys true))]]))
|
(js->clj :keywordize-keys true))]]))
|
||||||
:on-open #(prn "Opening a new connection")
|
; :on-open #(prn "Opening a new connection")
|
||||||
:on-close #(prn "Closing a connection")})
|
:on-open #(re-frame/dispatch [::load-events ws-uri])
|
||||||
|
:on-close #(prn "Closing a connection")
|
||||||
|
:on-error (fn [e] (.log js/console "Error with uri: " ws-uri (clj->js e))
|
||||||
|
(re-frame/dispatch [::update-ws-connection-status ws-uri "error"]))})
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::update-ws-connection-status
|
||||||
|
(fn [db [_ ws-uri status]]
|
||||||
|
(let [target-ws (first (filter #(= ws-uri (:uri %)) (:sockets db)))]
|
||||||
|
(assoc db
|
||||||
|
:sockets
|
||||||
|
(assoc (:sockets db)
|
||||||
|
(.indexOf (:sockets db) target-ws)
|
||||||
|
(merge target-ws {:status status}))))))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::load-events
|
||||||
|
(fn-traced [cofx [_ ws-uri]]
|
||||||
|
{::load-events-fx ws-uri}))
|
||||||
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
::load-events-fx
|
||||||
|
(fn [ws-uri]
|
||||||
|
(println "loading events")
|
||||||
|
|
||||||
|
(let [sockets (re-frame/subscribe [::subs/sockets])
|
||||||
|
target-ws (first (filter #(= ws-uri (:uri %)) @sockets))]
|
||||||
|
(ws/send (:socket target-ws) ["REQ" "4242" {:kinds [1 30142]
|
||||||
|
:limit 10}] fmt/json)
|
||||||
|
; (ws/close (:socket (first @sockets))) ;; should be handled otherwise (?)
|
||||||
|
)))
|
||||||
|
|
||||||
(defn create-socket
|
(defn create-socket
|
||||||
[uri]
|
[uri]
|
||||||
|
(println "creating socket with uri" uri)
|
||||||
(ws/create uri (handlers uri)))
|
(ws/create uri (handlers uri)))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::create-websocket
|
::create-websocket
|
||||||
|
;; ws {:id uuid
|
||||||
|
;; :uri
|
||||||
|
;; :name
|
||||||
|
;; :status connected | disconnected | error}
|
||||||
(fn-traced [{:keys [db]} [_ ws]]
|
(fn-traced [{:keys [db]} [_ ws]]
|
||||||
{:db (update db :sockets conj (merge ws {:socket (create-socket (:uri ws))}))}))
|
(if (some #(= (:uri ws) (:uri %)) (:sockets db))
|
||||||
|
(doall
|
||||||
|
(println "uri already there" (:uri ws))
|
||||||
|
{:db (assoc db
|
||||||
|
:sockets
|
||||||
|
(assoc (:sockets db)
|
||||||
|
(.indexOf (:sockets db) ws)
|
||||||
|
(merge ws {:socket (create-socket (:uri ws))
|
||||||
|
:status "connected"})))})
|
||||||
|
(doall
|
||||||
|
(println "uri not yet known")
|
||||||
|
{:db (update db :sockets conj (merge ws {:socket (create-socket (:uri ws))
|
||||||
|
:status "connected"}))}))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::connect-to-websocket
|
::connect-to-websocket
|
||||||
(fn-traced [{:keys [db]} [_ _]]
|
(fn-traced [{:keys [db]} [_ ws-uri]]
|
||||||
{::connect-to-websocket-fx _})) ;; TODO identify the socket to connect to
|
{::connect-to-websocket-fx ws-uri}))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::connect-to-websocket-fx
|
::connect-to-websocket-fx
|
||||||
(fn [_]
|
(fn [ws-uri]
|
||||||
(let [sockets (re-frame/subscribe [::subs/sockets])]
|
(let [sockets (re-frame/subscribe [::subs/sockets])
|
||||||
(println "Sockets: " @sockets)
|
target-ws (first (filter #(= ws-uri (:uri %)) @sockets))]
|
||||||
(ws/send (:socket (first @sockets)) ["REQ" "4242" {:kinds [1 30142]
|
(re-frame/dispatch [::create-websocket target-ws])
|
||||||
:limit 10}] fmt/json)
|
; (ws/create (:uri target-ws) (handlers (:uri target-ws)))
|
||||||
; (ws/close (:socket (first @sockets))) ;; should be handled otherwise (?)
|
|
||||||
)))
|
)))
|
||||||
|
|
||||||
;; TODO use id to close socket
|
;; TODO use id to close socket
|
||||||
|
|
@ -72,27 +126,44 @@
|
||||||
;; render connect / disconnect button based on status
|
;; render connect / disconnect button based on status
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::close-connection-to-websocket
|
::close-connection-to-websocket
|
||||||
(fn-traced [{:keys [db]} [_ _]]
|
(fn-traced [{:keys [db]} [_ ws-uri]]
|
||||||
{::close-connection-to-websocket-fx _}))
|
{::close-connection-to-websocket-fx ws-uri}))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::close-connection-to-websocket-fx
|
::close-connection-to-websocket-fx
|
||||||
(fn [_]
|
(fn [ws-uri]
|
||||||
(let [sockets (re-frame/subscribe [::subs/sockets])]
|
(let [sockets (re-frame/subscribe [::subs/sockets])]
|
||||||
(ws/close (:socket (first @sockets))))))
|
(ws/close (:socket (first (filter #(= ws-uri (:uri %)) @sockets))))
|
||||||
|
(re-frame/dispatch [::update-ws-connection-status ws-uri "disconnected"]))))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::connect-to-default-relays
|
||||||
|
(fn-traced [cofx [_]]
|
||||||
|
(let [default-relays (re-frame/subscribe [::subs/default-relays])]
|
||||||
|
{::connect-to-default-relays-fx @default-relays})))
|
||||||
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
::connect-to-default-relays-fx
|
||||||
|
(fn [default-relays]
|
||||||
|
(doall
|
||||||
|
(for [r default-relays]
|
||||||
|
(re-frame/dispatch [::create-websocket r])))))
|
||||||
|
|
||||||
;; TODO
|
;; TODO
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::send-to-relays
|
::send-to-relays
|
||||||
(fn-traced [cofx [_ signedEvent]]
|
(fn-traced [cofx [_ signedEvent]]
|
||||||
{::send-to-relays-fx signedEvent}))
|
(let [sockets (-> cofx :db :sockets)]
|
||||||
|
{::send-to-relays-fx [sockets signedEvent]})))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::send-to-relays-fx
|
::send-to-relays-fx
|
||||||
(fn [signedEvent]
|
(fn [[sockets signedEvent]]
|
||||||
(let [sockets (re-frame/subscribe [::subs/sockets])]
|
(println "got relays" sockets)
|
||||||
(.log js/console (clj->js ["EVENT" signedEvent]))
|
(let [connected-sockets (filter #(= "connected" (:status %)) sockets)]
|
||||||
(ws/send (:socket (first @sockets)) ["EVENT" signedEvent] fmt/json))))
|
(doseq [socket connected-sockets]
|
||||||
|
(.log js/console "sending to relay")
|
||||||
|
(ws/send (:socket socket) ["EVENT" signedEvent] fmt/json)))))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::update-websockets
|
::update-websockets
|
||||||
|
|
@ -116,6 +187,7 @@
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(assoc db :show-add-event (not (:show-add-event db)))))
|
(assoc db :show-add-event (not (:show-add-event db)))))
|
||||||
|
|
||||||
|
;; TODO just pass an event here that is then passed on to signing
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::publish-resource
|
::publish-resource
|
||||||
[(re-frame/inject-cofx :now)]
|
[(re-frame/inject-cofx :now)]
|
||||||
|
|
@ -123,15 +195,15 @@
|
||||||
(let [event {:kind 30142
|
(let [event {:kind 30142
|
||||||
:created_at (:now cofx)
|
:created_at (:now cofx)
|
||||||
:content "hello world"
|
:content "hello world"
|
||||||
::tags []
|
:tags [["author" "" (:author resource)]]}]
|
||||||
;;:tags [["author" "" (:author resource)]]
|
|
||||||
}]
|
|
||||||
{::publish-resource-fx event})))
|
{::publish-resource-fx event})))
|
||||||
|
|
||||||
|
;; TODO maybe we need some validation before publishing
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::publish-resource-fx
|
::publish-resource-fx
|
||||||
(fn [resource]
|
(fn [unsignedEvent]
|
||||||
(p/let [signedEvent (.nostr.signEvent js/window (clj->js resource))]
|
(p/let [_ (js/console.log (clj->js unsignedEvent))
|
||||||
|
signedEvent (.nostr.signEvent js/window (clj->js unsignedEvent))]
|
||||||
(re-frame/dispatch [::send-to-relays signedEvent]))))
|
(re-frame/dispatch [::send-to-relays signedEvent]))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
|
|
@ -160,5 +232,69 @@
|
||||||
(fn [cofx _data] ;; _data unused
|
(fn [cofx _data] ;; _data unused
|
||||||
(assoc cofx :now (quot (.now js/Date) 1000))))
|
(assoc cofx :now (quot (.now js/Date) 1000))))
|
||||||
|
|
||||||
(comment
|
(defn convert-amb-to-nostr-event
|
||||||
(quot (.now js/Date) 1000))
|
[json-string created_at]
|
||||||
|
(let [parsed-json (js->clj (js/JSON.parse json-string) :keywordize-keys true)
|
||||||
|
tags (into [["id" (:id parsed-json)]
|
||||||
|
["name" (:name parsed-json)]
|
||||||
|
["image" (:image parsed-json)]]
|
||||||
|
cat [(map (fn [e] ["about" (:id e) (-> e :prefLabel :de)]) (:about parsed-json))
|
||||||
|
(map (fn [e] ["inLanguage" e]) (:inLanguage parsed-json))])
|
||||||
|
event {:kind 30142
|
||||||
|
:created_at created_at
|
||||||
|
:content "Added AMB Resource"
|
||||||
|
:tags tags}]
|
||||||
|
event))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::convert-amb-and-publish-as-nostr-event
|
||||||
|
[(re-frame/inject-cofx :now)]
|
||||||
|
(fn-traced [cofx [_ json-string]]
|
||||||
|
(let [event (convert-amb-to-nostr-event json-string (:now cofx))]
|
||||||
|
{::publish-resource-fx event})))
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::toggle-selected-events
|
||||||
|
(fn [db [_ event]]
|
||||||
|
(js/console.log "toggling selected event with id" (:id event))
|
||||||
|
(if (some #(= event (:id %)) (:selected-events db))
|
||||||
|
(assoc db :selected-events (filter #(not= event (:id %)) (:selected-events db)))
|
||||||
|
(update db :selected-events conj event))))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::add-resources-to-list
|
||||||
|
[(re-frame/inject-cofx :now)]
|
||||||
|
(fn [cofx [_ [list resources-to-add]]]
|
||||||
|
(let [tags (into [["d" (:d list)
|
||||||
|
"name" (:name list)]]
|
||||||
|
(map (fn [e] (cond
|
||||||
|
(= 1 (:kind e)) ["e" (:id e)]
|
||||||
|
(= 30142 (:kind e)) ["a" (str "30142:" (:id e))]))
|
||||||
|
|
||||||
|
resources-to-add))
|
||||||
|
_ (.log js/console (clj->js tags))
|
||||||
|
event {:kind 30004
|
||||||
|
:created_at (:now cofx)
|
||||||
|
:content ""
|
||||||
|
:tags tags}]
|
||||||
|
{::publish-resource-fx event})))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::get-lists-for-npub
|
||||||
|
(fn [cofx [_ npub]]
|
||||||
|
(let [query-for-lists ["REQ"
|
||||||
|
(str "lists-for-npub") ;; TODO maybe make this more explicit later
|
||||||
|
{:authors [(nostr/get-pk-from-npub npub)]
|
||||||
|
:kinds [30004]}]]
|
||||||
|
{::request-from-relay query-for-lists})))
|
||||||
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
::request-from-relay
|
||||||
|
(fn [query]
|
||||||
|
(println "requesting from relay this query: " query)
|
||||||
|
|
||||||
|
(let [sockets @(re-frame/subscribe [::subs/sockets])]
|
||||||
|
(doall
|
||||||
|
(for [s (filter (fn [s] (= "connected" (:status s))) sockets)]
|
||||||
|
(ws/send (:socket s) query fmt/json))))))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
(ns ied.nostr
|
(ns ied.nostr
|
||||||
(:require
|
(:require
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
||||||
["@noble/secp256k1" :as secp]))
|
["@noble/secp256k1" :as secp]
|
||||||
|
["nostr-tools/nip19" :as nip19]))
|
||||||
|
|
||||||
(defn event-to-serialized-json [m]
|
(defn event-to-serialized-json [m]
|
||||||
(let [event [0
|
(let [event [0
|
||||||
|
|
@ -50,3 +51,17 @@
|
||||||
(println serialized-event)
|
(println serialized-event)
|
||||||
(println id)))
|
(println id)))
|
||||||
|
|
||||||
|
(defn string-to-uint8array [s]
|
||||||
|
(let [encoder (new js/TextEncoder)]
|
||||||
|
(.encode encoder s)))
|
||||||
|
|
||||||
|
(defn get-npub-from-pk [pk]
|
||||||
|
(.npubEncode nip19 pk))
|
||||||
|
|
||||||
|
(defn get-pk-from-npub [npub]
|
||||||
|
(.decode nip19 npub))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(get-npub-from-pk "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d")
|
||||||
|
(get-pk-from-npub "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6" )
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,16 @@
|
||||||
|
|
||||||
(def routes
|
(def routes
|
||||||
(atom
|
(atom
|
||||||
["/" {"" :home
|
["/"
|
||||||
"about" :about
|
{"" :home
|
||||||
"settings" :settings}]))
|
"add-resource" :add-resource
|
||||||
|
"about" :about
|
||||||
|
"settings" :settings
|
||||||
|
["" [#"npub1[ac-hj-np-z02-9]{58}" :npub]] {"" :npub-view
|
||||||
|
"/" :npub-view}}]))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(parse "/npub1r30l8j4vmppvq8w23umcyvd3vct4zmfpfkn4c7h2h057rmlfcrmq9xt9ma/"))
|
||||||
|
|
||||||
(defn parse
|
(defn parse
|
||||||
[url]
|
[url]
|
||||||
|
|
@ -25,7 +32,7 @@
|
||||||
(defn dispatch
|
(defn dispatch
|
||||||
[route]
|
[route]
|
||||||
(let [panel (keyword (str (name (:handler route)) "-panel"))]
|
(let [panel (keyword (str (name (:handler route)) "-panel"))]
|
||||||
(re-frame/dispatch [::events/set-active-panel panel])))
|
(re-frame/dispatch [::events/set-route {:route route :panel panel}])))
|
||||||
|
|
||||||
(defonce history
|
(defonce history
|
||||||
(pushy/pushy dispatch parse))
|
(pushy/pushy dispatch parse))
|
||||||
|
|
@ -42,3 +49,4 @@
|
||||||
:navigate
|
:navigate
|
||||||
(fn [handler]
|
(fn [handler]
|
||||||
(navigate! handler)))
|
(navigate! handler)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,24 +10,50 @@
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::active-panel
|
::active-panel
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(:active-panel db)))
|
(get-in db [:route :panel])))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::sockets
|
::sockets
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(:sockets db)))
|
(:sockets db)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::events
|
::connected-sockets
|
||||||
(fn [db _]
|
:<- [::sockets]
|
||||||
(:events db)))
|
(fn [[sockets]]
|
||||||
|
(filter #(= (:status %) "connected") sockets)))
|
||||||
(re-frame/reg-sub
|
|
||||||
::show-add-event
|
|
||||||
(fn [db _]
|
|
||||||
(:show-add-event db)))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::pk
|
::events
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(:pk db)))
|
(:events db)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::show-add-event
|
||||||
|
(fn [db _]
|
||||||
|
(:show-add-event db)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::pk
|
||||||
|
(fn [db _]
|
||||||
|
(:pk db)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::default-relays
|
||||||
|
(fn [db _]
|
||||||
|
(:default-relays db)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::selected-events
|
||||||
|
(fn [db _]
|
||||||
|
(:selected-events db)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::route-params
|
||||||
|
(fn [db _]
|
||||||
|
(get-in db [:route :route :route-params])))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::lists
|
||||||
|
(fn [db _]
|
||||||
|
(filter #(= 30004 (:kind %)) (:events db))))
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
[ied.events :as events]
|
[ied.events :as events]
|
||||||
[ied.routes :as routes]
|
[ied.routes :as routes]
|
||||||
[ied.subs :as subs]
|
[ied.subs :as subs]
|
||||||
|
["react" :as react]
|
||||||
[reagent.core :as reagent]))
|
[reagent.core :as reagent]))
|
||||||
|
|
||||||
;; add resource form
|
;; add resource form
|
||||||
|
|
@ -33,16 +33,27 @@
|
||||||
:value (:author @s)
|
:value (:author @s)
|
||||||
:on-change (fn [e]
|
:on-change (fn [e]
|
||||||
(swap! s assoc :author (-> e .-target .-value)))}]
|
(swap! s assoc :author (-> e .-target .-value)))}]
|
||||||
[:button {:on-click #(re-frame/dispatch [::events/publish-resource {:name (:name @s)
|
[:button {:on-click #(re-frame/dispatch [::events/publish-resource {:name (:name @s) ;; TODO this should be sth like build event
|
||||||
:uri (:uri @s)
|
:uri (:uri @s)
|
||||||
:author (:author @s)}])}
|
:author (:author @s)}])}
|
||||||
"Publish Resource"]])))
|
"Publish Resource"]])))
|
||||||
|
|
||||||
|
(defn add-resource-by-json []
|
||||||
|
(let [s (reagent/atom {:json-string ""})]
|
||||||
|
(fn []
|
||||||
|
[:form {:on-submit (fn [e] (.preventDefault e))}
|
||||||
|
[:textarea {:on-change (fn [e]
|
||||||
|
(swap! s assoc :json-string (-> e .-target .-value)))}]
|
||||||
|
[:button {:class "btn btn-warning"
|
||||||
|
:on-click #(re-frame/dispatch [::events/convert-amb-and-publish-as-nostr-event (:json-string @s)])}
|
||||||
|
"Publish as Nostr Event"]])))
|
||||||
|
|
||||||
;; events
|
;; events
|
||||||
(defn events-panel []
|
(defn events-panel []
|
||||||
(let [events (re-frame/subscribe [::subs/events])
|
(let [events (re-frame/subscribe [::subs/events])
|
||||||
|
selected-events @(re-frame/subscribe [::subs/selected-events])
|
||||||
show-add-event (re-frame/subscribe [::subs/show-add-event])]
|
show-add-event (re-frame/subscribe [::subs/show-add-event])]
|
||||||
[:div
|
[:div {:class "border-2 rounded"}
|
||||||
[:p {:on-click #(re-frame/dispatch [::events/toggle-show-add-event])}
|
[:p {:on-click #(re-frame/dispatch [::events/toggle-show-add-event])}
|
||||||
(if @show-add-event "X" "Add Resource!")]
|
(if @show-add-event "X" "Add Resource!")]
|
||||||
(when @show-add-event
|
(when @show-add-event
|
||||||
|
|
@ -51,10 +62,16 @@
|
||||||
(if (> (count @events) 0)
|
(if (> (count @events) 0)
|
||||||
(doall
|
(doall
|
||||||
(for [event @events]
|
(for [event @events]
|
||||||
; [:li (:content (nth event 2 {:content "hello"}))]
|
[:li {:key (:id event)} (get event :content "")
|
||||||
[:li {:key (:id event)} (get (nth event 2) :content "")]
|
[:input {:type "checkbox"
|
||||||
))
|
:on-click #(re-frame/dispatch [::events/toggle-selected-events event])}]]))
|
||||||
[:p "no events there"])]))
|
[:p "no events there"])
|
||||||
|
[:button {:class "btn"
|
||||||
|
:disabled (not (boolean (seq selected-events)))
|
||||||
|
:on-click #(re-frame/dispatch [::events/add-resources-to-list [{:d "unique-id-1"
|
||||||
|
:name "Test List SC"}
|
||||||
|
selected-events]])}
|
||||||
|
"Add To Lists"]]))
|
||||||
|
|
||||||
;; relays
|
;; relays
|
||||||
(defn add-relay-form
|
(defn add-relay-form
|
||||||
|
|
@ -88,15 +105,27 @@
|
||||||
[:div
|
[:div
|
||||||
[add-relay-form]
|
[add-relay-form]
|
||||||
|
|
||||||
(when (> (count @sockets) 0)
|
(if (> (count @sockets) 0)
|
||||||
[:ul
|
[:ul
|
||||||
(doall
|
(doall
|
||||||
(for [socket @sockets]
|
(for [socket @sockets]
|
||||||
[:li {:key (:id socket)}
|
[:li {:key (:id socket)}
|
||||||
[:span (:name socket)]
|
[:span (:name socket)]
|
||||||
[:button {:on-click #(re-frame/dispatch [::events/connect-to-websocket])} "Load events"]
|
[:span (:status socket)]
|
||||||
[:button {:on-click #(re-frame/dispatch [::events/close-connection-to-websocket])} "Disconnect"]
|
[:button {:class "btn"
|
||||||
[:button {:on-click #(re-frame/dispatch [::events/remove-websocket socket])} "Remove relay"]]))])]))
|
:disabled (not= "connected" (:status socket))
|
||||||
|
:on-click #(re-frame/dispatch [::events/load-events (:uri socket)])} "Load events"]
|
||||||
|
(if (not= (:status socket) "connected")
|
||||||
|
[:button {:class "btn"
|
||||||
|
:on-click #(re-frame/dispatch [::events/connect-to-websocket (:uri socket)])} "Connect"]
|
||||||
|
[:button {:class "btn"
|
||||||
|
:on-click #(re-frame/dispatch [::events/close-connection-to-websocket (:uri socket)])} "Disconnect"])
|
||||||
|
|
||||||
|
[:button {:class "btn btn-error"
|
||||||
|
:on-click #(re-frame/dispatch [::events/remove-websocket socket])} "Remove relay"]]))]
|
||||||
|
[:p "No relays found"]
|
||||||
|
;(re-frame/dispatch [::events/connect-to-default-relays])
|
||||||
|
)]))
|
||||||
|
|
||||||
;; Header
|
;; Header
|
||||||
|
|
||||||
|
|
@ -106,6 +135,9 @@
|
||||||
[:a {:on-click #(re-frame/dispatch [::events/navigate :home])}
|
[:a {:on-click #(re-frame/dispatch [::events/navigate :home])}
|
||||||
"home"]
|
"home"]
|
||||||
"|"
|
"|"
|
||||||
|
[:a {:on-click #(re-frame/dispatch [::events/navigate :add-resource])}
|
||||||
|
"add resource"]
|
||||||
|
"|"
|
||||||
[:a {:on-click #(re-frame/dispatch [::events/navigate :about])}
|
[:a {:on-click #(re-frame/dispatch [::events/navigate :about])}
|
||||||
"about"]
|
"about"]
|
||||||
"|"
|
"|"
|
||||||
|
|
@ -116,6 +148,16 @@
|
||||||
[:a {:on-click #(re-frame/dispatch [::events/logout])} "logout"]
|
[:a {:on-click #(re-frame/dispatch [::events/logout])} "logout"]
|
||||||
[:a {:on-click #(re-frame/dispatch [::events/login-with-extension])} "login"])]))
|
[:a {:on-click #(re-frame/dispatch [::events/login-with-extension])} "login"])]))
|
||||||
|
|
||||||
|
;; Add Resource Panel
|
||||||
|
|
||||||
|
(defn add-resource-panel []
|
||||||
|
[:div
|
||||||
|
[:h1 "Add Resource"]
|
||||||
|
[add-resource-form]
|
||||||
|
[add-resource-by-json]])
|
||||||
|
|
||||||
|
(defmethod routes/panels :add-resource-panel [] [add-resource-panel])
|
||||||
|
|
||||||
;; Settings
|
;; Settings
|
||||||
(defn settings-panel []
|
(defn settings-panel []
|
||||||
[:div
|
[:div
|
||||||
|
|
@ -141,19 +183,46 @@
|
||||||
(defn about-panel []
|
(defn about-panel []
|
||||||
[:div
|
[:div
|
||||||
[:h1 "This is the About Page."]
|
[:h1 "This is the About Page."]
|
||||||
|
|
||||||
[:div
|
[:div
|
||||||
[:a {:on-click #(re-frame/dispatch [::events/navigate :home])}
|
[:a {:on-click #(re-frame/dispatch [::events/navigate :home])}
|
||||||
"go to Home Page"]]])
|
"go to Home Page"]]])
|
||||||
|
|
||||||
(defmethod routes/panels :about-panel [] [about-panel])
|
(defmethod routes/panels :about-panel [] [about-panel])
|
||||||
|
|
||||||
|
;; npub
|
||||||
|
(defn npub-view-panel []
|
||||||
|
(let [route-params @(re-frame/subscribe [::subs/route-params])
|
||||||
|
lists @(re-frame/subscribe [::subs/lists])]
|
||||||
|
[:div
|
||||||
|
[:h1 (str "Hello Npub: " (:npub route-params))]
|
||||||
|
(if (nil? lists)
|
||||||
|
[:button {:class "btn"
|
||||||
|
:on-click
|
||||||
|
#(re-frame/dispatch [::events/get-lists-for-npub (:npub route-params)])} "Load lists"]
|
||||||
|
[:div "Got some lists"
|
||||||
|
(doall
|
||||||
|
(for [l lists]
|
||||||
|
[:div {:key (:id l)}
|
||||||
|
[:li
|
||||||
|
|
||||||
|
[:p (str "ID: " (:id l))]
|
||||||
|
[:p (str "Name: " (first (filter #(= "d" (first %)) (:tags l))))]
|
||||||
|
;; TODO filter tags for already being in events
|
||||||
|
;; for all that are not send a query
|
||||||
|
[:p (str "Tags: " (:tags l))]]]))])
|
||||||
|
[:button {:class "btn"
|
||||||
|
:on-click
|
||||||
|
#(re-frame/dispatch [::events/get-lists-for-npub (:npub route-params)])} "Load lists"]]))
|
||||||
|
|
||||||
|
(defmethod routes/panels :npub-view-panel [] [npub-view-panel])
|
||||||
|
|
||||||
;; main
|
;; main
|
||||||
(defn main-panel []
|
(defn main-panel []
|
||||||
(let [active-panel (re-frame/subscribe [::subs/active-panel])]
|
(let [active-panel (re-frame/subscribe [::subs/active-panel])]
|
||||||
[:div
|
[:div
|
||||||
[header]
|
[header]
|
||||||
(routes/panels @active-panel)]))
|
[:div
|
||||||
|
(routes/panels @active-panel)]]))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue