Skip to content

Commit

Permalink
feat: Remove personalities
Browse files Browse the repository at this point in the history
  • Loading branch information
motform committed Oct 5, 2024
1 parent e9c075b commit 6635fbd
Show file tree
Hide file tree
Showing 13 changed files with 470 additions and 573 deletions.
4 changes: 4 additions & 0 deletions .cljstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:files {:ignore #{"checkouts" "target"}}
:rules {:blank-lines {:max-consecutive 2
:insert-padding? false}
:functions {:enabled? false}}}
39 changes: 23 additions & 16 deletions src/org/motform/multiverse/components/app.cljs
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
(ns org.motform.multiverse.components.app
(:require [re-frame.core :as rf]
[org.motform.multiverse.components.header :refer [header]]
[org.motform.multiverse.components.landing :refer [landing]]
[org.motform.multiverse.components.library :refer [library]]
[org.motform.multiverse.components.new-story :refer [new-story]]
[org.motform.multiverse.components.story :refer [multiverse]]))
(:require
[org.motform.multiverse.components.header :refer [Header]]
[org.motform.multiverse.components.landing :refer [Landing]]
[org.motform.multiverse.components.library :refer [Library]]
[org.motform.multiverse.components.new-story :refer [NewStory]]
[org.motform.multiverse.components.story :refer [Multiverse]]
[re-frame.core :as rf]))

(defn active-page [page]

(defn active-page
[page]
(case page
:page/landing landing
:page/library library
:page/new-story new-story
:page/story multiverse))
:page/landing Landing
:page/library Library
:page/new-story NewStory
:page/story Multiverse))


(defn background-class [page]
(defn background-class
[page]
(case page
:page/landing
"background-landing"
(:page/new-story :page/story)
(str "background-" (name @(rf/subscribe [:personality/active]))
(str "background-neutral"
(when @(rf/subscribe [:open-ai/pending-request?]) " fast"))
"background-other"))

(defn app []

(defn app
[]
(let [page @(rf/subscribe [:page/active])
view (active-page page)]
view (active-page page)]
[:div.app-container.v-stack
{:class (background-class page)}
(when-not (= page :page/landing) [header])
(when-not (= page :page/landing) [Header])
[view]]))
30 changes: 15 additions & 15 deletions src/org/motform/multiverse/components/header.cljs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
(ns org.motform.multiverse.components.header
(:require [org.motform.multiverse.routes :as routes]
[org.motform.multiverse.components.map :as map]
[re-frame.core :as rf]
[org.motform.multiverse.icon :as icon]
[reagent.core :as r]))
(:require
[org.motform.multiverse.components.map :as map]
[org.motform.multiverse.icon :as icon]
[org.motform.multiverse.routes :as routes]
[re-frame.core :as rf]
[reagent.core :as r]))

(defn item [key active-page type label]
(defn Item [key active-page type label]
(let [*visible? (r/atom false)]
(fn [key active-page type label]
(let [active? (= key active-page)]
Expand All @@ -23,7 +24,7 @@
{:class (when (and @*visible? (not active?)) "tab-label-inactive")}
"Add literary space"])]))))

(defn tab [{:story/keys [title id]} active-story-id active-page]
(defn Tab [{:story/keys [title id]} active-story-id active-page]
[:div.tab.shadow-medium.tooltip-container.blurred
{:class (when (and (= active-page :page/story)
(= active-story-id id)) "tab-active")
Expand All @@ -36,21 +37,20 @@
[:p title]
(when (= id @(rf/subscribe [:tab/highlight]))
[:div.tab-map.rounded.shadow-large
[map/radial-map :source/header id {} {:w 400 :h 250}]])]])
[map/RadialMap :source/header id {} {:w 400 :h 250}]])]])

(defn tabs []
(defn Tabs []
(let [active-story-id @(rf/subscribe [:story/active])
active-page @(rf/subscribe [:page/active])
stories (->> @(rf/subscribe [:story/recent]) reverse (take 3))]
[:nav.tabs.h-stack.gap-half
(for [{:story/keys [id] :as story} stories]
^{:key id} [tab story active-story-id active-page])]))
^{:key id} [Tab story active-story-id active-page])]))

(defn header []
(defn Header []
(let [active-page @(rf/subscribe [:page/active])]
[:header.header.h-stack.spaced.pad-3-4
[:section.header-content.h-stack.gap-half
[tabs]
[item :page/new-story active-page :new-story icon/plus]]
[item :page/library active-page :library (count @(rf/subscribe [:story/recent]))]]))

[Tabs]
[Item :page/new-story active-page :new-story icon/plus]]
[Item :page/library active-page :library (count @(rf/subscribe [:story/recent]))]]))
22 changes: 11 additions & 11 deletions src/org/motform/multiverse/components/landing.cljs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
(ns org.motform.multiverse.components.landing
(:require
[clojure.string :as str]
[re-frame.core :as rf]
[org.motform.multiverse.routes :as routes]
[org.motform.multiverse.util :as util]))
[org.motform.multiverse.util :as util]
[re-frame.core :as rf]))

(defn elide [s n dots]
(apply str (concat
(take n s)
(repeat dots ".")
(drop (- (count s) n) s))))

(defn key-input-textarea [api-key validated?]
(defn KeyInputTextarea [api-key validated?]
[:textarea.key-input.shadow-medium.textarea-small.rounded.mono
{:value (if (< 10 (count api-key)) (elide api-key 3 16) api-key)
:spell-check false
Expand All @@ -23,33 +23,33 @@
(rf/dispatch [:page/active :page/new-story])
(rf/dispatch [:open-ai/validate-api-key])))}])

(defn key-input []
(defn KeyInput []
(let [{:open-ai/keys [api-key validated?]} @(rf/subscribe [:open-ai/key])]
[:article.key-input-container.v-stack.gap-quarter.rounded-large.shadow-large.blurred.pad-3-4.border
[:div.v-stack.gap-quarter
[:label.offset-label "OpenAI API key"]
[:div.h-stack.gap-half
[key-input-textarea api-key validated?]
[KeyInputTextarea api-key validated?]
[:button.open-ai-key-dispatch.rounded.shadow-small
{:disabled (str/blank? api-key)
:on-pointer-down #(when-not validated? (rf/dispatch [:open-ai/validate-api-key]))}
(if @(rf/subscribe [:open-ai/pending-request?])
[util/spinner-small]
"Check")]]]
"Check")]]]
[:a {:href (when validated?
(routes/url-for (if (empty? @(rf/subscribe [:db/stories])) :page/new-story :page/library)))}
[:button.open-ai-key-dispatch.rounded.shadow-small
{:disabled (not validated?)
:style {:width "100%" :margin-top "var(--space-half)"}}
"start"]]]))

(defn landing-blurb []
(defn LandingBlurb []
[:section.landing-blurb.v-stack.gap-half
[:h1 "Multiverse"]
[:p "A vision of the future of interactive generative literature. Non-linearly explore a literary space generated on the fly by OpenAI’s GPT family of machine learning langauge models. Read more "[:a {:href "https://motform.org/multiverse" :target "_blank"} "in my case study"] "."]
[:p "A vision of the future of interactive generative literature. Non-linearly explore a literary space generated on the fly by OpenAI’s GPT family of machine learning langauge models. Read more " [:a {:href "https://motform.org/multiverse" :target "_blank"} "in my case study"] "."]
[:p "Requires a GPT-4 enabled " [:a {:href "https://openai.com/api/" :target "_blank"} "OpenAI API key"] ". You will have to provide your own unless otherwise specified. Multiverse works best in fullscreen mode with toolbars disabled. All data is stored locally."]])

(defn landing []
(defn Landing []
[:div.landing-container.h-stack.gap-double
[landing-blurb]
[key-input]])
[LandingBlurb]
[KeyInput]])
33 changes: 17 additions & 16 deletions src/org/motform/multiverse/components/library.cljs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
(ns org.motform.multiverse.components.library
(:require [clojure.string :as str]
[re-frame.core :as rf]
[nano-id.core :refer [nano-id]]
[org.motform.multiverse.routes :as routes]
[org.motform.multiverse.util :as util]))
(:require
[clojure.string :as str]
[nano-id.core :refer [nano-id]]
[org.motform.multiverse.routes :as routes]
[org.motform.multiverse.util :as util]
[re-frame.core :as rf]))

(defn library-item [{:story/keys [meta sentences]}]
(let [{:story/keys [updated title id]} meta]
(defn LibraryItem [{:story/keys [meta sentences]}]
(let [{:story/keys [title id]} meta]
[:a.library-item.v-stack.spaced.gap-full.rounded.shadow-large.pad-half.border
[:div
[:div
{:href (routes/url-for :story)
:on-pointer-down #(do (rf/dispatch [:story/active id])
(rf/dispatch [:page/active :page/story])
Expand All @@ -20,10 +21,10 @@
{:on-pointer-down #(rf/dispatch [:story/delete id])}
"Delete Story"]]]))

(defn library-items []
(defn LibraryItems []
[:section.library-items
(for [story (reverse @(rf/subscribe [:db/stories]))]
^{:key (get-in story [:story/meta :story/id])} [library-item story])])
^{:key (get-in story [:story/meta :story/id])} [LibraryItem story])])

(defn export-library
"SOURCE: https://gist.github.com/zoren/cc74758198b503b1755b75d1a6b376e7"
Expand All @@ -37,7 +38,7 @@
(.click anchor)
(js/URL.revokeObjectURL edn-url)))

(defn library-toggles []
(defn LibraryToggles []
[:section.h-stack.spaced.centered
[:p>a.source-code {:href "https://github.com/motform/multiverse" :target "_bank"}
"Source code avalible on GitHub"]
Expand All @@ -50,15 +51,15 @@
{:on-pointer-down #(export-library)}
"export library"]]])

(defn empty-library []
(defn Empty []
[:section>p "The Library is empty, go" [:br]
[:a {:href (routes/url-for :page/new-story)} "explore"]
" a literary space."])

(defn library []
(defn Library []
[:main.library.v-stack.gap-double.pad-half
(if @(rf/subscribe [:db/stories])
[:<>
[library-items]
[library-toggles]]
[empty-library])])
[LibraryItems]
[LibraryToggles]]
[Empty])])
61 changes: 31 additions & 30 deletions src/org/motform/multiverse/components/map.cljs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
(ns org.motform.multiverse.components.map
(:require [cljsjs.d3]
[re-frame.core :as rf]
[reagent.core :as r]
[reagent.dom :as rdom]))
(:require
[cljsjs.d3]
[re-frame.core :as rf]
[reagent.core :as r]
[reagent.dom :as rdom]))

(defn link-class [{:keys [active-path active-sentence prospective-child? source]
{highlight :id} :highlight}]
(fn [link]
(let [target-id (.. link -target -data -name)
source-id (.. link -source -data -name)
has-children? (seq (.. link -target -data -children))
^string personality (.. link -target -data -personality)]
(str personality "-"
has-children? (seq (.. link -target -data -children))]
(str "neutral-"
(cond (active-path target-id) "tree-map-link-active"
has-children? "tree-map-link"
(= highlight source-id) "tree-map-link-prospective"
Expand All @@ -35,9 +35,8 @@
{highlight :id} :highlight}]
(fn [node]
(let [id (.. node -data -name)
parent-id (.. node -data -info)
^string personality (.. node -data -personality)]
(str personality "-"
parent-id (.. node -data -info)]
(str "neutral-"
(cond (= active-sentence id) (cond (not highlight) "tree-map-node-current"
(= highlight active-sentence) "tree-map-node-current"
(contains? active-path id) "tree-map-node-current-superseded"
Expand Down Expand Up @@ -105,27 +104,29 @@
(fn [this]
(draw-radial-map (rdom/dom-node this) (r/props this) map-id)))

(defn radial-map-d3 [opts]
(defn RadialMapD3 [opts]
(let [map-id (str "mapid-" (random-uuid))]
(r/create-class
{:display-name (str "radial-tree-map-" map-id)
:component-did-mount (redraw map-id)
:component-did-update (redraw map-id)
:reagent-render (fn []
[:section.radial-map
{:class (str "radial-map-" (-> opts :source name))}
[:svg {:id map-id}]])})))
{:display-name (str "radial-tree-map-" map-id)
:component-did-mount (redraw map-id)
:component-did-update (redraw map-id)
:reagent-render (fn []
[:section.radial-map
{:class (str "radial-map-" (-> opts :source name))}
[:svg {:id map-id}]])})))

(defn radial-map [source story-id settings dimensions]
(defn RadialMap [source story-id settings dimensions]
(fn []
[radial-map-d3 (merge {:dimensions dimensions
:sentence-tree @(rf/subscribe [:story/sentence-tree story-id])
:active-path @(rf/subscribe [:story/active-path story-id])
:active-sentence @(rf/subscribe [:sentence/active story-id])
:highlight @(rf/subscribe [:sentence/highlight])
:source source
:prospective-child? (->> @(rf/subscribe [:sentence/children @(rf/subscribe [:sentence/active story-id]) story-id])
(map :sentence/id)
set)
:root-sentence @(rf/subscribe [:story/root-sentence story-id])}
settings)]))
[RadialMapD3
(merge
{:dimensions dimensions
:sentence-tree @(rf/subscribe [:story/sentence-tree story-id])
:active-path @(rf/subscribe [:story/active-path story-id])
:active-sentence @(rf/subscribe [:sentence/active story-id])
:highlight @(rf/subscribe [:sentence/highlight])
:source source
:prospective-child? (->> @(rf/subscribe [:sentence/children @(rf/subscribe [:sentence/active story-id]) story-id])
(map :sentence/id)
set)
:root-sentence @(rf/subscribe [:story/root-sentence story-id])}
settings)]))
Loading

0 comments on commit 6635fbd

Please sign in to comment.