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
|
(ns computersandblues.lodestone.app
|
||||||
(:require [reagent.core :as r]
|
(:require [reagent.core :as r]
|
||||||
[reagent.dom.client :as rd]
|
[reagent.dom.client :as rd]
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]
|
||||||
|
[clojure.pprint :as pprint]))
|
||||||
|
|
||||||
|
|
||||||
(defonce state (r/atom {:root nil
|
(defonce state (r/atom {:root nil
|
||||||
:query nil
|
:query nil
|
||||||
|
|
@ -34,9 +36,24 @@
|
||||||
(swap! state assoc :query (if (str/blank? query) nil query))))
|
(swap! state assoc :query (if (str/blank? query) nil query))))
|
||||||
:value (:query @state)}])
|
: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]}]
|
(defn user [{:keys [user]}]
|
||||||
(:username 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]}]
|
(defn post [{:keys [post]}]
|
||||||
; TODO: handle (:sensitive post)
|
; TODO: handle (:sensitive post)
|
||||||
; TODO: handle attachments
|
; TODO: handle attachments
|
||||||
|
|
@ -52,20 +69,24 @@
|
||||||
(interleave (repeat ", "))
|
(interleave (repeat ", "))
|
||||||
(drop 1)) ")"])]
|
(drop 1)) ")"])]
|
||||||
[:div.url [:a {:href (:url post)} (:url post)]]
|
[: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 []
|
(defn app []
|
||||||
(let [favorites (:favorites @state)
|
(let [favorites (:favorites @state)
|
||||||
query (:query @state)
|
query (:query @state)
|
||||||
matches? (if query
|
matches? (if query
|
||||||
(partial re-find (js/RegExp query "i"))
|
(partial re-find (js/RegExp. query "i"))
|
||||||
(constantly true))
|
(constantly true))
|
||||||
matches (filter (fn [post]
|
matches (filter (fn [post]
|
||||||
(if query
|
(or (matches? (:content post))
|
||||||
(or (matches? (:content post))
|
(matches? (-> post :account :acct)) ; search for url + username of poster
|
||||||
(matches? (-> post :account :acct)) ; search for url + username of poster
|
(some #(matches? (:username %)) (:mentions post)))) ; search only for username of mentions
|
||||||
(some #(matches? (:username %)) (:mentions post))) ; search only for username of mentions
|
favorites)]
|
||||||
true)) favorites)]
|
|
||||||
[:div#app
|
[:div#app
|
||||||
[:h1 "Lodestone"]
|
[:h1 "Lodestone"]
|
||||||
[:h2 "Favorites"]
|
[:h2 "Favorites"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue