|
|
@@ -1,8 +1,8 @@
|
|
|
(ns logseq.shui.toaster.core
|
|
|
- (:require [rum.core :as rum]
|
|
|
+ (:require [cljs-bean.core :as bean]
|
|
|
[daiquiri.interpreter :refer [interpret]]
|
|
|
[logseq.shui.util :as util]
|
|
|
- [cljs-bean.core :as bean]))
|
|
|
+ [rum.core :as rum]))
|
|
|
|
|
|
(defonce ^:private Toaster (util/lsui-wrap "Toaster"))
|
|
|
(defonce ^:private *toast (atom nil))
|
|
|
@@ -22,23 +22,24 @@
|
|
|
(rum/defc install-toaster
|
|
|
< rum/static
|
|
|
[]
|
|
|
- (let [^js js-toast (js/window.LSUI.useToast)]
|
|
|
- (rum/use-effect!
|
|
|
- (fn []
|
|
|
- (reset! *toast {:toast (.-toast js-toast)
|
|
|
- :dismiss (.-dismiss js-toast)
|
|
|
- :update (.-update js-toast)})
|
|
|
- #())
|
|
|
- [])
|
|
|
- [:<> (Toaster)]))
|
|
|
+ ;; (let [^js js-toast (js/window.LSUI.useToast)]
|
|
|
+ ;; (rum/use-effect!
|
|
|
+ ;; (fn []
|
|
|
+ ;; (reset! *toast {:toast (.-toast js-toast)
|
|
|
+ ;; :dismiss (.-dismiss js-toast)
|
|
|
+ ;; :update (.-update js-toast)})
|
|
|
+ ;; #())
|
|
|
+ ;; [])
|
|
|
+ ;; [:<> (Toaster)])
|
|
|
+ )
|
|
|
|
|
|
(defn update-html-props
|
|
|
[v]
|
|
|
(update-keys v
|
|
|
- #(case %
|
|
|
- :class :className
|
|
|
- :for :htmlFor
|
|
|
- %)))
|
|
|
+ #(case %
|
|
|
+ :class :className
|
|
|
+ :for :htmlFor
|
|
|
+ %)))
|
|
|
|
|
|
(defn interpret-vals
|
|
|
[config ks & args]
|
|
|
@@ -46,7 +47,7 @@
|
|
|
(let [v (get config k)
|
|
|
v (if (fn? v) (apply v args) v)]
|
|
|
(if (vector? v) (assoc config k (interpret v)) config)))
|
|
|
- config ks))
|
|
|
+ config ks))
|
|
|
|
|
|
(defn toast!
|
|
|
([content-or-config] (toast! content-or-config :default nil))
|
|
|
@@ -56,12 +57,12 @@
|
|
|
(let [config (if (map? content-or-config)
|
|
|
content-or-config
|
|
|
(-> {:description content-or-config}
|
|
|
- (merge (if (map? status) status {:variant status}))))
|
|
|
+ (merge (if (map? status) status {:variant status}))))
|
|
|
config (update-html-props (merge config opts))
|
|
|
id (or (:id config) (gen-id))
|
|
|
config (assoc config :id id)
|
|
|
config (interpret-vals config [:title :description :action :icon]
|
|
|
- {:id id :dismiss! #(dismiss id) :update! #(toast! (assoc %1 :id id))})]
|
|
|
+ {:id id :dismiss! #(dismiss id) :update! #(toast! (assoc %1 :id id))})]
|
|
|
(js->clj (toast (clj->js config))))
|
|
|
:exception)))
|
|
|
|