widgets.cljs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. (ns frontend.components.widgets
  2. (:require [clojure.string :as string]
  3. [promesa.core :as p]
  4. [frontend.mobile.util :as mobile]
  5. [frontend.context.i18n :as i18n]
  6. [frontend.handler.notification :as notification]
  7. [frontend.handler.page :as page-handler]
  8. [frontend.handler.repo :as repo-handler]
  9. [frontend.handler.user :as user-handler]
  10. [frontend.handler.web.nfs :as nfs]
  11. [frontend.modules.shortcut.core :as shortcut]
  12. [frontend.state :as state]
  13. [frontend.ui :as ui]
  14. [frontend.util :as util]
  15. [rum.core :as rum]
  16. [frontend.config :as config]
  17. [frontend.mobile.util :as mobile-util]))
  18. (rum/defc choose-preferred-format
  19. []
  20. (rum/with-context [[t] i18n/*tongue-context*]
  21. [:div
  22. [:h1.title {:style {:margin-bottom "0.25rem"}}
  23. (t :format/preferred-mode)]
  24. [:div.mt-4.ml-1
  25. (ui/button
  26. "Markdown"
  27. :on-click
  28. #(user-handler/set-preferred-format! :markdown))
  29. [:span.ml-2.mr-2 "-OR-"]
  30. (ui/button
  31. "Org Mode"
  32. :on-click
  33. #(user-handler/set-preferred-format! :org))]]))
  34. (rum/defcs add-github-repo <
  35. (rum/local "" ::repo)
  36. (rum/local "" ::branch)
  37. [state]
  38. (let [repo (get state ::repo)
  39. branch (get state ::branch)]
  40. (rum/with-context [[t] i18n/*tongue-context*]
  41. [:div.flex.flex-col
  42. [:div.w-full.mx-auto
  43. [:div
  44. [:div
  45. [:h1.title
  46. (t :git/add-repo-prompt)]
  47. [:div.mt-4.mb-4.relative.rounded-md.shadow-sm.max-w-xs
  48. [:input#repo.form-input.block.w-full.sm:text-sm.sm:leading-5
  49. {:autoFocus true
  50. :placeholder "https://github.com/username/repo"
  51. :on-change (fn [e]
  52. (reset! repo (util/evalue e)))}]]
  53. [:label.font-medium "Default Branch (make sure it's matched with your setting on GitHub): "]
  54. [:div.mt-2.mb-4.relative.rounded-md.shadow-sm.max-w-xs
  55. [:input#branch.form-input.block.w-full.sm:text-sm.sm:leading-5
  56. {:value @branch
  57. :placeholder "e.g. main"
  58. :on-change (fn [e]
  59. (reset! branch (util/evalue e)))}]]]]
  60. (ui/button
  61. (t :git/add-repo-prompt-confirm)
  62. :on-click
  63. (fn []
  64. (let [branch (string/trim @branch)]
  65. (if (string/blank? branch)
  66. (notification/show!
  67. [:p.text-gray-700.dark:text-gray-300 "Please input a branch, make sure it's matched with your setting on GitHub."]
  68. :error
  69. false)
  70. (let [repo (util/lowercase-first @repo)]
  71. (if (util/starts-with? repo "https://github.com/")
  72. (let [repo (string/replace repo ".git" "")]
  73. (repo-handler/create-repo! repo branch))
  74. (notification/show!
  75. [:p.text-gray-700.dark:text-gray-300 "Please input a valid repo url, e.g. https://github.com/username/repo"]
  76. :error
  77. false)))))))]])))
  78. (rum/defcs add-local-directory
  79. []
  80. (rum/with-context [[t] i18n/*tongue-context*]
  81. [:div.flex.flex-col
  82. [:h1.title "Add a graph"]
  83. (let [nfs-supported? (or (nfs/supported?) (mobile/is-native-platform?))]
  84. (if (mobile-util/is-native-platform?)
  85. [:div.text-sm
  86. (ui/button "Open a local directory"
  87. :on-click #(page-handler/ls-dir-files! shortcut/refresh!))
  88. [:hr]
  89. [:ol
  90. [:li
  91. [:div.font-bold.mb-2 "How to sync my notes?"]
  92. (if (mobile-util/native-android?)
  93. [:div
  94. [:p "We're developing our built-in paid Logseq Sync, but you can use any third-party sync service to keep your notes sync with other devices."]
  95. [:p "If you prefer to use Dropbox to sync your notes, you can use "
  96. [:a {:href "https://play.google.com/store/apps/details?id=com.ttxapps.dropsync"
  97. :target "_blank"}
  98. "Dropsync"]
  99. ". Or you can use "
  100. [:a {:href "https://play.google.com/store/apps/details?id=dk.tacit.android.foldersync.lite"
  101. :target "_blank"}
  102. "FolderSync"]
  103. "."]]
  104. [:div
  105. [:p "iCloud TBD"]])]
  106. [:li.mt-8
  107. [:div.font-bold.mb-2 "I need some help"]
  108. [:p "👋 Join our discord group to chat with the makers and our helpful community members."]
  109. (ui/button "Join the community"
  110. :href "https://discord.gg/KpN4eHY"
  111. :target "_blank")]]]
  112. [:div.cp__widgets-open-local-directory
  113. [:div.select-file-wrap.cursor
  114. (when nfs-supported?
  115. {:on-click #(page-handler/ls-dir-files! shortcut/refresh!)})
  116. [:div
  117. [:h1.title "Open a local directory"]
  118. [:p "Logseq supports both Markdown and Org-mode. You can open an existing directory or create a new one on your device, a directory is also known simply as a folder. Your data will be stored only on this device."]
  119. [:p "After you have opened your directory, it will create three folders in that directory:"]
  120. [:ul
  121. [:li "/journals - store your journal pages"]
  122. [:li "/pages - store the other pages"]
  123. [:li "/logseq - store configuration, custom.css, and some metadata."]]
  124. (when-not nfs-supported?
  125. (ui/admonition :warning
  126. [:p "It seems that your browser doesn't support the "
  127. [:a {:href "https://web.dev/file-system-access/"
  128. :target "_blank"}
  129. "new native filesystem API"]
  130. [: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."]]))]]]))]))
  131. (rum/defcs add-graph <
  132. [state & {:keys [graph-types]
  133. :or {graph-types [:local :github]}
  134. :as opts}]
  135. (let [github-authed? (state/github-authed?)
  136. generate-f (fn [x]
  137. (case x
  138. :github
  139. (when (and github-authed? (not (util/electron?)))
  140. (rum/with-key (add-github-repo)
  141. "add-github-repo"))
  142. :local
  143. (rum/with-key (add-local-directory)
  144. "add-local-directory")
  145. nil))
  146. available-graph (->> (set graph-types)
  147. (keep generate-f)
  148. (vec)
  149. (interpose [:b.mt-10.mb-5.opacity-50 "OR"]))]
  150. (rum/with-context [[t] i18n/*tongue-context*]
  151. [:div.p-8.flex.flex-col available-graph])))
  152. (rum/defc demo-graph-alert
  153. []
  154. (when (and (config/demo-graph?)
  155. (not config/publishing?))
  156. (ui/admonition
  157. :warning
  158. [:p "This is a demo graph, changes will not be saved until you open a local folder."])))
  159. (rum/defc github-integration-soon-deprecated-alert
  160. []
  161. (when-let [repo (state/get-current-repo)]
  162. (when (string/starts-with? repo "https://github.com")
  163. [:div.github-alert
  164. (ui/admonition
  165. :warning
  166. [:p "We're going to deprecate the GitHub integration when the mobile app is out, you can switch to the latest "
  167. [:a {:href "https://github.com/logseq/logseq/releases"
  168. :target "_blank"}
  169. "desktop app"]
  170. [:span ", see more details at "]
  171. [:a {:href "https://discord.com/channels/725182569297215569/735735090784632913/861656585578086400"
  172. :target "_blank"}
  173. "here"]
  174. [:span "."]])])))