diff --git a/CHANGES.md b/CHANGES.md index 1cfbc1979f..3af59a49d2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -49,6 +49,7 @@ - Fix keep name of component equal to the shape name [Taiga #2341](https://tree.taiga.io/project/penpot/issue/2341) - Fix lossing changes when changing selection and an input was already changed [Taiga #2329](https://tree.taiga.io/project/penpot/issue/2329), [Taiga #2330](https://tree.taiga.io/project/penpot/issue/2330) - Fix blur input field when click on viewport [Taiga #2164](https://tree.taiga.io/project/penpot/issue/2164) +- Fix default page id in workspace [Taiga #2205](https://tree.taiga.io/project/penpot/issue/2205) ### :arrow_up: Deps updates diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 0be39e3096..bcf1bb0ac8 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -253,17 +253,24 @@ (->> (rx/of ::dwp/finalize) (rx/observe-on :async)))))) +(declare go-to-page) (defn initialize-page [page-id] (us/assert ::us/uuid page-id) (ptk/reify ::initialize-page + ptk/WatchEvent + (watch [_ state _] + (when-not (contains? (get-in state [:workspace-data :pages-index]) page-id) + (let [default-page-id (get-in state [:workspace-data :pages 0])] + (rx/of (go-to-page default-page-id))))) + ptk/UpdateEvent (update [_ state] (let [;; we maintain a cache of page state for user convenience ;; with the exception of the selection; when user abandon ;; the current page, the selection is lost - page (get-in state [:workspace-data :pages-index page-id]) + page-id (:id page) local (-> state (get-in [:workspace-cache page-id] workspace-local-default) (assoc :selected (d/ordered-set)))] diff --git a/frontend/src/app/main/ui/workspace.cljs b/frontend/src/app/main/ui/workspace.cljs index 1ccc80d5b6..7181f147fa 100644 --- a/frontend/src/app/main/ui/workspace.cljs +++ b/frontend/src/app/main/ui/workspace.cljs @@ -87,7 +87,8 @@ (mf/defc workspace-page [{:keys [file layout page-id] :as props}] - (mf/use-layout-effect + + (mf/use-layout-effect (mf/deps page-id) (fn [] (if (nil? page-id)