-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4997a2
commit cc45a8c
Showing
19 changed files
with
316 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
(ns status-im.common.alert-banner.events | ||
(:require [re-frame.core :as re-frame])) | ||
|
||
(defn add-alert-banner | ||
[{:keys [db]} [banner]] | ||
(let [current-banners-count (count (get db :alert-banners)) | ||
db (assoc-in db [:alert-banners (:type banner)] banner)] | ||
(cond-> {:db db} | ||
(zero? current-banners-count) | ||
(assoc :show-alert-banner nil)))) | ||
|
||
(defn remove-alert-banner | ||
[{:keys [db]} [banner-type]] | ||
(let [db (update-in db [:alert-banners] dissoc banner-type) | ||
new-count (count (get db :alert-banners))] | ||
(cond-> {:db db} | ||
(zero? new-count) | ||
(assoc :hide-alert-banner nil)))) | ||
|
||
(defn remove-all-alert-banners | ||
[{:keys [db]}] | ||
{:db (dissoc db :alert-banners) | ||
:hide-alert-banner nil}) | ||
|
||
(re-frame/reg-event-fx :alert-banners/add add-alert-banner) | ||
(re-frame/reg-event-fx :alert-banners/remove remove-alert-banner) | ||
(re-frame/reg-event-fx :alert-banners/remove-all remove-all-alert-banners) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
(ns status-im.common.alert-banner.events-test | ||
(:require | ||
[cljs.test :refer [deftest is testing]] | ||
matcher-combinators.test | ||
[status-im.common.alert-banner.events :as events])) | ||
|
||
(deftest add-alert-banner | ||
(testing "Alert banner is added" | ||
(is (match? {:db {:alert-banners | ||
{:alert {:text "Alert" | ||
:type :alert}}} | ||
:show-alert-banner nil} | ||
(events/add-alert-banner {:db {}} | ||
[{:text "Alert" | ||
:type :alert}]))))) | ||
|
||
(deftest remove-alert-banner | ||
(testing "Alert banner is removed" | ||
(is (match? {:db {} | ||
:hide-alert-banner nil} | ||
(events/remove-alert-banner {:db {:alert-banners | ||
{:alert {:text "Alert" | ||
:type :alert}}}} | ||
[:alert])))) | ||
(testing "Alert banner is not removed" | ||
(is (match? {:db {:alert-banners | ||
{:alert {:text "Alert" | ||
:type :alert}}}} | ||
(events/remove-alert-banner {:db {:alert-banners | ||
{:alert {:text "Alert" | ||
:type :alert}}}} | ||
[:error]))))) | ||
|
||
(deftest remove-all-alert-banners | ||
(testing "All Alert banners are removed" | ||
(is (match? {:db {} | ||
:hide-alert-banner nil} | ||
(events/remove-all-alert-banners {:db {:alert-banners | ||
{:alert {:text "Alert" | ||
:type :alert} | ||
:error {:text "Error" | ||
:type :error}}}}))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(ns status-im.common.alert-banner.style) | ||
|
||
(def border-radius 20) | ||
|
||
(defn container | ||
[background-color] | ||
{:background-color background-color}) | ||
|
||
(def second-banner-wrapper | ||
{:margin-top (- border-radius) | ||
:overflow :hidden | ||
:border-top-left-radius border-radius | ||
:border-top-right-radius border-radius}) | ||
|
||
(defn hole-view | ||
[background-color] | ||
{:padding-top 11 | ||
:align-items :center | ||
:height 60 | ||
:background-color background-color}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
(ns status-im.common.alert-banner.view | ||
(:require [quo.core :as quo] | ||
[quo.foundations.colors :as colors] | ||
quo.theme | ||
[react-native.core :as rn] | ||
[react-native.hole-view :as hole-view] | ||
[react-native.safe-area :as safe-area] | ||
[status-im.common.alert-banner.style :as style] | ||
[status-im.constants :as constants] | ||
[utils.re-frame :as rf])) | ||
|
||
(defn get-colors-map | ||
[theme] | ||
{:alert | ||
{:background-color (colors/resolve-color :warning theme 20) | ||
:text-color (colors/resolve-color :warning theme)} | ||
:error | ||
{:background-color (colors/resolve-color :danger theme 20) | ||
:text-color (colors/resolve-color :danger theme)}}) | ||
|
||
(defn- banner | ||
[{:keys [text type second-banner? colors-map]}] | ||
[rn/view (when second-banner? {:style style/second-banner-wrapper}) | ||
[hole-view/hole-view | ||
{:style (style/hole-view (get-in colors-map [type :background-color])) | ||
:holes (if second-banner? | ||
[] | ||
[{:x 0 | ||
:y constants/alert-banner-height | ||
:width (:width (rn/get-window)) | ||
:height constants/alert-banner-height | ||
:borderRadius style/border-radius}])} | ||
[quo/text | ||
{:size :paragraph-2 | ||
:weight :medium | ||
:style {:color (get-in colors-map [type :text-color])}} | ||
text]]]) | ||
|
||
(defn view | ||
[] | ||
(let [banners (rf/sub [:alert-banners]) | ||
theme (quo.theme/use-theme-value) | ||
banners-count (count banners) | ||
alert-banner (:alert banners) | ||
error-banner (:error banners) | ||
safe-area-top (safe-area/get-top) | ||
colors-map (get-colors-map theme)] | ||
[hole-view/hole-view | ||
{:style {:background-color colors/neutral-100} | ||
:holes [{:x 0 | ||
:y (+ safe-area-top (* constants/alert-banner-height banners-count)) | ||
:width (:width (rn/get-window)) | ||
:height constants/alert-banner-height | ||
:borderRadius style/border-radius}]} | ||
[rn/view | ||
{:style {:height safe-area-top | ||
:background-color (get-in colors-map | ||
[(if error-banner :error :alert) :background-color])}}] | ||
(when error-banner | ||
[banner | ||
(assoc error-banner | ||
:colors-map colors-map | ||
:second-banner? false)]) | ||
(when alert-banner | ||
[banner | ||
(assoc alert-banner | ||
:colors-map colors-map | ||
:second-banner? (= 2 banners-count))])])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/status_im/contexts/preview/status_im/banners/alert_banner.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(ns status-im.contexts.preview.status-im.banners.alert-banner | ||
(:require | ||
[reagent.core :as reagent] | ||
[status-im.contexts.preview.quo.preview :as preview] | ||
[utils.re-frame :as rf])) | ||
|
||
(def descriptor | ||
[{:key :alert-banner? | ||
:type :boolean} | ||
{:key :alert-message | ||
:type :text} | ||
{:key :error-banner? | ||
:type :boolean} | ||
{:key :error-message | ||
:type :text}]) | ||
|
||
(defn view | ||
[] | ||
(let [state (reagent/atom {:alert-banner? false | ||
:alert-message "Testnet mode enabled" | ||
:error-banner? false | ||
:error-message "Main and failover JSON RPC URLs offline"}) | ||
alert-banner? (reagent/cursor state [:alert-banner?]) | ||
alert-message (reagent/cursor state [:alert-message]) | ||
error-banner? (reagent/cursor state [:error-banner?]) | ||
error-message (reagent/cursor state [:error-message])] | ||
(fn [] | ||
(if @alert-banner? | ||
(rf/dispatch [:alert-banners/add | ||
{:type :alert | ||
:text @alert-message}]) | ||
(rf/dispatch [:alert-banners/remove :alert])) | ||
(if @error-banner? | ||
(rf/dispatch [:alert-banners/add | ||
{:type :error | ||
:text @error-message}]) | ||
(rf/dispatch [:alert-banners/remove :error])) | ||
[preview/preview-container {:state state :descriptor descriptor}]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.