Skip to content

Commit

Permalink
Load notebook contents initially
Browse files Browse the repository at this point in the history
  • Loading branch information
zampino committed Aug 9, 2023
1 parent 39b64c3 commit 12bb236
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
4 changes: 4 additions & 0 deletions notebooks/test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
;; # Ahoi
(ns test)

123
35 changes: 21 additions & 14 deletions src/nextjournal/clerk/render/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
{:key "Escape"
:run #(reset! !show-docstring? false)}]))]))
@!container-el))]
#_(show-notebook view)
(show-notebook view)
#(.destroy view))))
(code/use-dark-mode !view)
[:<>
Expand Down Expand Up @@ -362,19 +362,26 @@
"Shift-Alt-d" #'doc}]]]))

(defn root []
[view ";; # Ahoi"
{:eval-notebook-fn (fn [str]
(js/console.log :eval str )
(.. (render/clerk-eval
(list 'do
(list 'println "Saving...")
(list 'spit "notebooks/test.clj" str)
(list 'println "Saved...")
(list 'nextjournal.clerk/show! "notebooks/test.clj")
:evaled))
;; FIXME: eval-reply
(then (fn [r] (js/console.log :evaled r)))
(catch (fn [e] (js/console.log :error e)))))}])
(let [!doc-str (hooks/use-state nil)]
(hooks/use-effect
(fn []
(.then (render/clerk-eval (list 'slurp "notebooks/test.clj"))
(fn [doc-str] (reset! !doc-str doc-str)))))
(if @!doc-str
[view @!doc-str
{:eval-notebook-fn (fn [str]
(js/console.log :eval str)
(.. (render/clerk-eval
(list 'do
(list 'println "Saving...")
(list 'spit "notebooks/test.clj" str)
(list 'println "Saved...")
(list 'nextjournal.clerk/show! "notebooks/test.clj")
:evaled))
;; FIXME: eval-reply
(then (fn [r] (js/console.log :evaled r)))
(catch (fn [e] (js/console.log :error e)))))}]
[spinner-svg])))

(defn ^:export init []
(.render (react-client/createRoot (js/document.getElementById "editor"))
Expand Down
1 change: 0 additions & 1 deletion src/nextjournal/clerk/view.clj
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ viewer.init(viewer.read_string(state))\n"
(include-viewer-css state)
(include-css+js state))]
[:body.dark:bg-gray-900
[:h1 "Ahoi "]
[:div#editor]
[:script {:type "module"}
(str "nextjournal.clerk.render.editor.init()\n"
Expand Down

0 comments on commit 12bb236

Please sign in to comment.