Skip to content

feat: Add download list in the example app - #3

Closed
syed-tp wants to merge 1 commit into
feat/expose_download_modulefrom
app/add_download_list
Closed

feat: Add download list in the example app#3
syed-tp wants to merge 1 commit into
feat/expose_download_modulefrom
app/add_download_list

Conversation

@syed-tp

@syed-tp syed-tp commented Jun 17, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added a new downloads management screen where users can view, pause, resume, or delete video downloads.
    • Introduced a "Show Downloads" button in the main app to access the downloads screen.
    • Download progress, status, and actions are now visible and manageable from a dedicated interface.
  • User Interface
    • Improved navigation with an optional back button and clear loading indicators.
    • Enhanced error handling with user alerts for download-related issues.

@codetortoiseai

Copy link
Copy Markdown

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 17, 2025

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

A new DownloadExample React Native component is added to manage and display video downloads using react-native-tpstreams. The main app is updated to include a "Show Downloads" button, which conditionally renders the DownloadExample component. The download manager supports listing, pausing, resuming, and deleting downloads, with appropriate UI and error handling.

Changes

File(s) Change Summary
example/DownloadExample.tsx Introduced new DownloadExample component for managing video downloads, with UI and controls.
example/src/App.tsx Added state and UI to show/hide the DownloadExample component via a "Show Downloads" button.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant DownloadExample
    participant TPStreams

    User->>App: Tap "Show Downloads"
    App->>DownloadExample: Render component (onBack callback)
    DownloadExample->>TPStreams: Fetch downloads on mount
    TPStreams-->>DownloadExample: Return downloads list
    DownloadExample->>User: Display downloads list

    User->>DownloadExample: Tap Pause/Resume/Delete on a download
    DownloadExample->>TPStreams: Call pause/resume/cancel API
    TPStreams-->>DownloadExample: Return updated status
    DownloadExample->>TPStreams: Refresh downloads list
    TPStreams-->>DownloadExample: Return updated downloads
    DownloadExample->>User: Update UI

    User->>DownloadExample: Tap Back
    DownloadExample->>App: Call onBack()
    App->>App: Hide DownloadExample, show main UI
Loading

Poem

In the warren of code, a new path appears,
Downloads now managed, with buttons and cheers!
Pause, resume, or cancel—just tap and see,
A list of your streams, as easy as can be.
With a hop and a click, your content’s in sight,
This rabbit’s delighted—downloads done right! 🐇✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai

coderabbitai Bot commented Jun 17, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
example/DownloadExample.tsx (3)

37-59: Avoid full refresh after every action

handlePauseResume and handleCancel re-invoke loadDownloads, triggering a network/bridge round-trip and UI flicker for every small action.
Optimistically update the affected list item locally, then fall back to loadDownloads on failure, e.g.:

setDownloads((prev) =>
  prev.map((d) =>
    d.videoId === item.videoId
      ? { ...d, state: nextState }
      : d,
  ),
);

This keeps the UI snappy and saves bridge calls.


126-128: Use ActivityIndicator instead of plain text for loading

<Text>Loading...</Text> gives no visual feedback on iOS dark mode and feels static.
Replace it with the platform-native ActivityIndicator.

- {loading ? (
-   <Text style={styles.loading}>Loading...</Text>
+ {loading ? (
+   <ActivityIndicator size="large" style={styles.loading} />

A11y-friendly and instantly recognisable by users.


92-110: Add accessibility labels to interactive elements

The TouchableOpacity buttons currently miss accessibilityLabel / accessibilityRole.
Screen-reader users will only hear “button”. Provide meaningful labels:

<TouchableOpacity
   style={styles.button}
   onPress={() => handlePauseResume(item)}
+  accessibilityRole="button"
+  accessibilityLabel={isPaused ? "Resume download" : "Pause download"}
>

Same for the “Delete” and “Refresh” buttons.

example/src/App.tsx (1)

185-195: Consider using a navigator instead of manual boolean toggling

As the example app grows, controlling screens with booleans will quickly become unmanageable and breaks back-gesture handling on Android/iOS.
Integrating a lightweight navigator (@react-navigation/native-stack) provides:

• proper history stack
• platform back-button support
• cleaner component structure

The change can be incremental: wrap the current views in two simple stack screens (Player, Downloads) and swap setShowDownloads(true) with navigation.navigate('Downloads').

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f64d34d and c76c9fc.

📒 Files selected for processing (2)
  • example/DownloadExample.tsx (1 hunks)
  • example/src/App.tsx (3 hunks)
🔇 Additional comments (1)
example/src/App.tsx (1)

104-107: Great use of early return to integrate the new screen

The conditional early return keeps the main component readable and isolates the download UI.
Nice, concise solution. 👍

Comment on lines +37 to +46
const handlePauseResume = async (item: DownloadItem) => {
try {
if (item.state === 1) {
// DOWNLOADING
await TPStreamsDownload.pauseDownload(item.videoId);
} else if (item.state === 2) {
// PAUSED
await TPStreamsDownload.resumeDownload(item.videoId);
}
loadDownloads();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace magic numbers with typed enum / constants

Using raw state codes (1, 2, etc.) lowers readability and is brittle if the SDK ever changes.
Expose descriptive constants once and reuse them:

// ideally exported by SDK, otherwise create locally
enum DownloadState {
  Idle = 0,
  Downloading = 1,
  Paused = 2,
  Completed = 3,
  Failed = 4,
}

if (item.state === DownloadState.Downloading) {
  await TPStreamsDownload.pauseDownload(item.videoId);
} else if (item.state === DownloadState.Paused) {
  await TPStreamsDownload.resumeDownload(item.videoId);
}

This also simplifies getStateText.

🤖 Prompt for AI Agents
In example/DownloadExample.tsx around lines 37 to 46, replace the raw numeric
state codes (like 1 and 2) with a typed enum or constants to improve readability
and maintainability. Define a DownloadState enum with descriptive names for each
state (Idle, Downloading, Paused, Completed, Failed) either by importing from
the SDK if available or creating it locally. Then update the conditional checks
to use DownloadState.Downloading and DownloadState.Paused instead of the magic
numbers. Also update any related code like getStateText to use the enum values.

Comment on lines +25 to +35
const loadDownloads = async () => {
try {
setLoading(true);
const downloadItems = await TPStreamsDownload.getDownloads();
setDownloads(downloadItems);
} catch (error) {
Alert.alert('Error', 'Failed to load downloads');
} finally {
setLoading(false);
}
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Guard against state updates after unmount

loadDownloads is an async function that sets state after awaiting a promise.
If the component unmounts before the promise resolves (e.g., user quickly navigates away), the setDownloads/setLoading calls will try to update an unmounted component, triggering a memory-leak warning.

Add a simple isMounted ref or an AbortController to ignore the result once unmounted.

+  const isMounted = useRef(true);
+  useEffect(() => {
+    return () => {
+      isMounted.current = false;
+    };
+  }, []);

   const loadDownloads = async () => {
     try {
       setLoading(true);
       const downloadItems = await TPStreamsDownload.getDownloads();
-      setDownloads(downloadItems);
+      if (isMounted.current) setDownloads(downloadItems);
     } catch (error) {
       Alert.alert('Error', 'Failed to load downloads');
     } finally {
-      setLoading(false);
+      if (isMounted.current) setLoading(false);
     }
   };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const loadDownloads = async () => {
try {
setLoading(true);
const downloadItems = await TPStreamsDownload.getDownloads();
setDownloads(downloadItems);
} catch (error) {
Alert.alert('Error', 'Failed to load downloads');
} finally {
setLoading(false);
}
};
const isMounted = useRef(true);
useEffect(() => {
return () => {
isMounted.current = false;
};
}, []);
const loadDownloads = async () => {
try {
setLoading(true);
const downloadItems = await TPStreamsDownload.getDownloads();
if (isMounted.current) setDownloads(downloadItems);
} catch (error) {
Alert.alert('Error', 'Failed to load downloads');
} finally {
if (isMounted.current) setLoading(false);
}
};
🤖 Prompt for AI Agents
In example/DownloadExample.tsx around lines 25 to 35, the async function
loadDownloads updates state after awaiting a promise, which can cause
memory-leak warnings if the component unmounts before the promise resolves. To
fix this, add an isMounted ref or use an AbortController to track the
component's mounted status, and check this status before calling setDownloads
and setLoading to prevent state updates on an unmounted component.

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