Add image support
This commit is contained in:
parent
cef1c0aca8
commit
220b861ad1
1 changed files with 29 additions and 8 deletions
|
|
@ -1,7 +1,9 @@
|
|||
(ns computersandblues.lodestone.app
|
||||
(:require [reagent.core :as r]
|
||||
[reagent.dom.client :as rd]
|
||||
[clojure.string :as str]))
|
||||
[clojure.string :as str]
|
||||
[clojure.pprint :as pprint]))
|
||||
|
||||
|
||||
(defonce state (r/atom {:root nil
|
||||
:query nil
|
||||
|
|
@ -34,9 +36,24 @@
|
|||
(swap! state assoc :query (if (str/blank? query) nil query))))
|
||||
:value (:query @state)}])
|
||||
|
||||
(defn debug [obj]
|
||||
(let [pprinted (r/atom nil)]
|
||||
(fn []
|
||||
[:details.debug {:on-toggle (fn [_]
|
||||
(when-not @pprinted
|
||||
(reset! pprinted (with-out-str (pprint/pprint obj)))))}
|
||||
[:summary "Inspect"]
|
||||
[:pre @pprinted]])))
|
||||
|
||||
(defn user [{:keys [user]}]
|
||||
(:username user))
|
||||
|
||||
(defn attachment [{:keys [attachment]}]
|
||||
(prn attachment)
|
||||
(case (:type attachment)
|
||||
"image" [:img {:src (:preview_url attachment)
|
||||
:alt (:description attachment)}]))
|
||||
|
||||
(defn post [{:keys [post]}]
|
||||
; TODO: handle (:sensitive post)
|
||||
; TODO: handle attachments
|
||||
|
|
@ -52,20 +69,24 @@
|
|||
(interleave (repeat ", "))
|
||||
(drop 1)) ")"])]
|
||||
[:div.url [:a {:href (:url post)} (:url post)]]
|
||||
[:pre (prn-str [:div.content {:dangerouslySetInnerHTML {:__html (:content post)}}])]])
|
||||
[:div.content {:dangerouslySetInnerHTML (r/unsafe-html (:content post))}]
|
||||
(when (seq (:media_attachments post))
|
||||
[:div.attachments (map-indexed (fn [idx item]
|
||||
^{:key idx} [attachment {:attachment item}])
|
||||
(:media_attachments post))])
|
||||
#_[debug post]])
|
||||
|
||||
(defn app []
|
||||
(let [favorites (:favorites @state)
|
||||
query (:query @state)
|
||||
matches? (if query
|
||||
(partial re-find (js/RegExp query "i"))
|
||||
(partial re-find (js/RegExp. query "i"))
|
||||
(constantly true))
|
||||
matches (filter (fn [post]
|
||||
(if query
|
||||
(or (matches? (:content post))
|
||||
(matches? (-> post :account :acct)) ; search for url + username of poster
|
||||
(some #(matches? (:username %)) (:mentions post))) ; search only for username of mentions
|
||||
true)) favorites)]
|
||||
(or (matches? (:content post))
|
||||
(matches? (-> post :account :acct)) ; search for url + username of poster
|
||||
(some #(matches? (:username %)) (:mentions post)))) ; search only for username of mentions
|
||||
favorites)]
|
||||
[:div#app
|
||||
[:h1 "Lodestone"]
|
||||
[:h2 "Favorites"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue