Fix attachment reusal bug
The way that the atom was sometimes dereferenced and sometimes not caused weird re-rendering artifacts, where sometimes attachment would show up below posts that they actually did not belong to. Refactoring all of the different cases to be handled by separate functions seems to solve this.
This commit is contained in:
parent
bddb3b97fa
commit
58d709f7be
1 changed files with 23 additions and 14 deletions
|
|
@ -353,24 +353,33 @@
|
|||
(interleave (repeat ", "))
|
||||
(drop 1))])
|
||||
|
||||
(defn attachment [{:keys [attachment]}]
|
||||
(let [preview-url (or (:preview_remote_url attachment) (:preview_url attachment))
|
||||
remote-url (or (:remote_url attachment) (:url attachment))
|
||||
ext (last (str/split remote-url #"\."))]
|
||||
(case (:type attachment)
|
||||
"image" [:img {:src preview-url
|
||||
:srcset (str preview-url ", " remote-url)
|
||||
(defn img-attachment [{:keys [attachment preview-url]}]
|
||||
[:img {:src preview-url
|
||||
:alt (:description attachment)
|
||||
:loading "lazy"}]
|
||||
"video" [:video {:controls true}
|
||||
:loading "lazy"}])
|
||||
|
||||
(defn video-attachment [{:keys [attachment remote-url ext]}]
|
||||
[:video {:controls true}
|
||||
[:source {:type (str "video/" ext) :src remote-url}]
|
||||
[:a {:href (:remote_url attachment)} (str "Original video at " (:remote_url attachment))]]
|
||||
"gifv" (let [autoplay (r/atom false)
|
||||
[:a {:href (:remote_url attachment)} (str "Original video at " (:remote_url attachment))]])
|
||||
|
||||
(defn gifv-attachment [{:keys [attachment remote-url ext]}]
|
||||
(let [autoplay (r/atom false)
|
||||
toggle-autoplay #(swap! autoplay not)]
|
||||
(fn []
|
||||
[:video {:loop true :autoplay @autoplay :muted true :on-pointer-enter toggle-autoplay}
|
||||
[:source {:type (str "video/" ext) :src remote-url}]
|
||||
[:a {:href (:remote_url attachment)} (str "Original video at " (:remote_url attachment))]]))
|
||||
[:a {:href (:remote_url attachment)} (str "Original video at " (:remote_url attachment))]])))
|
||||
|
||||
(defn attachment [{:keys [attachment]}]
|
||||
(let [preview-url (or (:preview_remote_url attachment) (:preview_url attachment))
|
||||
remote-url (or (:remote_url attachment) (:url attachment))
|
||||
ext (last (str/split remote-url #"\."))
|
||||
props {:attachment attachment :preview-url preview-url :remote-url remote-url :ext ext}]
|
||||
(case (:type attachment)
|
||||
"image" [img-attachment props]
|
||||
"video" [video-attachment props]
|
||||
"gifv" [gifv-attachment props]
|
||||
[:div [:strong "Unsupported attachment"]
|
||||
[debug attachment]])))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue