(ns frontend.handler.db-based.import "Handles DB graph imports" (:require [cljs.pprint :as pprint] [clojure.edn :as edn] [frontend.config :as config] [frontend.db :as db] [frontend.handler.notification :as notification] [frontend.handler.repo :as repo-handler] [frontend.handler.ui :as ui-handler] [frontend.persist-db :as persist-db] [frontend.state :as state] [frontend.util :as util] [logseq.db :as ldb] [logseq.db.sqlite.export :as sqlite-export] [logseq.db.sqlite.util :as sqlite-util] [logseq.shui.ui :as shui] [promesa.core :as p])) (defn import-from-sqlite-db! [buffer bare-graph-name finished-ok-handler] (let [graph (str config/db-version-prefix bare-graph-name)] (-> (p/do! (persist-db/ (p/do! (persist-db/ (p/do (db/transact! repo init-tx tx-meta) (when (seq block-props-tx) (db/transact! repo block-props-tx tx-meta)) (when (seq misc-tx) (db/transact! repo misc-tx tx-meta)) (when-not import-block? (ui-handler/re-render-root!) (notification/show! "Import successful!" :success))) (p/catch (fn [e] (js/console.error "Import EDN error: " e) (notification/show! "An unexpected error occurred during import. See the javascript console for details." :error)))))) ;; Also close cmd-k (shui/dialog-close-all!))))) (defn ^:export import-edn-data-dialog "Displays dialog which allows users to paste and import sqlite.build EDN Data" [] (let [import-inputs (atom {:import-data "" :import-block? false})] (shui/dialog-open! [:div [:label.flex.my-2.text-lg "Import EDN Data"] #_[:label.block.flex.items-center.py-3 (shui/checkbox {:on-checked-change #(swap! import-inputs update :import-block? not)}) [:small.pl-2 (str "Import into current block")]] (shui/textarea {:placeholder "{}" :class "overflow-y-auto" :rows 10 :auto-focus true :on-change (fn [^js e] (swap! import-inputs assoc :import-data (util/evalue e)))}) (shui/button {:class "mt-3" :on-click (partial import-edn-data-from-form import-inputs)} "Import")])))