Przeglądaj źródła

enhance(mobile): add favorite/unfavorite button

charlie 2 miesięcy temu
rodzic
commit
f682cec29d
1 zmienionych plików z 64 dodań i 47 usunięć
  1. 64 47
      src/main/mobile/components/modal.cljs

+ 64 - 47
src/main/mobile/components/modal.cljs

@@ -8,6 +8,7 @@
             [frontend.state :as state]
             [frontend.ui :as ui]
             [logseq.db.frontend.entity-util :as entity-util]
+            [logseq.shui.hooks :as hooks]
             [logseq.shui.silkhq :as silkhq]
             [logseq.shui.ui :as shui]
             [mobile.components.ui :as mobile-ui]
@@ -21,7 +22,13 @@
   (let [[{:keys [open? block]}] (mobile-state/use-singleton-modal)
         close! #(swap! mobile-state/*singleton-modal assoc :open? false)
         block (when-let [id (:block/uuid block)]
-                (db/entity [:block/uuid id]))]
+                (db/entity [:block/uuid id]))
+        [favorited? set-favorited!] (hooks/use-state false)]
+
+    (hooks/use-effect!
+      (fn []
+        (set-favorited! (page-handler/favorited? (str (:block/uuid block)))))
+      [block])
 
     (when open?
       (state/clear-edit!)
@@ -41,51 +48,61 @@
        (silkhq/bottom-sheet-backdrop)
        (silkhq/bottom-sheet-content
         {:class "app-silk-sheet-scroll-content"}
-        (silkhq/scroll {:as-child true}
-                       (silkhq/scroll-view
-                        {:class "app-silk-scroll-view"}
-                        (silkhq/scroll-content
-                         {:class "app-silk-scroll-content"}
-                         [:div.app-silk-scroll-content-inner
-                          [:div.flex.justify-between.items-center.block-modal-page-header
-                           [:a.opacity-40.active:opacity-60.px-2
-                            {:on-pointer-down close!}
-                            (shui/tabler-icon "chevron-down" {:size 18 :stroke 3})]
-                           [:a.opacity-40.active:opacity-60.pr-1
-                            {:on-pointer-down (fn []
-                                                (mobile-ui/open-popup!
-                                                 (fn []
-                                                   [:div.-mx-2
-                                                    (ui/menu-link
-                                                     {:on-click #(mobile-ui/close-popup!)}
-                                                     [:span.text-lg.flex.gap-2.items-center
-                                                      (shui/tabler-icon "copy" {:class "opacity-80" :size 22})
-                                                      "Copy"])
+         (silkhq/scroll {:as-child true}
+           (silkhq/scroll-view
+             {:class "app-silk-scroll-view"}
+             (silkhq/scroll-content
+               {:class "app-silk-scroll-content"}
+               [:div.app-silk-scroll-content-inner
+                [:div.flex.justify-between.items-center.block-modal-page-header
+                 [:a.opacity-40.active:opacity-60.px-2
+                  {:on-pointer-down close!}
+                  (shui/tabler-icon "chevron-down" {:size 18 :stroke 3})]
+
+                 [:span.flex.items-center.gap-2
+                  (when-let [block-id-str (str (:block/uuid block))]
+                    [:a.active:opacity-80.pr-1
+                     {:class (if favorited? "opacity-80 !text-yellow-800" "opacity-40")
+                      :on-click #(-> (if favorited?
+                                       (page-handler/<unfavorite-page! block-id-str)
+                                       (page-handler/<favorite-page! block-id-str))
+                                   (p/then (fn [] (set-favorited! (not favorited?)))))}
+                     (shui/tabler-icon (if favorited? "star-filled" "star") {:size 18 :stroke 2})])
+                  [:a.opacity-40.active:opacity-60.pr-1
+                   {:on-pointer-down (fn []
+                                       (mobile-ui/open-popup!
+                                         (fn []
+                                           [:div.-mx-2
+                                            (ui/menu-link
+                                              {:on-click #(mobile-ui/close-popup!)}
+                                              [:span.text-lg.flex.gap-2.items-center
+                                               (shui/tabler-icon "copy" {:class "opacity-80" :size 22})
+                                               "Copy"])
 
-                                                    (ui/menu-link
-                                                     {:on-click #(-> (shui/dialog-confirm!
-                                                                      (str "⚠️ Are you sure you want to delete this "
-                                                                           (if (entity-util/page? block) "page" "block")
-                                                                           "?"))
-                                                                     (p/then
-                                                                      (fn []
-                                                                        (mobile-ui/close-popup!)
-                                                                        (some->
-                                                                         (:block/uuid block)
-                                                                         (page-handler/<delete!
-                                                                          (fn [] (close!))
-                                                                          {:error-handler
-                                                                           (fn [{:keys [msg]}]
-                                                                             (notification/show! msg :warning))})))))}
-                                                     [:span.text-lg.flex.gap-2.items-center.text-red-700
-                                                      (shui/tabler-icon "trash" {:class "opacity-80" :size 22})
-                                                      "Delete"])])
-                                                 {:title "Actions"
-                                                  :type :action-sheet}))}
-                            (shui/tabler-icon "dots-vertical" {:size 18 :stroke 2})]]
+                                            (ui/menu-link
+                                              {:on-click #(-> (shui/dialog-confirm!
+                                                                (str "⚠️ Are you sure you want to delete this "
+                                                                  (if (entity-util/page? block) "page" "block")
+                                                                  "?"))
+                                                            (p/then
+                                                              (fn []
+                                                                (mobile-ui/close-popup!)
+                                                                (some->
+                                                                  (:block/uuid block)
+                                                                  (page-handler/<delete!
+                                                                    (fn [] (close!))
+                                                                    {:error-handler
+                                                                     (fn [{:keys [msg]}]
+                                                                       (notification/show! msg :warning))})))))}
+                                              [:span.text-lg.flex.gap-2.items-center.text-red-700
+                                               (shui/tabler-icon "trash" {:class "opacity-80" :size 22})
+                                               "Delete"])])
+                                         {:title "Actions"
+                                          :type :action-sheet}))}
+                   (shui/tabler-icon "dots-vertical" {:size 18 :stroke 2})]]]
 
-                   ;; block page content
-                          [:div.block-modal-page-content
-                           (when open?
-                             (mobile-ui/classic-app-container-wrap
-                              (page/page-cp (db/entity [:block/uuid (:block/uuid block)]))))]])))))))))
+                ;; block page content
+                [:div.block-modal-page-content
+                 (when open?
+                   (mobile-ui/classic-app-container-wrap
+                     (page/page-cp (db/entity [:block/uuid (:block/uuid block)]))))]])))))))))