Skip to content

Commit

Permalink
fix: separate loading status for different graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Dec 21, 2021
1 parent 1048608 commit 8de131c
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 30 deletions.
6 changes: 1 addition & 5 deletions src/electron/electron/handler.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,7 @@
result (get (js->clj result) "filePaths")
path (first result)]
(if path
(do
(.. ^js window -webContents
(send "open-dir-confirmed"
(bean/->js {:opened? true})))
(p/resolved (bean/->js (get-files path))))
(p/resolved (bean/->js (get-files path)))
(p/rejected (js/Error "path empty")))))

(defmethod handle :getFiles [window [_ path]]
Expand Down
6 changes: 0 additions & 6 deletions src/main/electron/listener.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@

(defn listen-to-electron!
[]
(js/window.apis.on "open-dir-confirmed"
(fn []
(state/set-loading-files! true)
(when-not (state/home?)
(route-handler/redirect-to-home!))))

;; TODO: move "file-watcher" to electron.ipc.channels
(js/window.apis.on "file-watcher"
(fn [data]
Expand Down
4 changes: 2 additions & 2 deletions src/main/frontend/components/sidebar.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@
cloning? (state/sub :repo/cloning?)
default-home (get-default-home-if-valid)
importing-to-db? (state/sub :repo/importing-to-db?)
loading-files? (state/sub :repo/loading-files?)
current-repo (state/sub :git/current-repo)
loading-files? (when current-repo (state/sub [:repo/loading-files? current-repo]))
me (state/sub :me)
journals-length (state/sub :journals-length)
current-repo (state/sub :git/current-repo)
latest-journals (db/get-latest-journals (state/get-current-repo) journals-length)
preferred-format (state/sub [:me :preferred_format])
logged? (:name me)]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/handler/file.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
(defn load-files
[repo-url]
(state/set-cloning! false)
(state/set-loading-files! true)
(state/set-loading-files! repo-url true)
(p/let [files (git/list-files repo-url)
files (bean/->clj files)
config-content (load-file repo-url
Expand Down
4 changes: 2 additions & 2 deletions src/main/frontend/handler/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
(when-not (string/blank? file-path)
(db/transact! [[:db.fn/retractEntity [:file/path file-path]]])
(->
(p/let [_ (or (config/local-db? repo)
(p/let [_ (or (config/local-db? repo)
(git/remove-file repo file-path))
_ (and (config/local-db? repo)
(mobile-util/is-native-platform?)
Expand Down Expand Up @@ -685,7 +685,7 @@
[]
(when-let [repo (state/get-current-repo)]
(when (and (state/enable-journals? repo)
(not (:repo/loading-files? @state/state)))
(not (state/loading-files? repo)))
(state/set-today! (date/today))
(when (or (db/cloned? repo)
(config/local-db? repo)
Expand Down
4 changes: 2 additions & 2 deletions src/main/frontend/handler/repo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
(defn parse-files-and-load-to-db!
[repo-url files {:keys [first-clone? delete-files delete-blocks re-render? re-render-opts refresh?] :as opts
:or {re-render? true}}]
(state/set-loading-files! false)
(state/set-loading-files! repo-url false)
(when-not refresh? (state/set-importing-to-db! true))
(let [file-paths (map :file/path files)]
(let [metadata-file (config/get-metadata-path)
Expand Down Expand Up @@ -312,7 +312,7 @@
(js/console.dir error)
;; Empty repo
(create-default-files! repo-url)
(state/set-loading-files! false))))
(state/set-loading-files! repo-url false))))

:else
(when (seq diffs)
Expand Down
20 changes: 11 additions & 9 deletions src/main/frontend/handler/web/nfs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,24 @@
electron? (util/electron?)
mobile-native? (mobile-util/is-native-platform?)
nfs? (and (not electron?)
(not mobile-native?))]
(not mobile-native?))
*repo (atom nil)]
;; TODO: add ext filter to avoid loading .git or other ignored file handlers
(->
(p/let [result (fs/open-dir (fn [path handle]
(when nfs?
(swap! path-handles assoc path handle))))
_ (state/set-loading-files! true)
_ (when-not (state/home?)
(route-handler/redirect-to-home! false))
root-handle (first result)
dir-name (if nfs?
(gobj/get root-handle "name")
root-handle)]
root-handle)
repo (str config/local-db-prefix dir-name)
_ (state/set-loading-files! repo true)
_ (when-not (state/home?)
(route-handler/redirect-to-home! false))]
(reset! *repo repo)
(when-not (string/blank? dir-name)
(p/let [repo (str config/local-db-prefix dir-name)
root-handle-path (str config/local-handle-prefix dir-name)
(p/let [root-handle-path (str config/local-handle-prefix dir-name)
_ (when nfs?
(idb/set-item! root-handle-path root-handle)
(nfs/add-nfs-file-handle! root-handle-path root-handle))
Expand Down Expand Up @@ -174,7 +176,7 @@
{:first-clone? true
:nfs-files files})]
(state/add-repo! {:url repo :nfs? true})
(state/set-loading-files! false)
(state/set-loading-files! repo false)
(and ok-handler (ok-handler))
(when (util/electron?)
(fs/watch-dir! dir-name))
Expand All @@ -186,7 +188,7 @@
(p/catch (fn [error]
(log/error :exception error)
(if (contains? #{"AbortError" "Error"} (gobj/get error "name"))
(state/set-loading-files! false)
(when @*repo (state/set-loading-files! @*repo false))
;; (log/error :nfs/open-dir-error error)
))))))

Expand Down
11 changes: 8 additions & 3 deletions src/main/frontend/state.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
:notification/show? false
:notification/content nil
:repo/cloning? false
:repo/loading-files? nil
:repo/loading-files? {}
:repo/importing-to-db? nil
:repo/sync-status {}
:repo/changed-files nil
Expand Down Expand Up @@ -1320,8 +1320,13 @@
(:editor/in-composition? @state))

(defn set-loading-files!
[value]
(set-state! :repo/loading-files? value))
[repo value]
(when repo
(set-state! [:repo/loading-files? repo] value)))

(defn loading-files?
[repo]
(get-in @state [:repo/loading-files? repo]))

(defn set-importing-to-db!
[value]
Expand Down

0 comments on commit 8de131c

Please sign in to comment.