Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to search episodes displayed on HTML page - closes #75 #77

Merged
merged 2 commits into from
Jan 26, 2025

Conversation

hbmartin
Copy link
Owner

@hbmartin hbmartin commented Jan 26, 2025

Summary by Sourcery

New Features:

  • Added a search bar to the episode list page, allowing users to filter episodes by title or description.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added search functionality to the episode list, allowing users to filter episodes by typing in a search box.
    • Enhanced footer with a clickable LinkedIn link for the author.
  • Improvements

    • Updated HTML file path display in CLI output to include "file://" prefix.
    • Refined HTML template structure for better layout.
  • Technical Updates

    • Included JavaScript files in package distribution to support new features.

Copy link

sourcery-ai bot commented Jan 26, 2025

Reviewer's Guide by Sourcery

This pull request adds the ability to search episodes displayed on the HTML page. It introduces a search input field and a JavaScript function to filter episodes based on the search term. The search is case-insensitive and filters based on the text content of each episode section.

Sequence diagram for episode search interaction

sequenceDiagram
    actor User
    participant SearchInput
    participant SearchJS
    participant Episodes

    User->>SearchInput: Types search term
    SearchInput->>SearchJS: Triggers oninput event
    SearchJS->>Episodes: Get all episode sections
    SearchJS->>Episodes: Filter episodes by search term
    SearchJS->>Episodes: Show/hide episodes based on matches
Loading

File-Level Changes

Change Details Files
Added a search input field to the HTML page.
  • Added an input field with type text and a placeholder for search.
  • Added an oninput event listener to the input field that calls the searchEps function.
overcast_to_sqlite/html/index.html
Added a JavaScript file to handle the search functionality.
  • Created a searchEps function that takes a search string as input.
  • The function gets all the section elements on the page.
  • The function iterates through each section and checks if the inner text includes the search string.
  • If the section includes the search string, the display is set to flex, otherwise it is set to none.
overcast_to_sqlite/html/search.js
Included the JavaScript file in the HTML page.
  • Added a script key to the page_vars dictionary.
  • The script key is set to the content of the search.js file.
overcast_to_sqlite/html/page.py
Included the JavaScript file in the package data.
  • Added *.js to the package data.
pyproject.toml
Updated the output message to include file://.
  • Added file:// to the output message.
overcast_to_sqlite/cli.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

coderabbitai bot commented Jan 26, 2025

Walkthrough

The pull request modifies the Overcast to SQLite project by introducing a search functionality to the HTML output. This includes the addition of a search input field in index.html, the creation of a new search.js file containing a client-side search function, and adjustments to the HTML generation process to incorporate the new JavaScript. Additionally, a minor change in the CLI output was made to prepend "file://" to the HTML file path. These changes enhance the user interface by allowing users to filter episodes directly in the generated HTML page.

Changes

File Change Summary
overcast_to_sqlite/cli.py Modified print statement to prepend "file://" to HTML output path
overcast_to_sqlite/html/episode.html Repositioned <hr/> element within HTML structure
overcast_to_sqlite/html/index.html Added search input field and script section
overcast_to_sqlite/html/page.py Added script loading for search.js
overcast_to_sqlite/html/search.js New searchEps function for client-side episode filtering
pyproject.toml Updated package data to include JavaScript files

Sequence Diagram

sequenceDiagram
    participant User
    participant HTML Page
    participant Search Function
    
    User->>HTML Page: Load Page
    User->>HTML Page: Enter Search Text
    HTML Page->>Search Function: Trigger searchEps()
    Search Function->>HTML Page: Filter Sections
    Search Function-->>User: Display Matching Episodes
Loading

Poem

🐰 A rabbit's tale of search delight,
Where episodes now dance in sight,
With just a few keystrokes so neat,
The content filters, oh so sweet!
No podcast lost, no episode hidden,
By magic of code, perfectly ridden! 🎧


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 995a406 and 2808bc8.

📒 Files selected for processing (2)
  • overcast_to_sqlite/cli.py (1 hunks)
  • overcast_to_sqlite/html/index.html (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • overcast_to_sqlite/cli.py
  • overcast_to_sqlite/html/index.html

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @hbmartin - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider removing the space after 'file://' in the CLI output to ensure consistent URL parsing across systems
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -308,7 +308,7 @@ def html(
else:
html_output_path = Path(db_path).parent / "overcast-played.html"
generate_html_played(db_path, html_output_path)
print("📝Saved HTML to:", html_output_path.absolute())
print("📝Saved HTML to: file://", html_output_path.absolute())
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Remove extra space after file:// protocol

The extra space after 'file://' could cause issues with URL handling in some environments. Consider concatenating the strings directly.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 (2)
overcast_to_sqlite/html/search.js (1)

1-11: The search implementation works but could be enhanced.

While the core functionality is correct, consider these improvements:

  1. Use querySelectorAll('section') instead of getElementsByTagName for better performance
  2. Show all sections when search string is empty
  3. Add keyboard navigation and ARIA attributes for accessibility
 function searchEps(searchString) {
-  const divs = Array.from(document.getElementsByTagName('section'));
+  const divs = Array.from(document.querySelectorAll('section'));
+  if (!searchString.trim()) {
+    divs.forEach(div => div.style.display = 'flex');
+    return;
+  }
   divs.forEach(div => {
     const matches = div.innerText.toLowerCase().includes(searchString.toLowerCase());
     if (matches) {
         div.style.display = 'flex';
     } else {
         div.style.display = 'none';
     }
   });
 }
overcast_to_sqlite/html/index.html (1)

9-11: Add defer attribute to script tag for better performance.

The script should be loaded with defer to prevent blocking page rendering.

     <script>
         {script}
     </script>
+    <script defer>
+        {script}
+    </script>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f53a64e and 995a406.

📒 Files selected for processing (6)
  • overcast_to_sqlite/cli.py (1 hunks)
  • overcast_to_sqlite/html/episode.html (1 hunks)
  • overcast_to_sqlite/html/index.html (1 hunks)
  • overcast_to_sqlite/html/page.py (1 hunks)
  • overcast_to_sqlite/html/search.js (1 hunks)
  • pyproject.toml (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • overcast_to_sqlite/html/episode.html
  • overcast_to_sqlite/cli.py
🔇 Additional comments (1)
pyproject.toml (1)

12-12: LGTM!

The addition of *.js to package data is correct and necessary for including the search functionality in the distribution.

@@ -33,6 +33,7 @@ def generate_html_played(db_path: str, html_output_path: Path) -> None:
page_vars = {
"title": "Recently Played",
"style": Path(this_dir / "mvp.css").read_text(),
"script": Path(this_dir / "search.js").read_text(),
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for file read operations.

The script file read operation should handle potential IOErrors to prevent crashes if the file is missing or unreadable.

-        "script": Path(this_dir / "search.js").read_text(),
+        "script": Path(this_dir / "search.js").read_text() if (this_dir / "search.js").exists() else "",
📝 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
"script": Path(this_dir / "search.js").read_text(),
"script": Path(this_dir / "search.js").read_text() if (this_dir / "search.js").exists() else "",

<p><small>Made with ❤️ by your friendly neighborhood hbmartin</small></p>
</footer>
<main>
<input type="text" oninput="searchEps(this.value)" placeholder="Search">
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance search input accessibility and UX.

The search input needs a label and better styling for accessibility and user experience.

-    <input type="text" oninput="searchEps(this.value)" placeholder="Search">
+    <div class="search-container">
+        <label for="episode-search">Search Episodes:</label>
+        <input 
+            type="text" 
+            id="episode-search"
+            oninput="searchEps(this.value)" 
+            placeholder="Search episodes..."
+            aria-label="Search episodes"
+        >
+    </div>

Add this CSS to the existing style section:

.search-container {
    margin: 1rem 0;
}
.search-container input {
    width: 100%;
    padding: 0.5rem;
    font-size: 1rem;
    border: 1px solid #ccc;
    border-radius: 4px;
}

@hbmartin hbmartin merged commit 671ecb0 into main Jan 26, 2025
6 checks passed
@hbmartin hbmartin deleted the search-html branch January 26, 2025 21:30
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