|
| 1 | +(ns status-im.contexts.shell.activity-center.notification.news.view |
| 2 | + (:require [promesa.core :as promesa] |
| 3 | + [quo.core :as quo] |
| 4 | + [react-native.core :as rn] |
| 5 | + [status-im.contexts.shell.activity-center.notification.common.view :as common] |
| 6 | + [utils.datetime :as datetime] |
| 7 | + [utils.i18n :as i18n] |
| 8 | + [utils.re-frame :as rf])) |
| 9 | + |
| 10 | +(defn auto-resized-image |
| 11 | + [{:keys [url]}] |
| 12 | + (let [[height set-height] (rn/use-state nil) |
| 13 | + window-width (- (:width (rn/get-window)) 40)] |
| 14 | + (rn/use-effect #(-> (rn/image-get-size url) |
| 15 | + (promesa/then (fn [[w h]] |
| 16 | + (let [scale (/ window-width w) |
| 17 | + new-height (* h scale)] |
| 18 | + (set-height new-height)))))) |
| 19 | + (if height |
| 20 | + [rn/image |
| 21 | + {:resize-mode :contain |
| 22 | + :style {:width window-width |
| 23 | + :height height |
| 24 | + :align-self :center |
| 25 | + :border-radius 12} |
| 26 | + :source url}] |
| 27 | + [rn/view {:style {:height 200 :align-items :center :justify-content :center}} |
| 28 | + [rn/activity-indicator]]))) |
| 29 | + |
| 30 | +(defn sheet |
| 31 | + [{:keys [image title content link link-label]} timestamp] |
| 32 | + (let [customization-color (rf/sub [:profile/customization-color])] |
| 33 | + [:<> |
| 34 | + [quo/drawer-top {:title title :description timestamp}] |
| 35 | + [rn/scroll-view {:style {:flex 1}} |
| 36 | + (when image |
| 37 | + [auto-resized-image image]) |
| 38 | + [quo/text |
| 39 | + {:style {:padding-horizontal 20 |
| 40 | + :padding-vertical 8}} |
| 41 | + content]] |
| 42 | + (when (and link link-label) |
| 43 | + [quo/bottom-actions |
| 44 | + {:button-one-label link-label |
| 45 | + :button-one-props {:customization-color |
| 46 | + customization-color |
| 47 | + :icon-right :i/external |
| 48 | + :on-press |
| 49 | + (fn [] |
| 50 | + (rf/dispatch [:hide-bottom-sheet]))}}])])) |
| 51 | + |
| 52 | +;;TODO REMOVE |
| 53 | +#_(rf/dispatch |
| 54 | + [:activity-center.notifications/reconcile |
| 55 | + [{:id 0x1 |
| 56 | + :timestamp (datetime/timestamp) |
| 57 | + :type types/news-feed |
| 58 | + :title "Swaps around the corner! Loooong Looong TITLE" |
| 59 | + :description |
| 60 | + "Status Mobile's next release brings the app up-to-speed with Status Desktop.\u2028That means: SWAPS!" |
| 61 | + :content |
| 62 | + "Philosophers meticulously investigate existential dilemmas, scrutinizing metaphysical concepts and epistemological theories, seeking profound insights into consciousness, morality, and the enigmatic nature of existence through rigorous intellectual contemplation and debate." |
| 63 | + :link "https://our.status.im/" |
| 64 | + :link-label "Let's go" |
| 65 | + :image {:url "https://our.status.im/content/images/2025/03/Blog_-_cover_-_32.png"}}]]) |
| 66 | + |
| 67 | +(defn view |
| 68 | + [{:keys [notification extra-fn]}] |
| 69 | + (let [customization-color (rf/sub [:profile/customization-color]) |
| 70 | + {:keys [title description timestamp]} notification |
| 71 | + timestamp (datetime/timestamp->relative timestamp)] |
| 72 | + [common/swipeable |
| 73 | + {:left-button common/swipe-button-read-or-unread |
| 74 | + :left-on-press common/swipe-on-press-toggle-read |
| 75 | + :right-button common/swipe-button-delete |
| 76 | + :right-on-press common/swipe-on-press-delete |
| 77 | + :extra-fn extra-fn} |
| 78 | + [quo/activity-log |
| 79 | + {:title title |
| 80 | + :customization-color customization-color |
| 81 | + :icon :i/status-logo-bw |
| 82 | + :timestamp timestamp |
| 83 | + :context [[quo/text {} description]] |
| 84 | + :items [{:type :button |
| 85 | + :subtype :primary |
| 86 | + :key :button-reply |
| 87 | + :customization-color customization-color |
| 88 | + :label (i18n/label :t/read-more) |
| 89 | + :accessibility-label :read-more |
| 90 | + :on-press #(rf/dispatch |
| 91 | + [:show-bottom-sheet |
| 92 | + {:theme :dark |
| 93 | + :content |
| 94 | + (fn [] |
| 95 | + [sheet notification timestamp])}])}]}]])) |
0 commit comments