recent.cljs 1.1 KB

1234567891011121314151617181920212223242526272829
  1. (ns frontend.handler.db-based.recent
  2. "Fns related to recent pages feature"
  3. (:require [frontend.db :as db]
  4. [frontend.state :as state]
  5. [logseq.graph-parser.util :as gp-util]
  6. [clojure.string :as string]))
  7. (defn add-page-to-recent!
  8. [repo page click-from-recent?]
  9. (when-not (:db/restoring? @state/state)
  10. (when-let [page-uuid (if (uuid? page)
  11. nil
  12. (:block/uuid (db/entity [:block/name (gp-util/page-name-sanity-lc page)])))]
  13. (let [pages (or (db/get-key-value repo :recent/pages)
  14. '())]
  15. (when (or (and click-from-recent? (not ((set pages) page-uuid)))
  16. (not click-from-recent?))
  17. (let [new-pages (take 15 (distinct (cons page-uuid pages)))]
  18. (db/set-key-value repo :recent/pages new-pages)))))))
  19. (defn get-recent-pages
  20. []
  21. (->> (db/sub-key-value :recent/pages)
  22. (distinct)
  23. (map (fn [id]
  24. (let [e (db/entity [:block/uuid id])]
  25. (or (:block/original-name e)
  26. (:block/uuid e)))))
  27. (remove string/blank?)))