Skip to content

Commit

Permalink
Fix bug where initial sentence was not active
Browse files Browse the repository at this point in the history
  • Loading branch information
motform committed Mar 27, 2022
1 parent b51c5cb commit 87aacc8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 44 deletions.
1 change: 0 additions & 1 deletion src/org/motform/multiverse/components/new_story.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
:on-pointer-down #(when (not blank?)
(rf/dispatch [:new-story/submit]) ; TODO move into route controller
(rf/dispatch [:page/active :page/story])
(rf/dispatch [:story/mode :mode/explore])
(. (.-history js/window) pushState #js {} "" (routes/url-for :page/story)))} ; TODO move into routing
"Explore"]]]))

Expand Down
48 changes: 11 additions & 37 deletions src/org/motform/multiverse/components/story.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,6 @@
(for [s (distinct (util/conj? paragraph prospect-path))]
^{:key (:sentence/id s)} [sentence s paragraph prospect-path])])}))

(defn comparative-paragraph [{:sentence/keys [id]}]
(let [sentences @(rf/subscribe [:sentence/paragraph id])
leaf-id (->> sentences last :sentence/id)]
[:div>div.comparsion-paragraph.shadow-large.pad-half.rounded.v-stack.gap-full
{:on-pointer-down #(do (rf/dispatch [:sentence/active leaf-id])
(rf/dispatch [:story/mode :mode/explore]))}
[:p (for [{:sentence/keys [text id personality]} sentences]
^{:key id} [:span text [branch-marks id personality]])]
[map/radial-map :source/compare @(rf/subscribe [:story/active])
{:active-sentence leaf-id
:active-path (->> sentences last :sentence/path set)
:highlight nil
:prospective-child? #{}}
{:h 250 :w 460}]]))

(defn comparsion []
(let [leaves @(rf/subscribe [:story/leafs])]
[:section.comparsion.gap-full
{:style {:grid-template-columns (str "repeat(" (count leaves) ", 500px)")}}
(for [leaf leaves]
^{:key (:sentence/id leaf)} [comparative-paragraph leaf])]))

(defn multiverse []
(let [active-sentence @(rf/subscribe [:sentence/active])
request? @(rf/subscribe [:open-ai/pending-request?])
Expand All @@ -129,18 +107,14 @@
(rf/dispatch [:open-ai/completions active-sentence (open-ai/format-prompt paragraphs)]))

[:main.h-stack.story
(case @(rf/subscribe [:story/mode])
:mode/reader [reader/literary paragraphs]
:mode/compare [comparsion]
:mode/explore
[:<>
(when paragraphs
[:section.h-stack.gap-half.story-views
[personality/toggles :page/story]
[paragraph paragraphs prospect-path]
[map/radial-map :source/story]])
(if request?
[:section.children.pad-full [util/spinner]]
[:section.children.h-equal-3.gap-double.pad-full
(for [{:sentence/keys [id text children personality]} children]
^{:key id} [child-selector text id (seq children) personality])])])]))
[:<>
(when paragraphs
[:section.h-stack.gap-half.story-views
[personality/toggles :page/story]
[paragraph paragraphs prospect-path]
[map/radial-map :source/story]])
(if request?
[:section.children.pad-full [util/spinner]]
[:section.children.h-equal-3.gap-double.pad-full
(for [{:sentence/keys [id text children personality]} children]
^{:key id} [child-selector text id (seq children) personality])])]]))
1 change: 0 additions & 1 deletion src/org/motform/multiverse/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
:new-story/template :template/blank
:story/active nil
:story/recent []
:story/mode :mode/explore ; #{:mode/explore :mode/reader :mode/compare}
:personality/active :personality/neutral
:sentence/active nil
:sentence/highlight {:id nil :source nil}
Expand Down
6 changes: 1 addition & 5 deletions src/org/motform/multiverse/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@
(assoc-in [:db/state :story/active] story-id)
(update-in [:db/state :story/recent] conj story-id))))

(reg-event-db
:story/mode
(fn [db [_ mode]]
(assoc-in db [:db/state :story/mode] mode)))

(reg-event-db
:sentence/active
(fn [db [_ id]]
Expand Down Expand Up @@ -152,6 +147,7 @@
(assoc-in [:db/stories story-id] (->story story-id sentence-id prompt active-personality))
(assoc-in [:db/state :story/active] story-id)
(assoc-in [:db/state :sentence/active] sentence-id)
(assoc-in [:db/state :sentence/highlight] {:id sentence-id :source :page/new-story})
(update-in [:db/state :story/recent] conj story-id))
:dispatch [:open-ai/title]})))

Expand Down

0 comments on commit 87aacc8

Please sign in to comment.