widgets.cljs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. (ns frontend.components.widgets
  2. (:require [frontend.context.i18n :refer [t]]
  3. [frontend.handler.page :as page-handler]
  4. [frontend.handler.web.nfs :as nfs]
  5. [frontend.modules.shortcut.core :as shortcut]
  6. [frontend.ui :as ui]
  7. [rum.core :as rum]
  8. [frontend.config :as config]
  9. [frontend.mobile.util :as mobile-util]
  10. [frontend.state :as state]))
  11. (rum/defc add-local-directory
  12. []
  13. [:div.flex.flex-col
  14. [:h1.title (t :on-boarding/add-graph)]
  15. (let [nfs-supported? (or (nfs/supported?) (mobile-util/native-platform?))]
  16. (if (mobile-util/native-platform?)
  17. [:div.text-sm
  18. (ui/button "Open a local directory"
  19. :on-click #(state/pub-event! [:graph/setup-a-repo]))
  20. [:hr]
  21. [:div
  22. [:div.font-bold.mb-2 "I need some help"]
  23. [:p "👋 Join our Forum to chat with the makers and our helpful community members."]
  24. (ui/button "Join the community"
  25. :href "https://discuss.logseq.com"
  26. :target "_blank")]]
  27. [:div.cp__widgets-open-local-directory
  28. [:div.select-file-wrap.cursor
  29. (when nfs-supported?
  30. {:on-click #(page-handler/ls-dir-files! shortcut/refresh!)})
  31. [:div
  32. [:h1.title (t :on-boarding/open-local-dir)]
  33. [:p (t :on-boarding/new-graph-desc-1)]
  34. [:p (t :on-boarding/new-graph-desc-2)]
  35. [:ul
  36. [:li (t :on-boarding/new-graph-desc-3)]
  37. [:li (t :on-boarding/new-graph-desc-4)]
  38. [:li (t :on-boarding/new-graph-desc-5)]]
  39. (when-not nfs-supported?
  40. (ui/admonition :warning
  41. [:p "It seems that your browser doesn't support the "
  42. [:a {:href "https://web.dev/file-system-access/"
  43. :target "_blank"}
  44. "new native filesystem API"]
  45. [:span ", please use any Chromium 86+ based browser like Chrome, Vivaldi, Edge, etc. Notice that the API doesn't support mobile browsers at the moment."]]))]]]))])
  46. (rum/defc android-permission-alert
  47. []
  48. (when (mobile-util/native-android?)
  49. [:div.flex.flex-col
  50. [:h1.title "Storage access permission"]
  51. [:div.text-sm
  52. [:div
  53. [:p "Logseq needs the permission to access your device storage. Read "
  54. [:a {:href "https://developer.android.com/about/versions/11/privacy/storage#all-files-access"
  55. :target "_blank"}
  56. "more"]
  57. "."]
  58. [:div
  59. (ui/button "Grant Permission"
  60. :on-click #(page-handler/ls-dir-files! shortcut/refresh!))]
  61. [:p.mb-1 "Note:"]
  62. [:ol
  63. [:li "We will never access files outside of your graph folders you choose."]
  64. [:li "If you have granted the permission, you don't need to do it again."]]]
  65. [:hr]]]))
  66. (rum/defcs add-graph <
  67. [state & {:keys [graph-types]
  68. :or {graph-types [:local]}}]
  69. (let [generate-f (fn [x]
  70. (case x
  71. :local
  72. [(rum/with-key (android-permission-alert)
  73. "android-permission-alert")
  74. (rum/with-key (add-local-directory)
  75. "add-local-directory")]
  76. nil))
  77. available-graph (->> (set graph-types)
  78. (keep generate-f)
  79. (vec)
  80. (interpose [:b.mt-10.mb-5.opacity-50 "OR"]))]
  81. [:div.p-8.flex.flex-col available-graph]))
  82. (rum/defc demo-graph-alert
  83. []
  84. (when (and (config/demo-graph?)
  85. (not config/publishing?))
  86. (ui/admonition
  87. :warning
  88. [:p (t :on-boarding/demo-graph)])))