Browse Source

feat: whiteboard edited time on dashboard

Peng Xiao 3 years ago
parent
commit
7d33c3ab7c

+ 14 - 13
src/main/frontend/components/whiteboard.cljs

@@ -90,11 +90,12 @@
      page-name)))
 
 ;; This is not accurate yet
-;; (defn- get-page-human-update-time
-;;   [page-name]
-;;   (let [page-entity (model/get-page page-name)
-;;         updated-at (:block/updated-at page-entity)]
-;;     (str "Edited at " (util/time-ago (js/Date. updated-at)))))
+(defn- get-page-human-update-time
+  [page-name]
+  (let [page-entity (model/get-page page-name)
+        {:block/keys [updated-at created-at]} page-entity]
+    (str (if (= created-at updated-at) "Created " "Edited ")
+         (util/time-ago (js/Date. updated-at)))))
 
 (rum/defc dashboard-preview-card
   [page-name]
@@ -105,17 +106,15 @@
       (route-handler/redirect-to-whiteboard! page-name))}
    [:div.dashboard-card-title
     [:div.flex.w-full
-     [:div.dashboard-card-title-name
+     [:div.dashboard-card-title-name.font-bold
       (if (parse-uuid page-name)
         [:span.opacity-50 (t :untitled)]
         (get-page-display-name page-name))]
+     [:div.flex-1]]
+    [:div.flex.w-full.opacity-50
+     [:div (get-page-human-update-time page-name)]
      [:div.flex-1]
-     (page-refs-count page-name nil)]
-    ;; [:div.flex.w-full
-    ;;  [:div (get-page-human-update-time page-name)]
-    ;;  [:div.flex-1]
-    ;;  (page-refs-count page-name)]
-    ]
+     (page-refs-count page-name nil)]]
    [:div.p-4.h-64.flex.justify-center
     (tldraw-preview page-name)]])
 
@@ -150,7 +149,9 @@
 
 (rum/defc whiteboard-dashboard
   []
-  (let [whiteboards (model/get-all-whiteboards (state/get-current-repo))
+  (let [whiteboards (->> (model/get-all-whiteboards (state/get-current-repo))
+                         (sort-by :block/updated-at)
+                         reverse)
         whiteboard-names (map :block/name whiteboards)
         ref (rum/use-ref nil)
         rect (use-component-size ref)

+ 1 - 1
src/main/frontend/components/whiteboard.css

@@ -51,7 +51,7 @@
 }
 
 .dashboard-card-title {
-  @apply px-4 py-1 flex flex-col;
+  @apply px-4 py-3 flex flex-col;
   gap: 4px;
   border-bottom: 1px solid var(--ls-border-color);
   background-color: var(--ls-secondary-background-color);

+ 7 - 3
src/main/frontend/handler/whiteboard.cljs

@@ -3,6 +3,7 @@
             [frontend.db.model :as model]
             [frontend.db.utils :as db-utils]
             [frontend.handler.editor :as editor-handler]
+            [frontend.modules.outliner.core :as outliner]
             [frontend.modules.outliner.file :as outliner-file]
             [frontend.state :as state]
             [frontend.util :as util]
@@ -55,9 +56,12 @@
 
 (defn- tldr-page->blocks-tx [page-name tldr-data]
   (let [page-name (util/page-name-sanity-lc page-name)
-        page-block {:block/name page-name
-                    :block/whiteboard? true
-                    :block/properties (dissoc tldr-data :shapes)}
+        page-entity (model/get-page page-name)
+        page-block (merge {:block/name page-name
+                           :block/whiteboard? true
+                           :block/properties (dissoc tldr-data :shapes)}
+                          (when page-entity (select-keys page-entity [:block/created-at])))
+        page-block (outliner/block-with-timestamps page-block)
         ;; todo: use get-paginated-blocks instead?
         existing-blocks (model/get-page-blocks-no-cache (state/get-current-repo)
                                                         page-name

+ 1 - 1
src/main/frontend/modules/outliner/core.cljs

@@ -48,7 +48,7 @@
      db/pull
      block)))
 
-(defn- block-with-timestamps
+(defn block-with-timestamps
   [block]
   (let [updated-at (util/time-ms)
         block (cond->