mirror of
https://github.com/logseq/logseq.git
synced 2026-04-30 17:06:23 +00:00
refactor: separate og and db version (#12276)
separate og and new version apps remove file sync, tldraw, excalidraw and zotero
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
cursors"
|
||||
(:require [cljs-bean.core :as bean]
|
||||
[cljs.core.async :as async :refer [>!]]
|
||||
[cljs.spec.alpha :as s]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as string]
|
||||
[datascript.core :as d]
|
||||
@@ -21,7 +20,6 @@
|
||||
[logseq.common.config :as common-config]
|
||||
[logseq.db :as ldb]
|
||||
[logseq.db.common.entity-plus :as entity-plus]
|
||||
[logseq.db.sqlite.util :as sqlite-util]
|
||||
[logseq.shui.dialog.core :as shui-dialog]
|
||||
[logseq.shui.hooks :as hooks]
|
||||
[logseq.shui.ui :as shui]
|
||||
@@ -75,12 +73,9 @@
|
||||
:route-match nil
|
||||
:today nil
|
||||
:system/events (async/chan 1000)
|
||||
:file/unlinked-dirs #{}
|
||||
:reactive/custom-queries (async/chan 1000)
|
||||
:notification/show? false
|
||||
:notification/content nil
|
||||
:repo/loading-files? {}
|
||||
:nfs/refreshing? nil
|
||||
:instrument/disabled? (storage/get "instrument-disabled")
|
||||
;; TODO: how to detect the network reliably?
|
||||
;; NOTE: prefer to use flows/network-online-event-flow
|
||||
@@ -259,9 +254,6 @@
|
||||
|
||||
;; all notification contents as k-v pairs
|
||||
:notification/contents {}
|
||||
:graph/syncing? false
|
||||
;; graph -> state
|
||||
:graph/parsing-state {}
|
||||
|
||||
:copy/export-block-text-indent-style (or (storage/get :copy/export-block-text-indent-style)
|
||||
"dashes")
|
||||
@@ -290,24 +282,9 @@
|
||||
:auth/access-token nil
|
||||
:auth/id-token nil
|
||||
|
||||
;; file-sync
|
||||
:file-sync/jstour-inst nil
|
||||
:file-sync/onboarding-state (or (storage/get :file-sync/onboarding-state)
|
||||
{:welcome false})
|
||||
:file-sync/remote-graphs {:loading false :graphs nil}
|
||||
:file-sync/set-remote-graph-password-result {}
|
||||
|
||||
;; graph-uuid -> {:graphs-txid {}
|
||||
;; :file-sync/sync-manager {}
|
||||
;; :file-sync/sync-state {}
|
||||
;; ;; {file-path -> payload}
|
||||
;; :file-sync/progress {}
|
||||
;; :file-sync/start-time {}
|
||||
;; :file-sync/last-synced-at {}}
|
||||
:file-sync/graph-state {:current-graph-uuid nil}
|
||||
;; graph-uuid -> ...
|
||||
|
||||
:rtc/state (atom {})
|
||||
:rtc/loading-graphs? nil
|
||||
;; only latest rtc-log stored here, when a log stream is needed,
|
||||
;; use missionary to create a rtc-log-flow, use (missionary.core/watch <atom>)
|
||||
:rtc/log (atom nil)
|
||||
@@ -325,19 +302,13 @@
|
||||
:ui/container-id (atom 0)
|
||||
:ui/cached-key->container-id (atom {})
|
||||
:feature/enable-sync? (storage/get :logseq-sync-enabled)
|
||||
:feature/enable-sync-diff-merge? ((fnil identity true) (storage/get :logseq-sync-diff-merge-enabled))
|
||||
|
||||
:file/rename-event-chan (async/chan 100)
|
||||
:ui/find-in-page nil
|
||||
:graph/importing nil
|
||||
:graph/importing-state {}
|
||||
:graph/loading? nil
|
||||
:handbook/route-chan (async/chan (async/sliding-buffer 1))
|
||||
|
||||
:whiteboard/onboarding-whiteboard? (or (storage/get :ls-onboarding-whiteboard?) false)
|
||||
:whiteboard/onboarding-tour? (or (storage/get :whiteboard-onboarding-tour?) false)
|
||||
:whiteboard/last-persisted-at {}
|
||||
:whiteboard/pending-tx-data {}
|
||||
:system/info {}
|
||||
;; Whether block is selected
|
||||
:ui/select-query-cache (atom {})
|
||||
@@ -370,41 +341,6 @@
|
||||
;; Then the default value is applied
|
||||
:file/name-format :legacy})
|
||||
|
||||
(def file-default-config
|
||||
"Default repo config for file graphs"
|
||||
(merge common-default-config
|
||||
;; The "NOW" query returns tasks with "NOW" or "DOING" status.
|
||||
;; The "NEXT" query returns tasks with "NOW", "LATER", or "TODO" status.
|
||||
{:default-queries
|
||||
{:journals
|
||||
[{:title "🔨 NOW"
|
||||
:query '[:find (pull ?h [*])
|
||||
:in $ ?start ?today
|
||||
:where
|
||||
(task ?h #{"NOW" "DOING"})
|
||||
[?h :block/page ?p]
|
||||
[?p :block/journal-day ?d]
|
||||
[(>= ?d ?start)]
|
||||
[(<= ?d ?today)]]
|
||||
:inputs [:14d :today]
|
||||
:result-transform '(fn [result]
|
||||
(sort-by (fn [h]
|
||||
(get h :block/priority "Z")) result))
|
||||
:group-by-page? false
|
||||
:collapsed? false}
|
||||
{:title "📅 NEXT"
|
||||
:query '[:find (pull ?h [*])
|
||||
:in $ ?start ?next
|
||||
:where
|
||||
(task ?h #{"NOW" "LATER" "TODO"})
|
||||
[?h :block/page ?p]
|
||||
[?p :block/journal-day ?d]
|
||||
[(> ?d ?start)]
|
||||
[(< ?d ?next)]]
|
||||
:inputs [:today :7d-after]
|
||||
:group-by-page? false
|
||||
:collapsed? false}]}}))
|
||||
|
||||
(def db-default-config
|
||||
"Default repo config for DB graphs"
|
||||
(merge common-default-config
|
||||
@@ -471,7 +407,7 @@ should be done through this fn in order to get global config and config defaults
|
||||
(get-config (get-current-repo)))
|
||||
([repo-url]
|
||||
(merge-configs
|
||||
(if (sqlite-util/db-based-graph? repo-url) db-default-config file-default-config)
|
||||
db-default-config
|
||||
(get-global-config)
|
||||
(get-graph-config repo-url))))
|
||||
|
||||
@@ -511,12 +447,6 @@ should be done through this fn in order to get global config and config defaults
|
||||
[]
|
||||
(:custom-js-url (get-config)))
|
||||
|
||||
(defn get-default-journal-template
|
||||
[]
|
||||
(when-let [template (get-in (get-config) [:default-templates :journals])]
|
||||
(when-not (string/blank? template)
|
||||
(string/trim template))))
|
||||
|
||||
(defn all-pages-public?
|
||||
[]
|
||||
(let [value (:publishing/all-pages-public? (get-config))
|
||||
@@ -559,13 +489,6 @@ should be done through this fn in order to get global config and config defaults
|
||||
(:journals-directory (get-config repo)))
|
||||
"journals"))
|
||||
|
||||
(defn get-whiteboards-directory
|
||||
[]
|
||||
(or
|
||||
(when-let [repo (get-current-repo)]
|
||||
(:whiteboards-directory (get-config repo)))
|
||||
"whiteboards"))
|
||||
|
||||
(defn org-mode-file-link?
|
||||
[repo]
|
||||
(:org-mode/insert-file-link? (get-config repo)))
|
||||
@@ -594,13 +517,12 @@ should be done through this fn in order to get global config and config defaults
|
||||
|
||||
(defn get-date-formatter
|
||||
[]
|
||||
(let [repo (get-current-repo)]
|
||||
(if (sqlite-util/db-based-graph? repo)
|
||||
(when-let [conn (db-conn-state/get-conn repo)]
|
||||
(get (entity-plus/entity-memoized @conn :logseq.class/Journal)
|
||||
:logseq.property.journal/title-format
|
||||
"MMM do, yyyy"))
|
||||
(common-config/get-date-formatter (get-config)))))
|
||||
(or
|
||||
(when-let [repo (get-current-repo)]
|
||||
(when-let [conn (db-conn-state/get-conn repo)]
|
||||
(get (entity-plus/entity-memoized @conn :logseq.class/Journal)
|
||||
:logseq.property.journal/title-format)))
|
||||
"MMM do, yyyy"))
|
||||
|
||||
(defn custom-shortcuts []
|
||||
(merge (storage/get :ls-shortcuts)
|
||||
@@ -702,7 +624,7 @@ Similar to re-frame subscriptions"
|
||||
([] (sub-config (get-current-repo)))
|
||||
([repo]
|
||||
(let [config (sub :config)]
|
||||
(merge-configs (if (and (string? repo) (sqlite-util/db-based-graph? repo)) db-default-config file-default-config)
|
||||
(merge-configs db-default-config
|
||||
(get config ::global-config)
|
||||
(get config repo)))))
|
||||
|
||||
@@ -727,10 +649,8 @@ Similar to re-frame subscriptions"
|
||||
(defn enable-journals?
|
||||
([]
|
||||
(enable-journals? (get-current-repo)))
|
||||
([repo]
|
||||
(if (sqlite-util/db-based-graph? repo) ; db graphs rely on journals for quick capture/sharing/assets, etc.
|
||||
true
|
||||
(not (false? (:feature/enable-journals? (sub-config repo)))))))
|
||||
([_repo]
|
||||
true))
|
||||
|
||||
(defn enable-flashcards?
|
||||
([]
|
||||
@@ -738,24 +658,6 @@ Similar to re-frame subscriptions"
|
||||
([repo]
|
||||
(not (false? (:feature/enable-flashcards? (sub-config repo))))))
|
||||
|
||||
(defn enable-sync?
|
||||
[]
|
||||
(sub :feature/enable-sync?))
|
||||
|
||||
(defn enable-sync-diff-merge?
|
||||
[]
|
||||
(sub :feature/enable-sync-diff-merge?))
|
||||
|
||||
(defn enable-whiteboards?
|
||||
([]
|
||||
(enable-whiteboards? (get-current-repo)))
|
||||
([repo]
|
||||
(not (false? (:feature/enable-whiteboards? (sub-config repo))))))
|
||||
|
||||
(defn enable-git-auto-push?
|
||||
[repo]
|
||||
(not (false? (:git-auto-push (sub-config repo)))))
|
||||
|
||||
(defn graph-settings
|
||||
[]
|
||||
(:graph/settings (sub-config)))
|
||||
@@ -899,10 +801,6 @@ Similar to re-frame subscriptions"
|
||||
[]
|
||||
(= :home (get-current-route)))
|
||||
|
||||
(defn whiteboard-dashboard?
|
||||
[]
|
||||
(= :whiteboards (get-current-route)))
|
||||
|
||||
(defn get-current-page
|
||||
[]
|
||||
(when (= :page (get-current-route))
|
||||
@@ -918,22 +816,14 @@ Similar to re-frame subscriptions"
|
||||
[]
|
||||
(:git/current-repo @state))
|
||||
|
||||
(defn get-remote-file-graphs
|
||||
[]
|
||||
(get-in @state [:file-sync/remote-graphs :graphs]))
|
||||
|
||||
(defn get-rtc-graphs
|
||||
[]
|
||||
(:rtc/graphs @state))
|
||||
|
||||
(defn get-remote-graph-info-by-uuid
|
||||
[uuid]
|
||||
(when-let [graphs (seq (get-in @state [:file-sync/remote-graphs :graphs]))]
|
||||
(some #(when (= (:GraphUUID %) (str uuid)) %) graphs)))
|
||||
|
||||
(defn get-remote-graph-usage
|
||||
[]
|
||||
(when-let [graphs (seq (get-in @state [:file-sync/remote-graphs :graphs]))]
|
||||
;; TODO: rtc version
|
||||
(comment
|
||||
(defn get-remote-graph-usage
|
||||
[graphs]
|
||||
(->> graphs
|
||||
(map #(hash-map :uuid (:GraphUUID %)
|
||||
:name (:GraphName %)
|
||||
@@ -943,24 +833,6 @@ Similar to re-frame subscriptions"
|
||||
(map #(assoc % :free-gbs (- (:limit-gbs %) (:used-gbs %))))
|
||||
(vec))))
|
||||
|
||||
(defn delete-remote-graph!
|
||||
[repo]
|
||||
(let [remove-repo! (fn [repos]
|
||||
(remove #(and
|
||||
(:GraphUUID repo)
|
||||
(:GraphUUID %)
|
||||
(= (:GraphUUID repo) (:GraphUUID %))) repos))]
|
||||
(if (:rtc-graph? repo)
|
||||
(swap! state update :rtc/graphs remove-repo!)
|
||||
(swap! state update-in [:file-sync/remote-graphs :graphs] remove-repo!))))
|
||||
|
||||
(defn add-remote-graph!
|
||||
[repo]
|
||||
(swap! state update-in [:file-sync/remote-graphs :graphs]
|
||||
(fn [repos]
|
||||
(->> (conj repos repo)
|
||||
(distinct)))))
|
||||
|
||||
(defn get-repos
|
||||
[]
|
||||
(get-in @state [:me :repos]))
|
||||
@@ -986,14 +858,6 @@ Similar to re-frame subscriptions"
|
||||
(storage/remove :git/current-repo))
|
||||
(ipc/ipc "setCurrentGraph" repo))
|
||||
|
||||
(defn set-preferred-format!
|
||||
[format]
|
||||
(swap! state assoc-in [:me :preferred_format] (name format)))
|
||||
|
||||
(defn set-preferred-workflow!
|
||||
[workflow]
|
||||
(swap! state assoc-in [:me :preferred_workflow] (name workflow)))
|
||||
|
||||
(defn set-preferred-language!
|
||||
[language]
|
||||
(set-state! :preferred-language (name language))
|
||||
@@ -1412,11 +1276,6 @@ Similar to re-frame subscriptions"
|
||||
(set-state! :editor/action-data nil)
|
||||
(set-state! :view/selected-blocks nil))
|
||||
|
||||
(defn into-code-editor-mode!
|
||||
[]
|
||||
(set-state! :editor/cursor-range nil)
|
||||
(swap! state assoc :editor/code-mode? true))
|
||||
|
||||
(defn set-editor-last-pos!
|
||||
[new-pos]
|
||||
(update-state! :editor/last-saved-cursor
|
||||
@@ -1760,21 +1619,6 @@ Similar to re-frame subscriptions"
|
||||
(when-let [hooks (sub :plugin/installed-hooks)]
|
||||
(contains? hooks (str "hook:editor:slot_" type)))))
|
||||
|
||||
(defn active-tldraw-app
|
||||
[]
|
||||
(when-let [tldraw-el (.querySelector js/document.body ".logseq-tldraw[data-tlapp]")]
|
||||
(gobj/get js/window.tlapps (.. tldraw-el -dataset -tlapp))))
|
||||
|
||||
(defn tldraw-editing-logseq-block?
|
||||
[]
|
||||
(when-let [app (active-tldraw-app)]
|
||||
(and (= 1 (.. app -selectedShapesArray -length))
|
||||
(= (.. app -editingShape) (.. app -selectedShapesArray (at 0))))))
|
||||
|
||||
(defn set-graph-syncing?
|
||||
[value]
|
||||
(set-state! :graph/syncing? value))
|
||||
|
||||
(defn set-editor-in-composition!
|
||||
[value]
|
||||
(set-state! :editor/in-composition? value))
|
||||
@@ -1783,15 +1627,6 @@ Similar to re-frame subscriptions"
|
||||
[]
|
||||
(:editor/in-composition? @state))
|
||||
|
||||
(defn set-loading-files!
|
||||
[repo value]
|
||||
(when repo
|
||||
(set-state! [:repo/loading-files? repo] value)))
|
||||
|
||||
(defn loading-files?
|
||||
[repo]
|
||||
(get-in @state [:repo/loading-files? repo]))
|
||||
|
||||
(defn set-editor-last-input-time!
|
||||
[repo time]
|
||||
(set-state! :editor/last-input-time time :path-in-sub-atom repo))
|
||||
@@ -1808,17 +1643,8 @@ Similar to re-frame subscriptions"
|
||||
(>= (- now last-input-time) diff))
|
||||
|
||||
;; not in editing mode
|
||||
;; Is this a good idea to put whiteboard check here?
|
||||
(not (get-edit-input-id))))))
|
||||
|
||||
(defn set-nfs-refreshing!
|
||||
[value]
|
||||
(set-state! :nfs/refreshing? value))
|
||||
|
||||
(defn nfs-refreshing?
|
||||
[]
|
||||
(:nfs/refreshing? @state))
|
||||
|
||||
(defn set-search-result!
|
||||
[value]
|
||||
(set-state! :search/result value))
|
||||
@@ -1868,8 +1694,7 @@ Similar to re-frame subscriptions"
|
||||
(defn sidebar-add-block!
|
||||
[repo db-id block-type]
|
||||
(when (not (util/sm-breakpoint?))
|
||||
(let [page (and (sqlite-util/db-based-graph? repo)
|
||||
(= :page block-type)
|
||||
(let [page (and (= :page block-type)
|
||||
(some-> (db-conn-state/get-conn repo) deref (d/entity db-id)))]
|
||||
(if (and page
|
||||
;; TODO: Use config/dev? when it's not a circular dep
|
||||
@@ -1926,14 +1751,9 @@ Similar to re-frame subscriptions"
|
||||
[args]
|
||||
(set-state! :editor/args args))
|
||||
|
||||
(defn editing-whiteboard-portal?
|
||||
[]
|
||||
(and (active-tldraw-app) (tldraw-editing-logseq-block?)))
|
||||
|
||||
(defn block-component-editing?
|
||||
[]
|
||||
(and (:block/component-editing-mode? @state)
|
||||
(not (editing-whiteboard-portal?))))
|
||||
(:block/component-editing-mode? @state))
|
||||
|
||||
(defn set-block-component-editing-mode!
|
||||
[value]
|
||||
@@ -2016,14 +1836,6 @@ Similar to re-frame subscriptions"
|
||||
(when (mobile-util/native-platform?)
|
||||
(set-state! :mobile/show-action-bar? false))))))))
|
||||
|
||||
(defn get-git-auto-commit-enabled?
|
||||
[]
|
||||
(false? (sub [:electron/user-cfgs :git/disable-auto-commit?])))
|
||||
|
||||
(defn get-git-commit-on-close-enabled?
|
||||
[]
|
||||
(sub [:electron/user-cfgs :git/commit-on-close?]))
|
||||
|
||||
(defn set-last-key-code!
|
||||
[key-code]
|
||||
(set-state! :editor/last-key-code key-code))
|
||||
@@ -2169,49 +1981,8 @@ Similar to re-frame subscriptions"
|
||||
(defn get-auth-refresh-token []
|
||||
(:auth/refresh-token @state))
|
||||
|
||||
(defn set-file-sync-manager [graph-uuid v]
|
||||
(when (and graph-uuid v)
|
||||
(set-state! [:file-sync/graph-state graph-uuid :file-sync/sync-manager] v)))
|
||||
|
||||
(defn get-file-sync-manager [graph-uuid]
|
||||
(get-in @state [:file-sync/graph-state graph-uuid :file-sync/sync-manager]))
|
||||
|
||||
(defn clear-file-sync-state! [graph-uuid]
|
||||
(set-state! [:file-sync/graph-state graph-uuid] nil))
|
||||
|
||||
(defn clear-file-sync-progress! [graph-uuid]
|
||||
(set-state! [:file-sync/graph-state
|
||||
graph-uuid
|
||||
:file-sync/progress]
|
||||
nil))
|
||||
|
||||
(defn set-file-sync-state [graph-uuid v]
|
||||
(when v (s/assert :frontend.fs.sync/sync-state v))
|
||||
(set-state! [:file-sync/graph-state graph-uuid :file-sync/sync-state] v))
|
||||
|
||||
(defn get-current-file-sync-graph-uuid
|
||||
[]
|
||||
(get-in @state [:file-sync/graph-state :current-graph-uuid]))
|
||||
|
||||
(defn sub-current-file-sync-graph-uuid
|
||||
[]
|
||||
(sub [:file-sync/graph-state :current-graph-uuid]))
|
||||
|
||||
(defn get-file-sync-state
|
||||
([]
|
||||
(get-file-sync-state (get-current-file-sync-graph-uuid)))
|
||||
([graph-uuid]
|
||||
(get-in @state [:file-sync/graph-state graph-uuid :file-sync/sync-state])))
|
||||
|
||||
(defn sub-file-sync-state
|
||||
[graph-uuid]
|
||||
(sub [:file-sync/graph-state graph-uuid :file-sync/sync-state]))
|
||||
|
||||
(defn reset-parsing-state!
|
||||
[]
|
||||
(set-state! [:graph/parsing-state (get-current-repo)] {}))
|
||||
|
||||
(defn set-parsing-state!
|
||||
"Leave for tests"
|
||||
[m]
|
||||
(update-state! [:graph/parsing-state (get-current-repo)]
|
||||
(if (fn? m) m
|
||||
@@ -2223,47 +1994,6 @@ Similar to re-frame subscriptions"
|
||||
(every? not-empty (vals agent-opts)))
|
||||
(str protocol "://" host ":" port))))
|
||||
|
||||
(defn get-sync-graph-by-id
|
||||
[graph-uuid]
|
||||
(when graph-uuid
|
||||
(let [graph (first (filter #(= graph-uuid (:GraphUUID %))
|
||||
(get-repos)))]
|
||||
(when (:url graph)
|
||||
graph))))
|
||||
|
||||
(defn unlinked-dir?
|
||||
[dir]
|
||||
(contains? (:file/unlinked-dirs @state) dir))
|
||||
|
||||
(defn get-file-rename-event-chan
|
||||
[]
|
||||
(:file/rename-event-chan @state))
|
||||
|
||||
(defn offer-file-rename-event-chan!
|
||||
[v]
|
||||
{:pre [(map? v)
|
||||
(= #{:repo :old-path :new-path} (set (keys v)))]}
|
||||
(async/offer! (get-file-rename-event-chan) v))
|
||||
|
||||
(defn set-onboarding-whiteboard!
|
||||
[v]
|
||||
(set-state! :whiteboard/onboarding-whiteboard? v)
|
||||
(storage/set :ls-onboarding-whiteboard? v))
|
||||
|
||||
(defn get-onboarding-whiteboard?
|
||||
[]
|
||||
(get-in @state [:whiteboard/onboarding-whiteboard?]))
|
||||
|
||||
(defn get-local-container-root-url
|
||||
[]
|
||||
(when (mobile-util/native-ios?)
|
||||
(get-in @state [:mobile/container-urls :localContainerUrl])))
|
||||
|
||||
(defn get-icloud-container-root-url
|
||||
[]
|
||||
(when (mobile-util/native-ios?)
|
||||
(get-in @state [:mobile/container-urls :iCloudContainerUrl])))
|
||||
|
||||
(defn get-current-pdf
|
||||
[]
|
||||
(:pdf/current @state))
|
||||
@@ -2277,15 +2007,6 @@ Similar to re-frame subscriptions"
|
||||
(set-state! :pdf/current nil)
|
||||
(js/setTimeout #(settle-file!) 16)))))
|
||||
|
||||
(defn focus-whiteboard-shape
|
||||
([shape-id]
|
||||
(focus-whiteboard-shape (active-tldraw-app) shape-id))
|
||||
([tln shape-id]
|
||||
(when-let [^js api (gobj/get tln "api")]
|
||||
(when (and shape-id (parse-uuid shape-id))
|
||||
(. api selectShapes shape-id)
|
||||
(. api zoomToSelection)))))
|
||||
|
||||
(defn set-user-info!
|
||||
[info]
|
||||
(when info
|
||||
|
||||
Reference in New Issue
Block a user