refactor: remove i18n tongue context

This commit is contained in:
Tienson Qin
2022-02-08 17:31:32 +08:00
parent 5d17315561
commit 982eba9396
36 changed files with 2456 additions and 2665 deletions

View File

@@ -2,7 +2,7 @@
(:require [rum.core :as rum]
[frontend.state :as state]
[cljs-bean.core :as bean]
[frontend.context.i18n :as i18n]
[frontend.context.i18n :refer [t]]
[frontend.ui :as ui]
[frontend.handler.ui :as ui-handler]
[frontend.search :as search]
@@ -50,31 +50,28 @@
themes (sort #(:selected %) (map #(assoc % :selected (= (:url %) selected)) themes))
_ (reset! *total (count themes))]
(rum/with-context
[[t] i18n/*tongue-context*]
[:div.cp__themes-installed
{:tab-index -1}
[:h1.mb-4.text-2xl.p-1 (t :themes)]
(map-indexed
(fn [idx opt]
(let [current-selected (:selected opt)
plg (get (:plugin/installed-plugins @state/state) (keyword (:pid opt)))]
[:div.it.flex.px-3.py-1.5.rounded-sm.justify-between
{:key (str idx (:url opt))
:title (when current-selected "Cancel selected theme")
:class (util/classnames
[{:is-selected current-selected
:is-active (= idx @*cursor)}])
:on-click #(do (js/LSPluginCore.selectTheme (if current-selected nil (clj->js opt)))
(state/close-modal!))}
[:section
[:strong.block
[:small.opacity-60 (str (or (:name plg) "Logseq") " • ")]
(:name opt)]]
[:small.flex-shrink-0.flex.items-center.opacity-10
(when current-selected (ui/icon "check"))]]))
themes)])))
[:div.cp__themes-installed
{:tab-index -1}
[:h1.mb-4.text-2xl.p-1 (t :themes)]
(map-indexed
(fn [idx opt]
(let [current-selected (:selected opt)
plg (get (:plugin/installed-plugins @state/state) (keyword (:pid opt)))]
[:div.it.flex.px-3.py-1.5.rounded-sm.justify-between
{:key (str idx (:url opt))
:title (when current-selected "Cancel selected theme")
:class (util/classnames
[{:is-selected current-selected
:is-active (= idx @*cursor)}])
:on-click #(do (js/LSPluginCore.selectTheme (if current-selected nil (clj->js opt)))
(state/close-modal!))}
[:section
[:strong.block
[:small.opacity-60 (str (or (:name plg) "Logseq") " • ")]
(:name opt)]]
[:small.flex-shrink-0.flex.items-center.opacity-10
(when current-selected (ui/icon "check"))]]))
themes)]))
(rum/defc unpacked-plugin-loader
[unpacked-pkg-path]
@@ -164,136 +161,133 @@
name (or title name "Untitled")
unpacked? (not iir)
new-version (state/coming-update-new-version? coming-update)]
(rum/with-context
[[t] i18n/*tongue-context*]
[:div.cp__plugins-item-card
{:class (util/classnames
[{:market market?
:installed installed?
:updating installing-or-updating?
:has-new-version new-version}])}
[:div.cp__plugins-item-card
{:class (util/classnames
[{:market market?
:installed installed?
:updating installing-or-updating?
:has-new-version new-version}])}
[:div.l.link-block
{:on-click #(plugin-handler/open-readme!
url item (if repo remote-readme-display local-markdown-display))}
(if (and icon (not (string/blank? icon)))
[:img.icon {:src (if market? (plugin-handler/pkg-asset id icon) icon)}]
svg/folder)
[:div.l.link-block
{:on-click #(plugin-handler/open-readme!
url item (if repo remote-readme-display local-markdown-display))}
(if (and icon (not (string/blank? icon)))
[:img.icon {:src (if market? (plugin-handler/pkg-asset id icon) icon)}]
svg/folder)
(when (and (not market?) unpacked?)
[:span.flex.justify-center.text-xs.text-red-500.pt-2 (t :plugin/unpacked)])]
(when (and (not market?) unpacked?)
[:span.flex.justify-center.text-xs.text-red-500.pt-2 (t :plugin/unpacked)])]
[:div.r
[:h3.head.text-xl.font-bold.pt-1.5
[:div.r
[:h3.head.text-xl.font-bold.pt-1.5
[:span name]
(when (not market?) [:sup.inline-block.px-1.text-xs.opacity-50 version])]
[:span name]
(when (not market?) [:sup.inline-block.px-1.text-xs.opacity-50 version])]
[:div.desc.text-xs.opacity-70
[:p description]
;;[:small (js/JSON.stringify (bean/->js settings))]
]
[:div.desc.text-xs.opacity-70
[:p description]
;;[:small (js/JSON.stringify (bean/->js settings))]
]
;; Author & Identity
[:div.flag
[:p.text-xs.pr-2.flex.justify-between
[:small {:on-click #(when-let [^js el (js/document.querySelector ".cp__plugins-page .search-ctls input")]
(reset! *search-key (str "@" author))
(.select el))} author]
[:small {:on-click #(do
(notification/show! "Copied!" :success)
(util/copy-to-clipboard! id))}
(str "ID: " id)]]]
;; Author & Identity
[:div.flag
[:p.text-xs.pr-2.flex.justify-between
[:small {:on-click #(when-let [^js el (js/document.querySelector ".cp__plugins-page .search-ctls input")]
(reset! *search-key (str "@" author))
(.select el))} author]
[:small {:on-click #(do
(notification/show! "Copied!" :success)
(util/copy-to-clipboard! id))}
(str "ID: " id)]]]
;; Github repo
[:div.flag.is-top.opacity-50
(when repo
[:a.flex {:target "_blank"
:href (plugin-handler/gh-repo-url repo)}
(svg/github {:width 16 :height 16})])]
;; Github repo
[:div.flag.is-top.opacity-50
(when repo
[:a.flex {:target "_blank"
:href (plugin-handler/gh-repo-url repo)}
(svg/github {:width 16 :height 16})])]
(if market?
;; market ctls
[:div.ctl
[:ul.l.flex.items-center
;; stars
[:li.flex.text-sm.items-center.pr-3
(svg/star 16) [:span.pl-1 (:stargazers_count stat)]]
(if market?
;; market ctls
[:div.ctl
[:ul.l.flex.items-center
;; stars
[:li.flex.text-sm.items-center.pr-3
(svg/star 16) [:span.pl-1 (:stargazers_count stat)]]
;; downloads
(when-let [downloads (and stat (:total_downloads stat))]
(when (and downloads (> downloads 0))
[:li.flex.text-sm.items-center.pr-3
(svg/cloud-down 16) [:span.pl-1 downloads]]))]
;; downloads
(when-let [downloads (and stat (:total_downloads stat))]
(when (and downloads (> downloads 0))
[:li.flex.text-sm.items-center.pr-3
(svg/cloud-down 16) [:span.pl-1 downloads]]))]
[:div.r.flex.items-center
[:div.r.flex.items-center
[:a.btn
{:class (util/classnames [{:disabled (or installed? installing-or-updating?)
:installing installing-or-updating?}])
:on-click #(plugin-handler/install-marketplace-plugin item)}
(if installed?
(t :plugin/installed)
(if installing-or-updating?
[:span.flex.items-center [:small svg/loading]
(t :plugin/installing)]
(t :plugin/install)))]]]
[:a.btn
{:class (util/classnames [{:disabled (or installed? installing-or-updating?)
:installing installing-or-updating?}])
:on-click #(plugin-handler/install-marketplace-plugin item)}
(if installed?
(t :plugin/installed)
(if installing-or-updating?
[:span.flex.items-center [:small svg/loading]
(t :plugin/installing)]
(t :plugin/install)))]]]
;; installed ctls
[:div.ctl
[:div.l
[:div.de
[:strong (ui/icon "settings")]
[:ul.menu-list
[:li {:on-click #(when usf (js/apis.openPath usf))} (t :plugin/open-settings)]
[:li {:on-click #(js/apis.openPath url)} (t :plugin/open-package)]
[:li {:on-click
#(let [confirm-fn
(ui/make-confirm-modal
{:title (t :plugin/delete-alert name)
:on-confirm (fn [_ {:keys [close-fn]}]
(close-fn)
(plugin-handler/unregister-plugin id))})]
(state/set-sub-modal! confirm-fn {:center? true}))}
(t :plugin/uninstall)]]]
;; installed ctls
[:div.ctl
[:div.l
[:div.de
[:strong (ui/icon "settings")]
(when (seq sponsors)
[:div.de.sponsors
[:strong (ui/icon "coffee")]
[:ul.menu-list
[:li {:on-click #(when usf (js/apis.openPath usf))} (t :plugin/open-settings)]
[:li {:on-click #(js/apis.openPath url)} (t :plugin/open-package)]
[:li {:on-click
#(let [confirm-fn
(ui/make-confirm-modal
{:title (t :plugin/delete-alert name)
:on-confirm (fn [_ {:keys [close-fn]}]
(close-fn)
(plugin-handler/unregister-plugin id))})]
(state/set-sub-modal! confirm-fn {:center? true}))}
(t :plugin/uninstall)]]]
(for [link sponsors]
[:li [:a {:href link :target "_blank"}
[:span.flex.items-center link (ui/icon "external-link")]]])]])
]
(when (seq sponsors)
[:div.de.sponsors
[:strong (ui/icon "coffee")]
[:ul.menu-list
(for [link sponsors]
[:li [:a {:href link :target "_blank"}
[:span.flex.items-center link (ui/icon "external-link")]]])]])
]
[:div.r.flex.items-center
(when (and unpacked? (not disabled))
[:a.btn
{:on-click #(js-invoke js/LSPluginCore "reload" id)}
(t :plugin/reload)])
[:div.r.flex.items-center
(when (and unpacked? (not disabled))
[:a.btn
{:on-click #(js-invoke js/LSPluginCore "reload" id)}
(t :plugin/reload)])
(when (not unpacked?)
[:div.updates-actions
[:a.btn
{:class (util/classnames [{:disabled installing-or-updating?}])
:on-click #(when-not has-other-pending?
(plugin-handler/check-or-update-marketplace-plugin
(assoc item :only-check (not new-version))
(fn [e] (notification/show! e :error))))}
(when (not unpacked?)
[:div.updates-actions
[:a.btn
{:class (util/classnames [{:disabled installing-or-updating?}])
:on-click #(when-not has-other-pending?
(plugin-handler/check-or-update-marketplace-plugin
(assoc item :only-check (not new-version))
(fn [e] (notification/show! e :error))))}
(if installing-or-updating?
(t :plugin/updating)
(if new-version
(str (t :plugin/update) " 👉 " new-version)
(t :plugin/check-update))
)]])
(if installing-or-updating?
(t :plugin/updating)
(if new-version
(str (t :plugin/update) " 👉 " new-version)
(t :plugin/check-update))
)]])
(ui/toggle (not disabled)
(fn []
(js-invoke js/LSPluginCore (if disabled "enable" "disable") id)
(page-handler/init-commands!))
true)]])]])))
(ui/toggle (not disabled)
(fn []
(js-invoke js/LSPluginCore (if disabled "enable" "disable") id)
(page-handler/init-commands!))
true)]])]]))
(rum/defc panel-control-tabs
< rum/static
@@ -485,44 +479,41 @@
[@*sort-by #(compare %2 %1)])
filtered-pkgs))]
(rum/with-context
[[t] i18n/*tongue-context*]
[:div.cp__plugins-marketplace
[:div.cp__plugins-marketplace
(panel-control-tabs
t
@*search-key *search-key
@*category *category
@*sort-by *sort-by nil true
develop-mode? (::reload state))
(panel-control-tabs
t
@*search-key *search-key
@*category *category
@*sort-by *sort-by nil true
develop-mode? (::reload state))
(cond
(not online?)
[:p.flex.justify-center.pt-20.opacity-50
(svg/offline 30)]
(cond
(not online?)
[:p.flex.justify-center.pt-20.opacity-50
(svg/offline 30)]
@*fetching
[:p.flex.justify-center.pt-20
svg/loading]
@*fetching
[:p.flex.justify-center.pt-20
svg/loading]
@*error
[:p.flex.justify-center.pt-20.opacity-50
"Remote error: " (.-message @*error)]
@*error
[:p.flex.justify-center.pt-20.opacity-50
"Remote error: " (.-message @*error)]
:else
[:div.cp__plugins-marketplace-cnt
{:class (util/classnames [{:has-installing (boolean installing)}])}
[:div.cp__plugins-item-lists.grid-cols-1.md:grid-cols-2.lg:grid-cols-3
(for [item sorted-pkgs]
(rum/with-key
(let [pid (keyword (:id item))
stat (:stat item)]
(plugin-item-card
item true *search-key installing
(and installing (= (keyword (:id installing)) pid))
(contains? installed-plugins pid) stat nil))
(:id item)))]])])))
:else
[:div.cp__plugins-marketplace-cnt
{:class (util/classnames [{:has-installing (boolean installing)}])}
[:div.cp__plugins-item-lists.grid-cols-1.md:grid-cols-2.lg:grid-cols-3
(for [item sorted-pkgs]
(rum/with-key
(let [pid (keyword (:id item))
stat (:stat item)]
(plugin-item-card
item true *search-key installing
(and installing (= (keyword (:id installing)) pid))
(contains? installed-plugins pid) stat nil))
(:id item)))]])]))
(rum/defcs installed-plugins
< rum/static rum/reactive
@@ -570,27 +561,24 @@
(#(update % 0 (fn [coll] (sort-by :iir coll))))
(flatten))
filtered-plugins)]
(rum/with-context
[[t] i18n/*tongue-context*]
[:div.cp__plugins-installed
[:div.cp__plugins-installed
(panel-control-tabs
t
@*search-key *search-key
@*category *category
@*filter-by *filter-by
selected-unpacked-pkg
false develop-mode? nil)
(panel-control-tabs
t
@*search-key *search-key
@*category *category
@*filter-by *filter-by
selected-unpacked-pkg
false develop-mode? nil)
[:div.cp__plugins-item-lists.grid-cols-1.md:grid-cols-2.lg:grid-cols-3
(for [item sorted-plugins]
(rum/with-key
(let [pid (keyword (:id item))]
(plugin-item-card
item false *search-key updating
(and updating (= (keyword (:id updating)) pid))
true nil (get coming-updates pid))) (:id item)))]])))
[:div.cp__plugins-item-lists.grid-cols-1.md:grid-cols-2.lg:grid-cols-3
(for [item sorted-plugins]
(rum/with-key
(let [pid (keyword (:id item))]
(plugin-item-card
item false *search-key updating
(and updating (= (keyword (:id updating)) pid))
true nil (get coming-updates pid))) (:id item)))]]))
(rum/defcs waiting-coming-updates
< rum/reactive
@@ -720,30 +708,27 @@
(js/setTimeout (fn [] (.focus el)) 100))
[])
(rum/with-context
[[t] i18n/*tongue-context*]
[:div.cp__plugins-page
{:ref *el-ref
:tab-index "-1"}
[:h1 (t :plugins)]
(security-warning)
[:hr]
[:div.cp__plugins-page
{:ref *el-ref
:tab-index "-1"}
[:h1 (t :plugins)]
(security-warning)
[:hr]
[:div.tabs.flex.items-center.justify-center
[:div.tabs-inner.flex.items-center
(ui/button [:span.it (t :plugin/installed)]
:on-click #(set-active! :installed)
:intent "logseq" :class (if-not market? "active" ""))
[:div.tabs.flex.items-center.justify-center
[:div.tabs-inner.flex.items-center
(ui/button [:span.it (t :plugin/installed)]
:on-click #(set-active! :installed)
:intent "logseq" :class (if-not market? "active" ""))
(ui/button [:span.mk (svg/apps 16) (t :plugin/marketplace)]
:on-click #(set-active! :marketplace)
:intent "logseq" :class (if market? "active" ""))]]
(ui/button [:span.mk (svg/apps 16) (t :plugin/marketplace)]
:on-click #(set-active! :marketplace)
:intent "logseq" :class (if market? "active" ""))]]
[:div.panels
(if market?
(marketplace-plugins)
(installed-plugins))]])))
[:div.panels
(if market?
(marketplace-plugins)
(installed-plugins))]]))
(rum/defc custom-js-installer
[{:keys [t current-repo db-restoring? nfs-granted?]}]