This commit is contained in:
Omar Basem
2022-12-16 11:33:26 +04:00
parent 9884232134
commit 53fb04719f
8 changed files with 25 additions and 46 deletions
+2 -1
View File
@@ -82,7 +82,8 @@
:output-dir "target/test"
:optimizations :simple
:target :node-test
:ns-regexp "status-im.chat.models-test$"
;; When running tests without a REPL you can uncomment the below line to `make test-watch` a specific file
;:ns-regexp "status-im.chat.models-test$"
:main status-im.test-runner/main
;; set :ui-driven to true to let shadow-cljs inject node-repl
:ui-driven true
+8 -30
View File
@@ -107,32 +107,10 @@
(-> (if end-cursor
(.getPhotos CameraRoll #js {:first num :after end-cursor :assetType "Photos" :groupTypes "All"})
(.getPhotos CameraRoll #js {:first num :assetType "Photos" :groupTypes "All"}))
(.then #(re-frame/dispatch [:on-camera-roll-get-photos (:edges (types/js->clj %)) (:page_info (types/js->clj %)) end-cursor]))
(.then #(let [response (types/js->clj %)]
(re-frame/dispatch [:on-camera-roll-get-photos (:edges response) (:page_info response) end-cursor])))
(.catch #(log/warn "could not get camera roll photos"))))})))
;(re-frame/reg-fx
; :camera-roll/get-photos
; (fn [{:keys [num end-cursor on-success on-failure]}]
; (-> (permissions/request-permissions
; {:permissions [:read-external-storage]
; :on-allowed (fn []
; (-> (if end-cursor
; (.getPhotos CameraRoll #js {:first num
; :after end-cursor
; :assetType "Photos"
; :groupTypes "All"})
; (.getPhotos CameraRoll #js {:first num
; :assetType "Photos"
; :groupTypes "All"}))))})
; (.then (fn [^js js-result]
; (when on-success
; (let [result (types/js->clj js-result)]
; (re-frame/dispatch (conj on-success {:edges (:edges result)
; :page-info (:page_info result)}))))))
; (.catch (fn [error]
; (when on-failure
; (re-frame/dispatch (conj on-failure error)))) ))))
(fx/defn image-captured
{:events [:chat.ui/image-captured]}
[{:keys [db]} chat-id uri]
@@ -150,17 +128,17 @@
(fx/defn camera-roll-loading-more
{:events [:chat.ui/camera-roll-loading-more]}
[{:keys [db]} is-loading]
{:db (assoc db :camera-roll-loading-more is-loading)})
{:db (assoc db :camera-roll/loading-more is-loading)})
(fx/defn on-camera-roll-get-photos
{:events [:on-camera-roll-get-photos]}
[{:keys [db] :as cofx} photos page-info end-cursor]
(let [photos_x (when end-cursor (:camera-roll-photos db))]
(let [photos_x (when end-cursor (:camera-roll/photos db))]
{:db (-> db
(assoc :camera-roll-photos (concat photos_x (map #(get-in % [:node :image :uri]) photos)))
(assoc :camera-roll-end-cursor (:end_cursor page-info))
(assoc :camera-roll-has-next-page (:has_next_page page-info))
(assoc :camera-roll-loading-more false))}))
(assoc :camera-roll/photos (concat photos_x (map #(get-in % [:node :image :uri]) photos)))
(assoc :camera-roll/end-cursor (:end_cursor page-info))
(assoc :camera-roll/has-next-page (:has_next_page page-info))
(assoc :camera-roll/loading-more false))}))
(fx/defn clear-sending-images
{:events [:chat.ui/clear-sending-images]}
+3 -3
View File
@@ -93,7 +93,7 @@
(let [res (chat/navigate-to-chat-nav2 {:db db} chat-id false)]
(is (nil? (get-in res [:db :pagination-info chat-id :all-loaded?])))))))
(deftest camera-roll-loading-more
(let [cofx {:db {:camera-roll-loading-more false}}]
(is (= {:db {:camera-roll-loading-more true}}
(deftest camera-roll-loading-more-test
(let [cofx {:db {:camera-roll/loading-more false}}]
(is (= {:db {:camera-roll/loading-more true}}
(images/camera-roll-loading-more cofx true)))))
@@ -80,7 +80,7 @@
[quo/radio {:value true}]])]]))
(defview photos []
(letsubs [camera-roll-photos [:camera-roll-photos]
(letsubs [camera-roll-photos [:camera-roll/photos]
selected [:chats/sending-image]
panel-height (reagent/atom nil)]
[react/view {:style {:flex 1
@@ -33,7 +33,7 @@
:source {:uri uri}}]])
(defview photos []
(letsubs [camera-roll-photos [:camera-roll-photos]]
(letsubs [camera-roll-photos [:camera-roll/photos]]
{:component-did-mount #(re-frame/dispatch [:chat.ui/camera-roll-get-photos 20])}
[react/scroll-view {:horizontal true
:style {:max-height 88}
@@ -55,8 +55,8 @@
[info-count/info-count (+ (utils/first-index #(= item %) @selected) 1) (style/image-count)])])
(defn on-end-reached [end-cursor]
(let [loading? (rf/sub [:camera-roll-loading-more])
has-next-page? (rf/sub [:camera-roll-has-next-page])]
(let [loading? (rf/sub [:camera-roll/loading-more])
has-next-page? (rf/sub [:camera-roll/has-next-page])]
(when (and (not loading?) has-next-page?)
(rf/dispatch [:chat.ui/camera-roll-loading-more true])
(rf/dispatch [:chat.ui/camera-roll-get-photos 20 end-cursor]))))
@@ -67,8 +67,8 @@
(fn []
(let [{window-height :height window-width :width} (rn/use-window-dimensions)
safe-area (safe-area/use-safe-area)
camera-roll-photos (rf/sub [:camera-roll-photos])
end-cursor (rf/sub [:camera-roll-end-cursor])]
camera-roll-photos (rf/sub [:camera-roll/photos])
end-cursor (rf/sub [:camera-roll/end-cursor])]
[rn/view {:style {:height (- window-height (:top safe-area))}}
[rn/touchable-opacity
{:on-press #(js/alert "Camera: not implemented")
+2 -2
View File
@@ -5,12 +5,12 @@
["react-native" :refer (DevSettings LogBox)]))
;; Ignore all logs, because there are lots of temporary warnings when developing and hot reloading
;(.ignoreAllLogs LogBox)
(.ignoreAllLogs LogBox)
;; Only ignore warnings/errors that cannot be fixed for the time being.
;; When you add a warning to be ignored explain below why it is ignored and how it can be fixed.
;; When a warning is fixed make sure to remove it from here.
(.ignoreLogs ^js LogBox (clj->js ["undefined is not an object (evaluating 'e.message')"
#_(.ignoreLogs ^js LogBox (clj->js ["undefined is not an object (evaluating 'e.message')"
"Cannot read property 'message' of undefined"
"InternalError Metro has encountered an error"
"undefined Unable to resolve module `parse-svg-path`"
+4 -4
View File
@@ -99,10 +99,10 @@
(reg-root-key-sub :selected-participants :selected-participants)
(reg-root-key-sub :chat/inputs :chat/inputs)
(reg-root-key-sub :chat/memberships :chat/memberships)
(reg-root-key-sub :camera-roll-photos :camera-roll-photos)
(reg-root-key-sub :camera-roll-end-cursor :camera-roll-end-cursor)
(reg-root-key-sub :camera-roll-has-next-page :camera-roll-has-next-page)
(reg-root-key-sub :camera-roll-loading-more :camera-roll-loading-more)
(reg-root-key-sub :camera-roll/photos :camera-roll/photos)
(reg-root-key-sub :camera-roll/end-cursor :camera-roll/end-cursor)
(reg-root-key-sub :camera-roll/has-next-page :camera-roll/has-next-page)
(reg-root-key-sub :camera-roll/loading-more :camera-roll/loading-more)
(reg-root-key-sub :group-chat/invitations :group-chat/invitations)
(reg-root-key-sub :chats/mention-suggestions :chats/mention-suggestions)
(reg-root-key-sub :chat/inputs-with-mentions :chat/inputs-with-mentions)