page.cljs 5.6 KB

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