mirror of
https://github.com/logseq/logseq.git
synced 2026-05-24 20:54:09 +00:00
94 lines
3.2 KiB
Clojure
94 lines
3.2 KiB
Clojure
(ns mobile.core
|
|
"Mobile core"
|
|
(:require ["react-dom/client" :as rdc]
|
|
[clojure.string :as string]
|
|
[frontend.background-tasks]
|
|
[frontend.components.imports :as imports]
|
|
[frontend.db.async :as db-async]
|
|
[frontend.handler :as fhandler]
|
|
[frontend.handler.db-based.rtc-background-tasks]
|
|
[frontend.handler.route :as route-handler]
|
|
[frontend.state :as state]
|
|
[frontend.util :as util]
|
|
[lambdaisland.glogi :as log]
|
|
[logseq.shui.ui :as shui]
|
|
[mobile.bottom-tabs :as bottom-tabs]
|
|
[mobile.components.app :as app]
|
|
[mobile.events]
|
|
[mobile.init :as init]
|
|
[mobile.navigation :as mobile-nav]
|
|
[mobile.routes :refer [routes]]
|
|
[mobile.state :as mobile-state]
|
|
[promesa.core :as p]
|
|
[reitit.frontend :as rf]
|
|
[reitit.frontend.easy :as rfe]))
|
|
|
|
(defonce ^js root (rdc/createRoot (.getElementById js/document "root")))
|
|
|
|
(defn ^:export render!
|
|
[]
|
|
(.render root (app/main)))
|
|
|
|
(defn set-router!
|
|
[]
|
|
(let [router (rf/router routes nil)]
|
|
(rfe/start!
|
|
router
|
|
(fn [route]
|
|
(let [route-name (get-in route [:data :name])
|
|
path (-> js/location .-hash (string/replace-first #"^#" ""))]
|
|
(mobile-nav/notify-route-change!
|
|
{:route {:to route-name
|
|
:path-params (:path-params route)
|
|
:query-params (:query-params route)}
|
|
:path path})
|
|
|
|
(route-handler/set-route-match! route)
|
|
|
|
(bottom-tabs/show!)
|
|
(case route-name
|
|
:page
|
|
(let [id-str (get-in route [:path-params :name])]
|
|
(when (util/uuid-string? id-str)
|
|
(let [page-uuid (uuid id-str)
|
|
repo (state/get-current-repo)]
|
|
(when (and repo page-uuid)
|
|
(p/let [entity (db-async/<get-block repo page-uuid
|
|
{:children? false
|
|
:skip-refresh? true})]
|
|
(when entity
|
|
(when (state/get-edit-block)
|
|
(state/clear-edit!))
|
|
(when (mobile-state/quick-add-open?)
|
|
(mobile-state/close-popup!))))))))
|
|
|
|
:graphs
|
|
(mobile-state/redirect-to-tab! "settings")
|
|
|
|
:import
|
|
(p/do!
|
|
(p/delay 300)
|
|
(shui/popup-show! nil (fn []
|
|
(imports/importer {}))
|
|
{:id :import}))
|
|
|
|
nil)))
|
|
|
|
;; set to false to enable HistoryAPI
|
|
{:use-fragment true})))
|
|
|
|
(defn ^:export init []
|
|
;; init is called ONCE when the page loads
|
|
;; this is called in the index.html and must be exported
|
|
;; so it is available even in :advanced release builds
|
|
(prn "[Mobile] init!")
|
|
(log/add-handler mobile-state/log-append!)
|
|
(set-router!)
|
|
(init/init!)
|
|
(fhandler/start! render!))
|
|
|
|
(defn ^:export stop! []
|
|
;; stop is called before any code is reloaded
|
|
;; this is controlled by :before-load in the config
|
|
(prn "[Mobile] stop!"))
|