Skip to content

Commit

Permalink
Re-enable library
Browse files Browse the repository at this point in the history
  • Loading branch information
motform committed Aug 10, 2022
1 parent db6280e commit d32c462
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "shadow-cljs release --verbose app"
},
"devDependencies": {
"shadow-cljs": "^2.14.5"
"shadow-cljs": "^2.19.8"
},
"author": "",
"license": "ISC",
Expand Down
21 changes: 17 additions & 4 deletions resources/public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ textarea:focus {
.template-toggles {
align-self: flex-end;
background: var(--blurred-0);
border-radius: 9999px;
border-radius: 99999px;
padding: 0 10px;
}

Expand Down Expand Up @@ -1022,15 +1022,17 @@ h1 {

/* library */

.library-icon {
padding-top: 10px;
}

.library {
margin: var(--space-full) auto;
max-width: 1200px;
overflow: auto;
height: 85vh;
height: 90vh;
}



.library-button:hover {
background: var(--accent-25);
color: var(--bg);
Expand Down Expand Up @@ -1078,6 +1080,17 @@ h1 {
justify-content: center;
}

.library-delete-story {
background-color: darkred;
color: var(--fg);
padding: 6px 8px;
border-radius: 4px;
}

.library-delete-story:hover {
background-color: #9f0000;
}

.source-code {
color: var(--acccent-20);
}
Expand Down
13 changes: 8 additions & 5 deletions src/org/motform/multiverse/components/header.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
(let [active? (= key active-page)]
[:<>
[:a.hitem.tab.shadow-medium
{:class (str (case type :library "tab tab-secondary" :new-story " tab-new-story")
{:class (str (case type :library "tab tab-secondary library-icon" :new-story " tab-new-story")
(when active? " tab-active"))
:href (routes/url-for key)
:on-pointer-over #(reset! *visible? true)
:on-pointer-out #(reset! *visible? false)}
label]
(when (or @*visible? active?)
(when (and (= type :new-story)
(or @*visible? active?))
[:label.tab-label
{:class (when (and @*visible? (not active?)) "tab-label-inactive")}
"Add literary space"])]))))
Expand All @@ -39,9 +40,10 @@

(defn tabs []
(let [active-story-id @(rf/subscribe [:story/active])
active-page @(rf/subscribe [:page/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} @(rf/subscribe [:story/recent])]
(for [{:story/keys [id] :as story} stories]
^{:key id} [tab story active-story-id active-page])]))

(defn header []
Expand All @@ -50,4 +52,5 @@
[:section.header-content.h-stack.gap-half
[tabs]
[item :page/new-story active-page :new-story icon/plus]]
#_[]])) ;; TODO add about dialog
[item :page/library active-page :library (count @(rf/subscribe [:story/recent]))]]))

19 changes: 11 additions & 8 deletions src/org/motform/multiverse/components/library.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
(defn library-item [{:story/keys [meta sentences]}]
(let [{:story/keys [updated title id]} meta]
[:a.library-item.v-stack.spaced.gap-full.rounded.shadow-large.pad-half.border
{:href (routes/url-for :story)
:on-pointer-down #(do (rf/dispatch [:story/active id])
(rf/dispatch [:page/active :page/story])
(. (.-history js/window) pushState #js {} "" (routes/url-for :page/story)))}
[:h2 (if-not (str/blank? title) (util/title-case title) "Generating title...")]
[:section.h-stack.spaced.library-item-meta
[:div
{:href (routes/url-for :story)
:on-pointer-down #(do (rf/dispatch [:story/active id])
(rf/dispatch [:page/active :page/story])
(. (.-history js/window) pushState #js {} "" (routes/url-for :page/story)))}
[:h2 (if-not (str/blank? title) (util/title-case title) "Generating title...")]]
[:section.h-stack.spaced.library-item-meta.centered
[:p (str (count sentences) " sentences")]
[:p "Last explored " (util/format-date updated)]]]))
[:p.library-delete-story
{:on-pointer-down #(rf/dispatch [:story/delete id])}
"Delete Story"]]]))

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

(defn export-library
Expand Down
8 changes: 8 additions & 0 deletions src/org/motform/multiverse/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@
(fn [db _]
(assoc db :db/stories {})))

(reg-event-db
:story/delete
[local-storage-interceptor]
(fn [db [_ story-id]]
(-> db
(update :db/stories dissoc story-id)
(assoc-in [:db/state :story/active] nil))))

;;; OpenAI

(defn ->children
Expand Down

0 comments on commit d32c462

Please sign in to comment.