Skip to content

Commit

Permalink
enhance: page only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc authored and tiensonqin committed Apr 12, 2023
1 parent cf13507 commit b613a9a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 68 deletions.
21 changes: 0 additions & 21 deletions src/main/frontend/components/bottom_bar.cljs

This file was deleted.

8 changes: 0 additions & 8 deletions src/main/frontend/components/bottom_bar.css

This file was deleted.

4 changes: 1 addition & 3 deletions src/main/frontend/components/container.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
[frontend.components.svg :as svg]
[frontend.components.theme :as theme]
[frontend.components.widgets :as widgets]
[frontend.components.bottom-bar :as bottom-bar]
[frontend.config :as config]
[frontend.context.i18n :refer [t]]
[frontend.db :as db]
Expand Down Expand Up @@ -552,8 +551,7 @@
main-content])

(when onboarding-and-home?
(onboarding/intro onboarding-and-home?))]]
(bottom-bar/bar)]))
(onboarding/intro onboarding-and-home?))]]]))

(defonce sidebar-inited? (atom false))
;; TODO: simplify logic
Expand Down
17 changes: 9 additions & 8 deletions src/main/frontend/handler/history.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@

(defn restore-app-state!
[state]
(let [route-match (:route-match state)
current-route (:route-match @state/state)
prev-route-data (get-route-data route-match)
current-route-data (get-route-data current-route)]
(when (and (not= prev-route-data current-route-data)
prev-route-data)
(route-handler/redirect! prev-route-data))
(swap! state/state merge state)))
(when-not (:history/page-only-mode? @state/state)
(let [route-match (:route-match state)
current-route (:route-match @state/state)
prev-route-data (get-route-data route-match)
current-route-data (get-route-data current-route)]
(when (and (not= prev-route-data current-route-data)
prev-route-data)
(route-handler/redirect! prev-route-data))
(swap! state/state merge state))))

(defn undo!
[e]
Expand Down
34 changes: 8 additions & 26 deletions src/main/frontend/modules/editor/undo_redo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
(:require [datascript.core :as d]
[frontend.db :as db]
[frontend.db.conn :as conn]
[frontend.handler.notification :as notification]
[frontend.modules.datascript-report.core :as db-report]
[frontend.util.page :as page-util]
[frontend.state :as state]
[clojure.set :as set]
[medley.core :as medley]))
Expand Down Expand Up @@ -31,22 +33,6 @@
[]
(-> (get-state) :redo-stack))

(defn- get-page-from-block
[stack]
(let [last-blocks (:blocks (last stack))]
(or (:db/id (some #(when (:block/name %) %) last-blocks))
(:db/id (some :block/page last-blocks)))))

(defn- get-history-page
[action]
(or
(:history/page @state/state)
(when-let [id (if (= :undo action)
(get-page-from-block @(get-undo-stack))
(get-page-from-block @(get-redo-stack)))]
(swap! state/state assoc :history/page id)
id)))

(defn push-undo
[txs]
(let [undo-stack (get-undo-stack)]
Expand Down Expand Up @@ -113,7 +99,7 @@
(defn- smart-pop-redo
[]
(if (:history/page-only-mode? @state/state)
(if-let [page-id (get-history-page :redo)]
(if-let [page-id (page-util/get-editing-page-id)]
(page-pop-redo page-id)
(pop-redo))
(pop-redo)))
Expand Down Expand Up @@ -163,7 +149,7 @@
(defn- smart-pop-undo
[]
(if (:history/page-only-mode? @state/state)
(if-let [page-id (get-history-page :undo)]
(if-let [page-id (page-util/get-editing-page-id)]
(page-pop-undo page-id)
(pop-undo))
(pop-undo)))
Expand Down Expand Up @@ -221,14 +207,10 @@

(defn toggle-undo-redo-mode!
[]
(if (:history/page-only-mode? @state/state)
(swap! state/state assoc
:history/page-only-mode? false
:history/page nil)
(when-let [page-id (get-history-page :undo)]
(swap! state/state assoc
:history/page-only-mode? true
:history/page page-id))))
(swap! state/state update :history/page-only-mode? not)
(let [mode (if (:history/page-only-mode? @state/state) "Page only" "Global")]
(notification/show!
[:p (str "Undo/redo mode: " mode)])))

(defn pause-listener!
[]
Expand Down
3 changes: 1 addition & 2 deletions src/main/frontend/state.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@
:whiteboard/onboarding-tour? (or (storage/get :whiteboard-onboarding-tour?) false)
:whiteboard/last-persisted-at {}
:whiteboard/pending-tx-data {}
:history/page-only-mode? false
:history/page nil})))
:history/page-only-mode? false})))

;; Block ast state
;; ===============
Expand Down
8 changes: 8 additions & 0 deletions src/main/frontend/util/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
(or (and page-name (:db/id (db/entity [:block/name page-name])))
(get-in (first (state/get-editor-args)) [:block :block/page :db/id]))))

(defn get-editing-page-id
"Fetch the editing page id. If there is an edit-input-id set, we are probably still
on editing mode"
[]
(if (or (state/editing?) (state/get-edit-input-id))
(get-in (first (state/get-editor-args)) [:block :block/page :db/id])
(get-current-page-id)))

(defn get-page-file-rpath
"Gets the file path of a page. If no page is given, detects the current page.
Returns nil if no file path is found or no page is detected or given"
Expand Down

0 comments on commit b613a9a

Please sign in to comment.