page.cljs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. (ns frontend.page
  2. "Provides root component for both Logseq app and publishing build"
  3. (:require [rum.core :as rum]
  4. [frontend.state :as state]
  5. [frontend.ui :as ui]
  6. [frontend.components.sidebar :as sidebar]
  7. [frontend.handler.search :as search-handler]
  8. [frontend.handler.notification :as notification]
  9. [frontend.components.onboarding.quick-tour :as quick-tour]
  10. [frontend.handler.plugin :as plugin-handler]))
  11. (rum/defc route-view
  12. [view route-match]
  13. (view route-match))
  14. (defn- setup-fns!
  15. []
  16. (try
  17. (comp
  18. (ui/setup-active-keystroke!))
  19. (catch :default _e
  20. nil)))
  21. (rum/defc helpful-default-error-screen
  22. "This screen is displayed when the UI has crashed hard. It provides the user
  23. with basic troubleshooting steps to get them back to a working state. This
  24. component is purposefully stupid simple as it needs to render under any number
  25. of broken conditions"
  26. []
  27. ;; This layout emulates most of sidebar/sidebar
  28. [:div#main-container.cp__sidebar-main-layout.flex-1.flex
  29. [:div.#app-container
  30. [:div#left-container
  31. [:div#main-container.cp__sidebar-main-layout.flex-1.flex
  32. [:div#main-content-container.scrollbar-spacing.w-full.flex.justify-center
  33. [:div.cp__sidebar-main-content
  34. [:div.ls-center
  35. [:div.icon-box.p-1.rounded.mb-3 (ui/icon "bug" {:style {:font-size ui/icon-size}})]
  36. [:div.text-xl.font-bold
  37. "Sorry. Something went wrong!"]
  38. [:div.mt-2.mb-2 "Logseq is having a problem. To try to get it back to a
  39. working state, please try the following safe steps in order:"]
  40. [:div
  41. ;; TODO: Enable once multi-window case doesn't result in possible data loss
  42. #_[:div.flex.flex-row.justify-between.align-items.mb-2
  43. [:div.flex.flex-col.items-start
  44. [:div.text-2xs.uppercase "STEP 1"]
  45. [:div [:span.font-bold "Reload"] " the app"]]
  46. [:div (ui/icon "command") (ui/icon "letter-r")]]
  47. [:div.flex.flex-row.justify-between.align-items.mb-2.items-center.py-4
  48. [:div.flex.flex-col.items-start
  49. [:div.text-2xs.font-bold.uppercase.toned-down "STEP 1"]
  50. [:div [:span.highlighted.font-bold "Rebuild"] [:span.toned-down " search index"]]]
  51. [:div
  52. (ui/button "Try"
  53. :small? true
  54. :on-click (fn []
  55. (search-handler/rebuild-indices! true)))]]
  56. [:div.flex.flex-row.justify-between.align-items.mb-2.items-center.separator-top.py-4
  57. [:div.flex.flex-col.items-start
  58. [:div.text-2xs.font-bold.uppercase.toned-down "STEP 2"]
  59. [:div [:span.highlighted.font-bold "Relaunch"][:span.toned-down " the app"]]
  60. [:div.text-xs.toned-down "Quit the app and then reopen it."]]
  61. [:div (ui/icon "command" {:class "rounded-md p-1 mr-2 bg-quaternary"})
  62. (ui/icon "letter-q" {:class "rounded-md p-1 bg-quaternary"})]]
  63. [:div.flex.flex-row.justify-between.align-items.mb-4.items-center.separator-top.py-4
  64. [:div.flex.flex-col.items-start
  65. [:div.text-2xs.font-bold.uppercase.toned-down "STEP 3"]
  66. [:div [:span.highlighted.font-bold "Clear"] [:span.toned-down " local storage"]]
  67. [:div.text-xs.toned-down "This does delete minor preferences like dark/light theme preference."]]
  68. [:div
  69. (ui/button "Try"
  70. :small? true
  71. :on-click (fn []
  72. (.clear js/localStorage)
  73. (notification/show! "Cleared!" :success)))]]]
  74. [:div
  75. [:p "If you think you have experienced data loss, check for backup files under
  76. the folder logseq/bak/."]
  77. [:p "If these troubleshooting steps have not solved your problem, please "
  78. [:a.underline
  79. {:href "https://github.com/logseq/logseq/issues/new?labels=from:in-app&template=bug_report.yaml"}
  80. "open an issue."]]]]]]]]]
  81. (ui/notification)])
  82. (rum/defc current-page < rum/reactive
  83. {:did-mount (fn [state]
  84. (state/set-root-component! (:rum/react-component state))
  85. (state/setup-electron-updater!)
  86. (ui/inject-document-devices-envs!)
  87. (ui/inject-dynamic-style-node!)
  88. (quick-tour/init)
  89. (plugin-handler/host-mounted!)
  90. (assoc state ::teardown (setup-fns!) ))
  91. :will-unmount (fn [state]
  92. (when-let [teardown (::teardown state)]
  93. (teardown)))}
  94. []
  95. (when-let [route-match (state/sub :route-match)]
  96. (let [route-name (get-in route-match [:data :name])]
  97. (when-let [view (:view (:data route-match))]
  98. (ui/catch-error-and-notify
  99. (helpful-default-error-screen)
  100. (if (= :draw route-name)
  101. (view route-match)
  102. (sidebar/sidebar
  103. route-match
  104. (view route-match))))))))
  105. ;; FIXME: disable for now
  106. ;; (let [route-name (get-in route-match [:data :name])
  107. ;; no-animate? (contains? #{:repos :repo-add :file}
  108. ;; route-name)]
  109. ;; (when-let [view (:view (:data route-match))]
  110. ;; (sidebar/sidebar
  111. ;; route-match
  112. ;; (if no-animate?
  113. ;; (route-view view route-match)
  114. ;; (ui/transition-group
  115. ;; {:class-name "router-wrapper"}
  116. ;; (ui/css-transition
  117. ;; {:class-names "pageChange"
  118. ;; :key route-name
  119. ;; :timeout {:enter 300
  120. ;; :exit 200}}
  121. ;; (route-view view route-match)))))))