Skip to content

Commit

Permalink
safe-nth
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarBasem committed Mar 29, 2023
1 parent 77bc68c commit 803f36d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/status_im/utils/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
(when (string? s)
(string/replace s m r)))

(defn safe-nth
[coll index]
(when (number? index)
(nth coll index)))

(defn svg?
[some-string]
(string/ends-with? some-string ".svg"))
Expand Down
3 changes: 2 additions & 1 deletion src/status_im2/contexts/chat/lightbox/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
[status-im2.contexts.chat.lightbox.top-view :as top-view]
[status-im2.contexts.chat.lightbox.bottom-view :as bottom-view]
[utils.worklets.lightbox :as worklet]
[status-im.utils.utils :as utils]
[oops.core :refer [oget]]))

(def ^:const seperator-width 16)
Expand Down Expand Up @@ -130,7 +131,7 @@
;; The initial value of data is the image that was pressed (and not the whole album) in order
;; for the transition animation to execute properly, otherwise it would animate towards
;; outside the screen (even if we have `initialScrollIndex` set).
data (reagent/atom (if (number? index) [(nth messages index)] []))
data (reagent/atom [(utils/safe-nth messages index)])
scroll-index (reagent/atom index)
transparent? (reagent/atom false)
set-full-height? (reagent/atom false)
Expand Down

0 comments on commit 803f36d

Please # to comment.