From 66fcaf0c1f43ecef937f36ae3b071cbbf45aa81b Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 25 Jul 2024 15:50:12 +0800 Subject: [PATCH] fix: remove import/export options for db graphs --- src/main/frontend/components/export.cljs | 80 ++++++++-------- src/main/frontend/components/imports.cljs | 111 +++++++++++----------- 2 files changed, 100 insertions(+), 91 deletions(-) diff --git a/src/main/frontend/components/export.cljs b/src/main/frontend/components/export.cljs index f8db2541e..9927928f4 100644 --- a/src/main/frontend/components/export.cljs +++ b/src/main/frontend/components/export.cljs @@ -18,44 +18,48 @@ (rum/defc export [] (when-let [current-repo (state/get-current-repo)] - [:div.export - [:h1.title (t :export)] - [:ul.mr-1 - [:li.mb-4 - [:a.font-medium {:on-click #(export/export-repo-as-edn! current-repo)} - (t :export-edn)]] - [:li.mb-4 - [:a.font-medium {:on-click #(export/export-repo-as-json! current-repo)} - (t :export-json)]] - (when (config/db-based-graph? current-repo) - [:li.mb-4 - [:a.font-medium {:on-click #(export/export-repo-as-sqlite-db! current-repo)} - (t :export-sqlite-db)]]) - (when (util/electron?) - [:li.mb-4 - [:a.font-medium {:on-click #(export/download-repo-as-html! current-repo)} - (t :export-public-pages)]]) - (when-not (mobile-util/native-platform?) - [:li.mb-4 - [:a.font-medium {:on-click #(export-text/export-repo-as-markdown! current-repo)} - (t :export-markdown)]]) - (when-not (mobile-util/native-platform?) - [:li.mb-4 - [:a.font-medium {:on-click #(export-opml/export-repo-as-opml! current-repo)} - (t :export-opml)]]) - (when-not (mobile-util/native-platform?) - [:li.mb-4 - [:a.font-medium {:on-click #(export/export-repo-as-roam-json! current-repo)} - (t :export-roam-json)]])] - [:a#download-as-edn-v2.hidden] - [:a#download-as-json-v2.hidden] - [:a#download-as-sqlite-db.hidden] - [:a#download-as-roam-json.hidden] - [:a#download-as-html.hidden] - [:a#download-as-zip.hidden] - [:a#export-as-markdown.hidden] - [:a#export-as-opml.hidden] - [:a#convert-markdown-to-unordered-list-or-heading.hidden]])) + (let [db-based? (config/db-based-graph? current-repo)] + [:div.export + [:h1.title (t :export)] + [:ul.mr-1 + (when-not db-based? + [:li.mb-4 + [:a.font-medium {:on-click #(export/export-repo-as-edn! current-repo)} + (t :export-edn)]]) + (when-not db-based? + [:li.mb-4 + [:a.font-medium {:on-click #(export/export-repo-as-json! current-repo)} + (t :export-json)]]) + (when (config/db-based-graph? current-repo) + [:li.mb-4 + [:a.font-medium {:on-click #(export/export-repo-as-sqlite-db! current-repo)} + (t :export-sqlite-db)]]) + (when-not db-based? + (when (util/electron?) + [:li.mb-4 + [:a.font-medium {:on-click #(export/download-repo-as-html! current-repo)} + (t :export-public-pages)]])) + (when-not (or (mobile-util/native-platform?) db-based?) + [:li.mb-4 + [:a.font-medium {:on-click #(export-text/export-repo-as-markdown! current-repo)} + (t :export-markdown)]]) + (when-not (or (mobile-util/native-platform?) db-based?) + [:li.mb-4 + [:a.font-medium {:on-click #(export-opml/export-repo-as-opml! current-repo)} + (t :export-opml)]]) + (when-not (or (mobile-util/native-platform?) db-based?) + [:li.mb-4 + [:a.font-medium {:on-click #(export/export-repo-as-roam-json! current-repo)} + (t :export-roam-json)]])] + [:a#download-as-edn-v2.hidden] + [:a#download-as-json-v2.hidden] + [:a#download-as-sqlite-db.hidden] + [:a#download-as-roam-json.hidden] + [:a#download-as-html.hidden] + [:a#download-as-zip.hidden] + [:a#export-as-markdown.hidden] + [:a#export-as-opml.hidden] + [:a#convert-markdown-to-unordered-list-or-heading.hidden]]))) (def *export-block-type (atom :text)) diff --git a/src/main/frontend/components/imports.cljs b/src/main/frontend/components/imports.cljs index aa9e66714..2e688baf0 100644 --- a/src/main/frontend/components/imports.cljs +++ b/src/main/frontend/components/imports.cljs @@ -374,7 +374,8 @@ (rum/defc importer < rum/reactive - [{:keys [query-params]}] + [{:keys [query-params]}] + (let [db-based? (config/db-based-graph? (state/get-current-repo))] (if (state/sub :graph/importing) (let [{:keys [total current-idx current-page]} (state/sub :graph/importing-state) left-label (if (and current-idx total (= current-idx total)) @@ -396,63 +397,67 @@ [:h1 (t :on-boarding/importing-title)] [:h2 (t :on-boarding/importing-desc)]] [:section.d.md:flex.flex-col - [:label.action-input.flex.items-center.mx-2.my-2 - [:span.as-flex-center [:i (svg/logo 28)]] - [:span.flex.flex-col - [[:strong "SQLite"] - [:small (t :on-boarding/importing-sqlite-desc)]]] - [:input.absolute.hidden - {:id "import-sqlite-db" - :type "file" - :on-change (fn [e] - (shui/dialog-open! - #(set-graph-name-dialog e {:sqlite? true})))}]] + (when db-based? + [:label.action-input.flex.items-center.mx-2.my-2 + [:span.as-flex-center [:i (svg/logo 28)]] + [:span.flex.flex-col + [[:strong "SQLite"] + [:small (t :on-boarding/importing-sqlite-desc)]]] + [:input.absolute.hidden + {:id "import-sqlite-db" + :type "file" + :on-change (fn [e] + (shui/dialog-open! + #(set-graph-name-dialog e {:sqlite? true})))}]]) - (when (or util/electron? util/web-platform?) - [:label.action-input.flex.items-center.mx-2.my-2 - [:span.as-flex-center [:i (svg/logo 28)]] - [:span.flex.flex-col - [[:strong "File to DB graph"] - [:small "Import a file-based Logseq graph folder into a new DB graph"]]] - [:input.absolute.hidden - {:id "import-file-graph" - :type "file" - :webkitdirectory "true" - :on-change (debounce (fn [e] - (import-file-to-db-handler e {})) - 1000)}]]) + (when (and db-based? (or util/electron? util/web-platform?)) + [:label.action-input.flex.items-center.mx-2.my-2 + [:span.as-flex-center [:i (svg/logo 28)]] + [:span.flex.flex-col + [[:strong "File to DB graph"] + [:small "Import a file-based Logseq graph folder into a new DB graph"]]] + [:input.absolute.hidden + {:id "import-file-graph" + :type "file" + :webkitdirectory "true" + :on-change (debounce (fn [e] + (import-file-to-db-handler e {})) + 1000)}]]) - [:label.action-input.flex.items-center.mx-2.my-2 - [:span.as-flex-center [:i (svg/logo 28)]] - [:span.flex.flex-col - [[:strong "EDN / JSON"] - [:small (t :on-boarding/importing-lsq-desc)]]] - [:input.absolute.hidden - {:id "import-lsq" - :type "file" - :on-change lsq-import-handler}]] + (when-not db-based? + [:label.action-input.flex.items-center.mx-2.my-2 + [:span.as-flex-center [:i (svg/logo 28)]] + [:span.flex.flex-col + [[:strong "EDN / JSON"] + [:small (t :on-boarding/importing-lsq-desc)]]] + [:input.absolute.hidden + {:id "import-lsq" + :type "file" + :on-change lsq-import-handler}]]) - [:label.action-input.flex.items-center.mx-2.my-2 - [:span.as-flex-center [:i (svg/roam-research 28)]] - [:div.flex.flex-col - [[:strong "RoamResearch"] - [:small (t :on-boarding/importing-roam-desc)]]] - [:input.absolute.hidden - {:id "import-roam" - :type "file" - :on-change roam-import-handler}]] + (when-not db-based? + [:label.action-input.flex.items-center.mx-2.my-2 + [:span.as-flex-center [:i (svg/roam-research 28)]] + [:div.flex.flex-col + [[:strong "RoamResearch"] + [:small (t :on-boarding/importing-roam-desc)]]] + [:input.absolute.hidden + {:id "import-roam" + :type "file" + :on-change roam-import-handler}]]) - [:label.action-input.flex.items-center.mx-2.my-2 - [:span.as-flex-center.ml-1 (ui/icon "sitemap" {:size 26})] - [:span.flex.flex-col - [[:strong "OPML"] - [:small (t :on-boarding/importing-opml-desc)]]] + (when-not db-based? + [:label.action-input.flex.items-center.mx-2.my-2 + [:span.as-flex-center.ml-1 (ui/icon "sitemap" {:size 26})] + [:span.flex.flex-col + [[:strong "OPML"] + [:small (t :on-boarding/importing-opml-desc)]]] - [:input.absolute.hidden - {:id "import-opml" - :type "file" - :on-change opml-import-handler}]]] + [:input.absolute.hidden + {:id "import-opml" + :type "file" + :on-change opml-import-handler}]])] (when (= "picker" (:from query-params)) [:section.e - [:a.button {:on-click #(route-handler/redirect-to-home!)} "Skip"]])]))) + [:a.button {:on-click #(route-handler/redirect-to-home!)} "Skip"]])]))))