Compare commits
No commits in common. "8d7e4dde0ec39440bb924b6ad0d0355af20527a6" and "905fe2bd88aa4e9090560616657d0d5b4598c792" have entirely different histories.
8d7e4dde0e
...
905fe2bd88
2 changed files with 33 additions and 37 deletions
|
|
@ -153,11 +153,13 @@
|
||||||
(obtain-oauth-authorization-code! application))))))
|
(obtain-oauth-authorization-code! application))))))
|
||||||
|
|
||||||
(declare fetch-posts!)
|
(declare fetch-posts!)
|
||||||
(declare debounced-refresh!)
|
(declare refresh-displayed-posts!)
|
||||||
|
|
||||||
(defn- fetch-application-settings []
|
(defn- fetch-application-settings []
|
||||||
(->> (db/open-cursor! ::db/application db/all)
|
(-> (db/open-cursor! ::db/application db/all)
|
||||||
(db/first-result (map #(js->clj % :keywordize-keys true)))))
|
(db/transduce-cursor (comp (take 1)
|
||||||
|
(map #(js->clj % :keywordize-keys true)))
|
||||||
|
(fn [_ x] x))))
|
||||||
|
|
||||||
(defn setup-application!
|
(defn setup-application!
|
||||||
"Handles Mastodon application setup on the client side"
|
"Handles Mastodon application setup on the client side"
|
||||||
|
|
@ -200,7 +202,7 @@
|
||||||
(if (zero? post-count)
|
(if (zero? post-count)
|
||||||
(fetch-posts! {:instance-url (:instance_url application)
|
(fetch-posts! {:instance-url (:instance_url application)
|
||||||
:bearer-token (:bearer_token application)})
|
:bearer-token (:bearer_token application)})
|
||||||
(debounced-refresh! (:section/posts @state))))))))
|
(refresh-displayed-posts! (:section/posts @state))))))))
|
||||||
|
|
||||||
;;; views
|
;;; views
|
||||||
|
|
||||||
|
|
@ -287,7 +289,7 @@
|
||||||
:on-change (fn [e]
|
:on-change (fn [e]
|
||||||
(let [query (.. e -target -value)]
|
(let [query (.. e -target -value)]
|
||||||
(swap! state assoc-in [:section/posts :query] (if (str/blank? query) nil query))
|
(swap! state assoc-in [:section/posts :query] (if (str/blank? query) nil query))
|
||||||
(debounced-refresh! (:section/posts @state))))}])
|
(refresh-displayed-posts! (:section/posts @state))))}])
|
||||||
|
|
||||||
(defn- debug
|
(defn- debug
|
||||||
"Implements a lazy pretty-printer for whatever is passed in as `obj`. The
|
"Implements a lazy pretty-printer for whatever is passed in as `obj`. The
|
||||||
|
|
@ -315,23 +317,16 @@
|
||||||
(drop 1))])
|
(drop 1))])
|
||||||
|
|
||||||
(defn attachment [{:keys [attachment]}]
|
(defn attachment [{:keys [attachment]}]
|
||||||
(let [preview-url (or (:preview_remote_url attachment) (:preview_url attachment))
|
(case (:type attachment)
|
||||||
remote-url (or (:remote_url attachment) (:url attachment))
|
"image" [:img {:src (:preview_url attachment)
|
||||||
_ (js/console.log :preview-url preview-url :remote_url remote-url :attachment attachment)
|
:alt (:description attachment)
|
||||||
ext (last (str/split remote-url #"\."))]
|
:lazy "lazy"}]
|
||||||
(case (:type attachment)
|
"video" [:video {:controls true}
|
||||||
"image" [:img {:src preview-url
|
[:source {:type (str "video/" (last (str/split (:remote_url attachment) #"\.")))
|
||||||
:srcset (str preview-url ", " remote-url)
|
:src (:remote_url attachment)}]
|
||||||
:alt (:description attachment)
|
[:a {:href (:remote_url attachment)} (str "Original video at " (:remote_url attachment))]]
|
||||||
:lazy "lazy"}]
|
[:div [:strong "Unsupported attachment"]
|
||||||
"video" [:video {:controls true}
|
[debug attachment]]))
|
||||||
[:source {:type (str "video/" ext) :src remote-url}]
|
|
||||||
[:a {:href (:remote_url attachment)} (str "Original video at " (:remote_url attachment))]]
|
|
||||||
"gifv" [:video {:controls true :loop true :autoplay true}
|
|
||||||
[:source {:type (str "video/" ext) :src remote-url}]
|
|
||||||
[:a {:href (:remote_url attachment)} (str "Original video at " (:remote_url attachment))]]
|
|
||||||
[:div [:strong "Unsupported attachment"]
|
|
||||||
[debug attachment]])))
|
|
||||||
|
|
||||||
(defn post [{:keys [post]}]
|
(defn post [{:keys [post]}]
|
||||||
; TODO: handle (:sensitive post)
|
; TODO: handle (:sensitive post)
|
||||||
|
|
@ -382,8 +377,8 @@
|
||||||
refresh-id (js/Date.now)]
|
refresh-id (js/Date.now)]
|
||||||
(swap! state update-in [:section/posts :loading] conj refresh-id)
|
(swap! state update-in [:section/posts :loading] conj refresh-id)
|
||||||
(. (promise-all [(db/count! ::db/posts)
|
(. (promise-all [(db/count! ::db/posts)
|
||||||
(->> (db/open-cursor! ::db/posts ::db/post-created-at db/all "prev")
|
(-> (db/open-cursor! ::db/posts ::db/post-created-at db/all "prev")
|
||||||
(db/transduce-cursor xform))])
|
(db/transduce-cursor xform))])
|
||||||
(then (fn [[total displayed-posts]]
|
(then (fn [[total displayed-posts]]
|
||||||
(swap! state update :section/posts #(-> (assoc % :total total)
|
(swap! state update :section/posts #(-> (assoc % :total total)
|
||||||
(assoc :displayed-posts displayed-posts)
|
(assoc :displayed-posts displayed-posts)
|
||||||
|
|
@ -412,10 +407,12 @@
|
||||||
(paginate-posts! (merge defaults opts))))
|
(paginate-posts! (merge defaults opts))))
|
||||||
|
|
||||||
(defn- internal-post-id [max-or-min]
|
(defn- internal-post-id [max-or-min]
|
||||||
(->> (db/open-cursor! ::db/posts ::db/post-created-at db/all (if (= max-or-min :min)
|
(-> (db/open-cursor! ::db/posts ::db/post-created-at db/all (if (= max-or-min :min)
|
||||||
"next"
|
"next"
|
||||||
"prev"))
|
"prev"))
|
||||||
(db/first-result (keep (j/get :internal_id)))))
|
(db/transduce-cursor (comp (keep (j/get :internal_id))
|
||||||
|
(take 1))
|
||||||
|
(fn [_ x] x))))
|
||||||
|
|
||||||
(defn fetch-more-posts! [e]
|
(defn fetch-more-posts! [e]
|
||||||
(.preventDefault e)
|
(.preventDefault e)
|
||||||
|
|
|
||||||
|
|
@ -103,13 +103,13 @@
|
||||||
Takes a transducer `xform`, a reducing function `rf` and an initial `init`.
|
Takes a transducer `xform`, a reducing function `rf` and an initial `init`.
|
||||||
If no `init` is given, it will default to `(rf)`. If no `rf` is given, the
|
If no `init` is given, it will default to `(rf)`. If no `rf` is given, the
|
||||||
resulting value will be a persistent vector containing the result of all steps."
|
resulting value will be a persistent vector containing the result of all steps."
|
||||||
([xform cursor-req]
|
([cursor-req xform]
|
||||||
; optimization: work with a transient vector before returning the final result
|
; optimization: work with a transient vector before returning the final result
|
||||||
(-> (transduce-cursor xform conj! (transient []) cursor-req)
|
(-> (transduce-cursor cursor-req xform conj! (transient []))
|
||||||
(.then persistent!)))
|
(.then persistent!)))
|
||||||
([xform rf cursor-req]
|
([cursor-req xform rf]
|
||||||
(transduce-cursor xform rf (rf) cursor-req))
|
(transduce-cursor cursor-req xform rf (rf)))
|
||||||
([xform rf init cursor-req]
|
([cursor-req xform rf init]
|
||||||
(let [result (volatile! init)
|
(let [result (volatile! init)
|
||||||
xform (xform rf)]
|
xform (xform rf)]
|
||||||
(js/Promise.
|
(js/Promise.
|
||||||
|
|
@ -121,15 +121,14 @@
|
||||||
; to avoid unnecessary conversion costs.
|
; to avoid unnecessary conversion costs.
|
||||||
(let [step (xform @result (.-value cursor))]
|
(let [step (xform @result (.-value cursor))]
|
||||||
(if (reduced? step)
|
(if (reduced? step)
|
||||||
(resolve @step)
|
(do
|
||||||
|
(vreset! result @step)
|
||||||
|
(resolve @result))
|
||||||
(do
|
(do
|
||||||
(vreset! result step)
|
(vreset! result step)
|
||||||
(.continue cursor))))
|
(.continue cursor))))
|
||||||
(resolve @result)))))))))
|
(resolve @result)))))))))
|
||||||
|
|
||||||
(defn first-result [xform cursor-req]
|
|
||||||
(transduce-cursor (comp xform (take 1)) (fn [_ x] x) cursor-req))
|
|
||||||
|
|
||||||
(def all (js/IDBKeyRange.lowerBound ""))
|
(def all (js/IDBKeyRange.lowerBound ""))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue