Skip to content

Implement Audio Sharing for Selected Text#992

Open
TheNonPirate wants to merge 3 commits into
sillsdev:mainfrom
TheNonPirate:feature/share-audio/377
Open

Implement Audio Sharing for Selected Text#992
TheNonPirate wants to merge 3 commits into
sillsdev:mainfrom
TheNonPirate:feature/share-audio/377

Conversation

@TheNonPirate

@TheNonPirate TheNonPirate commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Implementing #377. If there is audio timing data, this causes the share button when text is selected to open a modal that gives the user a choice between sharing text and sharing audio.

Summary by CodeRabbit

  • New Features

    • New audio export feature enables sharing selected verses as downloadable audio files
    • Share dialog utilizes native browser sharing capabilities when available, with seamless fallback to direct download for broad browser compatibility
  • Improvements

    • Share functionality now organized through a dedicated modal interface for enhanced user experience

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@TheNonPirate, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 48 minutes and 5 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dca2def1-1cce-4020-a376-918f73933d02

📥 Commits

Reviewing files that changed from the base of the PR and between 5ab1d1e and 9ee24f1.

📒 Files selected for processing (1)
  • src/lib/components/ShareSelector.svelte
📝 Walkthrough

Walkthrough

This PR introduces a new ShareSelector modal that lets users share selected verses as text or export them as trimmed audio. The modal replaces the previous VerseOnImage modal in the type registry, integrates with TextSelectionToolbar to trigger on verse selection, and wires into the layout for dispatch and rendering.

Changes

Audio and text sharing modal

Layer / File(s) Summary
Share modal type contract
src/lib/data/stores/view.ts
ModalType registry replaces VerseOnImage with new Share entry, establishing the modal dispatch contract.
ShareSelector modal component
src/lib/components/ShareSelector.svelte
Text sharing builds a message from selected verses and logs analytics. Audio sharing decodes the chapter audio, trims segments per verse using timing data, encodes via mediabunny (aac or opus), and attempts navigator.share with fallback to download. Modal positioning derives CSS from vertOffset, showModal() is exported, and two action buttons render.
Text selection toolbar integration
src/lib/components/TextSelectionToolbar.svelte
Imports modal and ModalType, updates TODO comment, and branches shareSelectedText() to open the Share modal when audio timing is available or falls back to direct text sharing.
Layout modal dispatch and rendering
src/routes/+layout.svelte
Imports ShareSelector, declares shareSelector state, extends modal dispatch to handle ModalType.Share, and renders the bound component.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ShareSelector
  participant TextShare as shareText
  participant AudioContext
  participant Mediabunny
  participant Navigator as navigator.share
  participant Fallback as Download link

  rect rgba(200, 150, 255, 0.5)
  User->>ShareSelector: Click Share Text
  ShareSelector->>ShareSelector: Build reference & message
  ShareSelector->>TextShare: shareText(filename, message)
  ShareSelector->>ShareSelector: logShareContent()
  end

  rect rgba(150, 200, 255, 0.5)
  User->>ShareSelector: Click Share Audio
  ShareSelector->>ShareSelector: pickSupportedAudioConfig()
  ShareSelector->>AudioContext: Decode chapter audio
  ShareSelector->>AudioContext: Extract & trim verse segments
  AudioContext->>Mediabunny: Encode trimmed audio
  Mediabunny->>ShareSelector: Return encoded blob
  ShareSelector->>Navigator: navigator.share({ files: [File] })
  alt Share succeeded
    Navigator->>User: Share dialog
  else Share unsupported
    ShareSelector->>Fallback: Create download link
    Fallback->>User: Trigger download
  end
  ShareSelector->>AudioContext: Close context
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • sillsdev/appbuilder-pwa#963: Both PRs modify the ModalType registry in view.ts and change the verse sharing infrastructure; this PR replaces VerseOnImage with Share, while the related PR introduced VerseOnImage.

Suggested reviewers

  • chrisvire
  • FyreByrd

Poem

🐰 A modal takes wing with audio and text,
Trimming verses in time, no mess, no vexed!
From TextSelectionToolbar to the root layout's dance,
ShareSelector opens—share files at a glance! 🎵

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main feature being implemented: audio sharing for selected text, which aligns with the PR's primary objective of adding audio sharing capability when timing data is available.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Currently it downloads rather than sharing the audio.
Audio will be downloaded if sharing fails, which occurs on most browsers.
@TheNonPirate TheNonPirate force-pushed the feature/share-audio/377 branch from e5d1011 to 5ab1d1e Compare June 11, 2026 21:31
@TheNonPirate TheNonPirate marked this pull request as ready for review June 11, 2026 21:34
@TheNonPirate TheNonPirate requested a review from FyreByrd June 11, 2026 21:34

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/lib/components/ShareSelector.svelte (1)

27-40: ⚡ Quick win

Extract shared text-share composition into one helper.

Lines 27-40 duplicate the same “selected verses → message → shareText + logShareContent” logic now also present in src/lib/components/TextSelectionToolbar.svelte (Lines 138-150). Centralizing this avoids drift in filename/message/analytics behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/components/ShareSelector.svelte` around lines 27 - 40, Extract the
repeated "selected verses → message → shareText + logShareContent" logic into a
single helper (e.g., export a function like composeAndShareSelectedText or
shareSelectedVerses) and replace the duplicate blocks in shareSelectedText (in
ShareSelector.svelte) and the corresponding handler in
TextSelectionToolbar.svelte to call that helper; the helper should accept the
selectedVerses object (or its derived book, collection, text, and reference),
scriptureConfig.name, and internally build the filename, message body, call
shareText(scriptureName, message, filename) and then call
logShareContent('Text', bookCol, bookAbbrev, reference) so both components share
identical filename/message/analytics behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/components/ShareSelector.svelte`:
- Around line 124-129: In shareAudio() in ShareSelector.svelte, modify the catch
after navigator.share(...) to detect a user-cancelled share (error.name ===
'AbortError' or error is a DOMException with name 'AbortError') and return early
so the download fallback is not triggered; only for other errors should the code
continue to createObjectURL(file) and trigger the anchor download. Ensure you
check error?.name and only fall through on non-AbortError cases.

---

Nitpick comments:
In `@src/lib/components/ShareSelector.svelte`:
- Around line 27-40: Extract the repeated "selected verses → message → shareText
+ logShareContent" logic into a single helper (e.g., export a function like
composeAndShareSelectedText or shareSelectedVerses) and replace the duplicate
blocks in shareSelectedText (in ShareSelector.svelte) and the corresponding
handler in TextSelectionToolbar.svelte to call that helper; the helper should
accept the selectedVerses object (or its derived book, collection, text, and
reference), scriptureConfig.name, and internally build the filename, message
body, call shareText(scriptureName, message, filename) and then call
logShareContent('Text', bookCol, bookAbbrev, reference) so both components share
identical filename/message/analytics behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 132775a3-fce6-4d3e-9c2d-793176254d92

📥 Commits

Reviewing files that changed from the base of the PR and between c6b8f04 and 5ab1d1e.

📒 Files selected for processing (5)
  • src/lib/components/ShareSelector.svelte
  • src/lib/components/TextSelectionToolbar.svelte
  • src/lib/components/VerseOnImage.svelte
  • src/lib/data/stores/view.ts
  • src/routes/+layout.svelte

Comment thread src/lib/components/ShareSelector.svelte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant