reference.cljs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. (ns frontend.components.reference
  2. (:require [rum.core :as rum]
  3. [frontend.util :as util]
  4. [frontend.state :as state]
  5. [clojure.string :as string]
  6. [frontend.db :as db]
  7. [frontend.components.block :as block]
  8. [frontend.ui :as ui]
  9. [frontend.components.content :as content]
  10. [frontend.date :as date]
  11. [frontend.components.editor :as editor]
  12. [frontend.db-mixins :as db-mixins]
  13. [clojure.string :as string]))
  14. (rum/defc references < rum/reactive db-mixins/query
  15. [page-name marker? priority?]
  16. (when page-name
  17. (let [block? (util/uuid-string? page-name)
  18. block-id (and block? (uuid page-name))
  19. page-name (string/lower-case page-name)
  20. journal? (date/valid-journal-title? (string/capitalize page-name))
  21. ref-blocks (cond
  22. priority?
  23. (db/get-blocks-by-priority (state/get-current-repo) page-name)
  24. marker?
  25. (db/get-marker-blocks (state/get-current-repo) page-name)
  26. block-id
  27. (db/get-block-referenced-blocks block-id)
  28. :else
  29. (db/get-page-referenced-blocks page-name))
  30. scheduled-or-deadlines (if journal?
  31. (db/get-date-scheduled-or-deadlines (string/capitalize page-name))
  32. nil)
  33. n-ref (count ref-blocks)]
  34. (when (or (> n-ref 0)
  35. (seq scheduled-or-deadlines))
  36. [:div.references.mt-6.flex-1.flex-row
  37. [:div.content
  38. (when (seq scheduled-or-deadlines)
  39. (ui/foldable
  40. [:h2.font-bold.opacity-50 (let []
  41. "SCHEDULED AND DEADLINE")]
  42. [:div.references-blocks.mb-6
  43. (let [ref-hiccup (block/->hiccup scheduled-or-deadlines
  44. {:id (str page-name "-agenda")
  45. :start-level 2
  46. :ref? true
  47. :group-by-page? true
  48. :editor-box editor/box}
  49. {})]
  50. (content/content page-name
  51. {:hiccup ref-hiccup}))]))
  52. (ui/foldable
  53. [:h2.font-bold.opacity-50 (let []
  54. (str n-ref " Linked References"))]
  55. [:div.references-blocks
  56. (let [ref-hiccup (block/->hiccup ref-blocks
  57. {:id page-name
  58. :start-level 2
  59. :ref? true
  60. :breadcrumb-show? true
  61. :group-by-page? true
  62. :editor-box editor/box}
  63. {})]
  64. (content/content page-name
  65. {:hiccup ref-hiccup}))])]]))))
  66. (rum/defcs unlinked-references-aux
  67. < rum/reactive db-mixins/query
  68. {:will-mount (fn [state]
  69. (let [[page-name n-ref] (:rum/args state)
  70. ref-blocks (db/get-page-unlinked-references page-name)]
  71. (reset! n-ref (count ref-blocks))
  72. (assoc state ::ref-blocks ref-blocks)))}
  73. [state page-name n-ref]
  74. (let [ref-blocks (::ref-blocks state)]
  75. [:div.references-blocks
  76. (let [ref-hiccup (block/->hiccup ref-blocks
  77. {:id (str page-name "-unlinked-")
  78. :start-level 2
  79. :ref? true
  80. :group-by-page? true
  81. :editor-box editor/box}
  82. {})]
  83. (content/content page-name
  84. {:hiccup ref-hiccup}))]))
  85. (rum/defcs unlinked-references < rum/reactive
  86. (rum/local nil ::n-ref)
  87. [state page-name]
  88. (let [n-ref (get state ::n-ref)]
  89. (when page-name
  90. (let [page-name (string/lower-case page-name)]
  91. [:div.references.mt-6.flex-1.flex-row
  92. [:div.content.flex-1
  93. (ui/foldable
  94. [:h2.font-bold {:style {:opacity "0.3"}}
  95. (if @n-ref
  96. (str @n-ref " Unlinked References")
  97. "Unlinked References")]
  98. (fn [] (unlinked-references-aux page-name n-ref))
  99. true)]]))))