Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buttons to generate a message list #4

Merged
merged 1 commit into from Oct 16, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

1,417 calcit.edn

Large diffs are not rendered by default.

@@ -20,6 +20,7 @@
"author": "jiyinyiyong",
"license": "MIT",
"dependencies": {
"dayjs": "^1.8.16",
"md5": "^2.2.1",
"randomcolor": "^0.5.4",
"shortid": "^2.2.15",
@@ -7,7 +7,7 @@
[cumulo/recollect "0.5.0"]
[cumulo/reel "0.1.1"]
[cumulo/util "0.1.10"]
[respo "0.10.12"]
[respo "0.10.13-a1"]
[respo/ui "0.3.13"]
[respo/alerts "0.3.13"]
[respo/message "0.3.4"]
@@ -1,5 +1,5 @@

(ns app.cache (:require ["path" :as path] ["fs" :as fs]))
(ns app.cache (:require ["path" :as path] ["fs" :as fs] [clojure.string :as string]))

(def books-cache
{"cicero" (string/split
@@ -67,7 +67,13 @@
(case (:name router)
:home (comp-home (:data router))
:profile (comp-profile (:user store) (:data router))
:reading (comp-reading-room (:book (:data router)) (:reading (:data router)))
:reading
(cursor->
:reading
comp-reading-room
states
(:book (:data router))
(:reading (:data router)))
(<> router))
(comp-login states))
(comp-status-color (:color store))
@@ -3,13 +3,18 @@
(:require [hsl.core :refer [hsl]]
[respo-ui.core :as ui]
[respo.comp.space :refer [=<]]
[respo.core :refer [defcomp <> action-> list-> button span div]]
[respo.core
:refer
[defcomp <> action-> cursor-> list-> button span div textarea]]
[app.config :as config]
[respo.util.list :refer [map-val]]))
[respo.util.list :refer [map-val]]
["dayjs" :as dayjs]
[respo-alerts.comp.alerts :refer [comp-prompt]]
[clojure.string :as string]))

(defcomp
comp-reading-room
(book reading)
(states book reading)
(if (nil? reading)
(div
{:style {:padding "24px 16px"}}
@@ -22,11 +27,59 @@
:inner-text "Start Reading",
:on-click (fn [e d! m!] (d! :reading/start (:id book)))})))
(div
{:style (merge ui/expand ui/column {:padding "16px"})}
(div {} (<> "Messages" {:font-family ui/font-fancy, :font-size 16}))
{:style (merge ui/expand ui/column {})}
(list->
{:style ui/expand}
{:style (merge ui/expand {:background-color (hsl 0 0 92), :padding "100px 16px 160px"})}
(->> (:messages reading)
(map-val
(fn [message] (div {} (<> "BOOK:") (<> (:text message)) (<> (:time message)))))))
(div {} (<> "toolbar")))))
(sort-by (fn [[k message]] (:time message)))
(map
(fn [[k message]]
[k
(if (or (= (:kind message) :hint) (= (:kind message) :content))
(div
{:style {:margin-bottom 12}}
(div
{}
(<> "BOOK" {:color (hsl 0 0 60)})
(=< 8 nil)
(<>
(-> (:time message) (dayjs) (.format "MM-DD HH:mm"))
{:font-size 12, :color (hsl 0 0 70)}))
(div
{:style {:background-color (hsl 0 0 100),
:padding 6,
:border-radius "4px",
:line-height "24px",
:max-width 600}}
(<> (:text message))))
(div
{:style ui/column}
(div {:style ui/row-parted} (span nil) (<> "Me"))
(div
{:style ui/row-parted}
(span nil)
(div
{:style {:background-color (hsl 0 0 100),
:padding 6,
:border-radius "4px",
:line-height "24px",
:max-width 600}}
(<> (:text message))))))]))))
(div
{:style (merge
ui/row-center
{:padding "16px", :border-top (str "1px solid " (hsl 0 0 90))})}
(button
{:style ui/button,
:inner-text "Next",
:on-click (fn [e d! m!] (d! :reading/next (:id book)))})
(=< 8 nil)
(cursor->
:note
comp-prompt
states
{:trigger (button {:style ui/button, :inner-text "Add note"}),
:multiline? true,
:button-text "Add note",
:validator (fn [x] (if (string/blank? x) "Need content" nil))}
(fn [result d! m!] (d! :reading/note {:book-id (:id book), :text result})))))))
@@ -17,5 +17,7 @@
:user/log-out user/log-out
:router/change router/change
:reading/start reading/touch-book
:reading/next reading/read-next
:reading/note reading/add-note
(do (println "Unknown op:" op) identity))]
(f db op-data sid op-id op-time)))
@@ -1,5 +1,59 @@

(ns app.updater.reading (:require [app.schema :as schema]))
(ns app.updater.reading
(:require [app.schema :as schema]
[app.cache :refer [books-cache]]
[clojure.string :as string]))

(defn add-note [db op-data sid op-id op-time]
(let [book-id (:book-id op-data)
text (:text op-data)
user-id (get-in db [:sessions sid :user-id])]
(update-in
db
[:users user-id :readings book-id]
(fn [reading]
(update
reading
:messages
(fn [messages]
(if (string/blank? text)
(do (println "Not accept empty content") messages)
(assoc
messages
op-id
(merge
schema/message
{:id op-id,
:time op-time,
:text text,
:kind :note,
:book-index (:progress reading)})))))))))

(defn read-next [db op-data sid op-id op-time]
(let [book-id op-data
user-id (get-in db [:sessions sid :user-id])
book-content (get books-cache book-id)]
(update-in
db
[:users user-id :readings book-id]
(fn [reading]
(if (< (:progress reading) (dec (count book-content)))
(-> reading
(update :progress inc)
(update
:messages
(fn [messages]
(assoc
messages
op-id
(merge
schema/message
{:kind :content,
:text (get book-content (:progress reading)),
:time op-time,
:id op-id,
:book-index (:progress reading)})))))
(do (println "Already finished book") reading))))))

(defn touch-book [db op-data sid op-id op-time]
(let [book-id op-data, user-id (get-in db [:sessions sid :user-id])]

Some generated files are not rendered by default. Learn more.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.