feat(mobile): audio record && transcribe (#12105)

* feat: audio transcribe

* enhance(mobile): auto start recording on initialization

* fix(mobile): can't delete journal from selection bar

* fix: duplicated audio record buttons in quick add

* fix(mobile): inactive bottom tab color

* enhance(mobile): display no results when there's no matched items

* enhance(mobile): add audio transcription feature and enhance audio component

* fix: store assets directly instead in today page instead of node ref

* save transcribed text to audio's child block

* enhance: transcribe supports punctuations and being offline only

* fix(mobile): save assets to current editing page

---------

Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
This commit is contained in:
Charlie
2025-09-16 16:09:29 +08:00
committed by GitHub
parent ecc182879a
commit e103593c0d
31 changed files with 640 additions and 463 deletions

View File

@@ -912,17 +912,25 @@
block (first blocks)
block-parent (get uuid->dom-block (:block/uuid block))
sibling-block (when block-parent (util/get-prev-block-non-collapsed-non-embed block-parent))
blocks' (block-handler/get-top-level-blocks blocks)]
blocks' (block-handler/get-top-level-blocks blocks)
mobile? (util/capacitor-new?)]
(p/do!
(when (and sibling-block (not (util/capacitor-new?)))
(when (and sibling-block (not mobile?))
(let [{:keys [edit-block-f]} (move-to-prev-block repo sibling-block
(get block :block/format :markdown)
"")]
(state/set-state! :editor/edit-block-fn edit-block-f)))
(ui-outliner-tx/transact!
{:outliner-op :delete-blocks
:mobile-action-bar? mobile-action-bar?}
(outliner-op/delete-blocks! blocks' nil))))))
(let [journals (and mobile? (filter ldb/journal? blocks'))
blocks (remove (fn [b] (contains? (set (map :db/id journals)) (:db/id b))) blocks)]
(when (or (seq journals) (seq blocks))
(ui-outliner-tx/transact!
{:outliner-op :delete-blocks
:mobile-action-bar? mobile-action-bar?}
(when (seq blocks)
(outliner-op/delete-blocks! blocks nil))
(when (seq journals)
(doseq [journal journals]
(outliner-op/delete-page! (:block/uuid journal)))))))))))
(defn set-block-timestamp!
[block-id key value]
@@ -1493,7 +1501,7 @@
"Save incoming(pasted) assets to assets directory.
Returns: asset entity"
[repo files & {:keys [pdf-area?]}]
[repo files & {:keys [pdf-area? last-edit-block]}]
(p/let [[repo-dir asset-dir-rpath] (assets-handler/ensure-assets-dir! repo)]
(p/all
(for [[_index ^js file] (map-indexed vector files)]
@@ -1524,19 +1532,23 @@
:edit-block? false
:properties properties}
_ (db-based-save-asset! repo dir file file-rpath)
edit-block (state/get-edit-block)
edit-block (or (state/get-edit-block) last-edit-block)
today-page-name (date/today)
today-page-e (db-model/get-journal-page today-page-name)
today-page (if (nil? today-page-e)
(state/pub-event! [:page/create today-page-name])
today-page-e)
insert-to-current-block-page? (and (:block/uuid edit-block) (string/blank? (state/get-edit-content)) (not pdf-area?))
insert-opts' (if insert-to-current-block-page?
(assoc insert-opts
:block-uuid (:block/uuid edit-block)
:replace-empty-target? true
:sibling? true)
(assoc insert-opts :page (:block/uuid asset)))
result (api-insert-new-block! file-name-without-ext insert-opts')
new-entity (db/entity [:block/uuid (:block/uuid result)])]
(assoc insert-opts :page (:block/uuid today-page)))
new-block (api-insert-new-block! file-name-without-ext insert-opts')]
(when insert-to-current-block-page?
(state/clear-edit!))
(or new-entity
(or new-block
(throw (ex-info "Can't save asset" {:files files}))))))))))
(def insert-command! editor-common-handler/insert-command!)

View File

@@ -219,9 +219,6 @@
(defmethod handle :mobile/keyboard-will-show [[_ keyboard-height]]
(let [_main-node (util/app-scroll-container-node)]
(state/set-state! :mobile/show-action-bar? false)
(when (= (state/sub :editor/record-status) "RECORDING")
(state/set-state! :mobile/show-recording-bar? true))
(when-let [^js html (js/document.querySelector ":root")]
(.setProperty (.-style html) "--ls-native-kb-height" (str keyboard-height "px"))
(.add (.-classList html) "has-mobile-keyboard")
@@ -234,8 +231,6 @@
(defmethod handle :mobile/keyboard-will-hide [[_]]
(let [main-node (util/app-scroll-container-node)]
(when (= (state/sub :editor/record-status) "RECORDING")
(state/set-state! :mobile/show-recording-bar? false))
(when-let [^js html (js/document.querySelector ":root")]
(.removeProperty (.-style html) "--ls-native-kb-height")
(.setProperty (.-style html) "--ls-native-toolbar-opacity" 0)

View File

@@ -342,13 +342,13 @@
format (state/get-preferred-format repo)
db-based? (config/db-based-graph? repo)
create-f (fn []
(p/do!
(<create! title {:redirect? false
:split-namespace? false
:today-journal? true})
(when-not db-based? (state/pub-event! [:journal/insert-template today-page]))
(ui-handler/re-render-root!)
(plugin-handler/hook-plugin-app :today-journal-created {:title today-page})))]
(p/let [result (<create! title {:redirect? false
:split-namespace? false
:today-journal? true})]
(when-not db-based? (state/pub-event! [:journal/insert-template today-page]))
(ui-handler/re-render-root!)
(plugin-handler/hook-plugin-app :today-journal-created {:title today-page})
result))]
(when-not (db/get-page today-page)
(if db-based?
(create-f)