Skip to content

Conversation

@a0m0rajab
Copy link

@a0m0rajab a0m0rajab commented Oct 18, 2025

(This is a demo PR, will check the functionality later today)

This pull request enhances the templates UI by adding a search input for filtering templates by language and introduces an event-driven mechanism for template filtering. The main changes are grouped below:

UI Enhancements:

  • Added a search input field (<input id="templates-search-input" ...>) to the templates navigation, allowing users to filter templates by language.

Event-Driven Filtering:

  • Introduced an inline script that listens for user input in the search field, debounces the input, and emits a templates:filter custom event with the current query. This enables other scripts to react and perform the actual filtering logic.

What type of PR is this? (check all applicable)

  • ✨ Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Stylea
  • ♻️ Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert
  • 🌐 Internationalization / Translation

Description

Related Tickets & Documents

Fixes #900
This pull request adds a search/filter feature to the templates section in the templates.html file, allowing users to filter templates by language. It introduces a search input UI and emits a custom event to enable template filtering functionality.

User interface improvements:

  • Added a search input field (<input id="templates-search-input" ...>) to the templates navigation for filtering templates by language.

Interactivity and event handling:

  • Added an inline script that listens to input changes on the search field, debounces user input, and emits a templates:filter custom event with the current query to enable live filtering of templates.

Mobile & Desktop Screenshots/Recordings

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help

Added to documentations?

  • 📓 docs (./docs)
  • 📕 storybook (./storybook)
  • 📜 README.md
  • 🙅 no documentation needed

[optional] Are there any post-deployment tasks we need to perform?

[optional] What gif best describes this PR or how it makes you feel?

Summary by CodeRabbit

  • New Features
    • Added a search input in the templates tab header, enabling users to filter templates in real-time as they type.

@netlify
Copy link

netlify bot commented Oct 18, 2025

Deploy Preview for livecodes ready!

Name Link
🔨 Latest commit ef91608
🔍 Latest deploy log https://app.netlify.com/projects/livecodes/deploys/68f35d671cab620008e7747e
😎 Deploy Preview https://deploy-preview-901--livecodes.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link

coderabbitai bot commented Oct 18, 2025

Walkthrough

Added a templates search UI to the templates tab header with a labeled input field. Implemented debounced keystroke handling (150ms) that emits a "templates:filter" CustomEvent on the templates container element for template filtering.

Changes

Cohort / File(s) Summary
Templates Search Feature
src/livecodes/html/templates.html
Added search input UI in templates tab header with inline JavaScript logic: debounces user input (150ms), emits "templates:filter" CustomEvent with query to #templates-container for downstream filtering

Sequence Diagram

sequenceDiagram
    participant User
    participant Input as Search Input
    participant Debounce as Debounce Logic
    participant EventTarget as #templates-container
    participant Listener as Filter Handler

    User->>Input: Types search query
    Input->>Debounce: Keystroke (rapid fire)
    Note over Debounce: 150ms debounce window
    Debounce->>EventTarget: Emit CustomEvent("templates:filter")<br/>with query in event.detail
    EventTarget->>Listener: Dispatch event
    Listener->>Listener: Filter templates based on query
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A search box hops into the templates shore,

Debounced keystrokes, filtering forevermore!

Events dispatched with CustomEvent flair,

Finding templates anywhere, everywhere!

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Linked Issues Check ❓ Inconclusive Issue #900 requests adding a search text field to the languages selection panel to allow users to find programming languages more easily. The PR implements a templates-search input with event-driven filtering via a custom "templates:filter" event, which provides the UI component and event emission infrastructure. However, the PR does not implement the actual filtering logic itself—it only sets up the event mechanism for other scripts to respond to, and the objectives note this filtering logic is "to be checked later." This creates ambiguity about whether the complete feature requirement is satisfied: while the PR addresses the UI aspect of searching, it remains unclear whether filtering templates by language fully meets the issue's objective of enabling users to easily find programming languages. To conclusively assess compliance, verify that: (1) the templates panel and languages panel are the same component, (2) the "templates:filter" event will be consumed by a handler that performs the actual language filtering, and (3) the complete feature (UI + filtering logic) satisfies issue #900's requirement. If the filtering handler is external to this PR, consider documenting that dependency or confirming it exists in the codebase.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat(Templates): add search functionality for user templates" is concise, specific, and directly aligns with the primary change in the changeset. The modification adds a new search input field with debounce logic to the templates navigation, enabling users to filter templates. The title clearly conveys the main objective without unnecessary detail or vague terminology, making it easily understandable for developers reviewing the project history.
Out of Scope Changes Check ✅ Passed All changes in the pull request are directly related to the linked issue #900's objective of adding search functionality to the templates/languages panel. The modifications consist solely of a new search input field with id "templates-search-input" and an inline debounce script that emits a custom "templates:filter" event. These changes are narrowly scoped to implementing the requested search feature and do not include unrelated modifications such as refactoring, documentation changes, or functionality outside the templates search context.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@sonarqubecloud
Copy link

Copy link

@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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7344c78 and ef91608.

📒 Files selected for processing (1)
  • src/livecodes/html/templates.html (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Redirect rules - livecodes
  • GitHub Check: Header rules - livecodes
  • GitHub Check: Pages changed - livecodes
🔇 Additional comments (1)
src/livecodes/html/templates.html (1)

36-55: Script logic is sound; confirm filtering implementation is planned.

The inline script correctly debounces input (150ms), emits a templates:filter custom event with the query value, and uses defensive null checks. The implementation is event-driven as intended, allowing other scripts to listen and filter templates accordingly.

Since this is described as a demo PR pending actual filtering logic, verify that:

  • Event listeners consuming the templates:filter event will be implemented separately.
  • The event dispatch to #templates-container aligns with where filter listeners will be attached.

Comment on lines +13 to +16
<li class="templates-search">
<label for="templates-search-input" class="visually-hidden" data-i18n="templates.search.label">Search templates</label>
<input id="templates-search-input" type="search" placeholder="Filter languages..." aria-label="Filter templates by language" />
</li>
Copy link

@coderabbitai coderabbitai bot Oct 18, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Move search input out of the tab list for proper semantic structure.

Placing the search input as an <li> inside the tab navigation list violates WAI-ARIA tab patterns. The tab list (<ul class="modal-tabs">) contains tab controls, not search fields. Screen readers will incorrectly announce this as a tab item rather than a search field, degrading accessibility.

Recommend restructuring to place the search input in a dedicated container outside the tab list (e.g., above or below the tabs, or in a separate section).

Consider restructuring like this:

    <ul id="templates-tabs" class="modal-tabs">
      <li class="active">
        <a href="#" data-target="templates-starter" data-i18n="templates.starter.heading">
          Starter Templates
        </a>
      </li>
      <li>
        <a href="#" data-target="templates-user" data-i18n="templates.user.heading">My Templates</a>
      </li>
-     <li class="templates-search">
-       <label for="templates-search-input" class="visually-hidden" data-i18n="templates.search.label">Search templates</label>
-       <input id="templates-search-input" type="search" placeholder="Filter languages..." aria-label="Filter templates by language" />
-     </li>
    </ul>
+   <div class="templates-search-container">
+     <label for="templates-search-input" class="visually-hidden" data-i18n="templates.search.label">Search templates</label>
+     <input id="templates-search-input" type="search" placeholder="Filter languages..." aria-label="Filter templates by language" />
+   </div>

Adjust CSS styling as needed to position the search container appropriately within the templates modal layout.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/livecodes/html/templates.html around lines 13 to 16, the search input is
currently an <li> inside the tab list which breaks WAI-ARIA tab semantics; move
the search input out of the <ul class="modal-tabs"> into its own container (for
example a <div class="templates-search">) placed immediately before or after the
tab list, keep the existing label, input id, placeholder and aria-label intact,
and remove the <li> wrapper; finally update/adjust CSS selectors to position the
new .templates-search container as needed within the templates modal layout so
visual placement remains unchanged.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the search input should not be added as a new tab, since it affects the other tabs. The suggestion by CodeRabbit AI is reasonable.

Copy link

Choose a reason for hiding this comment

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

@hatemhosny Thank you for confirming! Moving the search input outside the tab list will maintain proper semantic structure and ensure the tabs remain independent of the filtering functionality. The suggested refactoring will improve both accessibility and the overall architecture of the component.

Copy link
Collaborator

@hatemhosny hatemhosny left a comment

Choose a reason for hiding this comment

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

Thank you @a0m0rajab

I have added some comments.

Comment on lines +13 to +16
<li class="templates-search">
<label for="templates-search-input" class="visually-hidden" data-i18n="templates.search.label">Search templates</label>
<input id="templates-search-input" type="search" placeholder="Filter languages..." aria-label="Filter templates by language" />
</li>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the search input should not be added as a new tab, since it affects the other tabs. The suggestion by CodeRabbit AI is reasonable.

</div>

<!-- Inline: emit a "templates:filter" event with the current query so other scripts can perform filtering -->
<script>
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can move the logic to src/livecodes/UI/templates.ts.
Think of the html here as the "view" while the logic in templates.ts as the "controller" in MVC pattern.

Also if you do that, you can directly manipulate DOM elements e.g. add display: none; without having to emit events.

var val = e.target.value || '';
// debounce to avoid excessive events while typing
clearTimeout(timeout);
timeout = setTimeout(function () { emit(val.trim()); }, 150);
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a debounce function here that you can re-use.

</li>
<li class="templates-search">
<label for="templates-search-input" class="visually-hidden" data-i18n="templates.search.label">Search templates</label>
<input id="templates-search-input" type="search" placeholder="Filter languages..." aria-label="Filter templates by language" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's change "Filter languages..." to "Search templates...". And then we can search by title, languages and others (e.g. tags).

Also, after you finish your edits, please run npm run i18n-export to regenerate the i18n json and fix this build error.

@hatemhosny
Copy link
Collaborator

Thank you @DevAbdelrahmanSayed
It is still in progress.
If @a0m0rajab doesn't have the time to complete it, you are welcome to work on it.

@a0m0rajab
Copy link
Author

Hi, thanks for mentioning me in the comments! I’d love to work on and finish this, but I might not be able to get to it before the weekend.

Just a general note, it’s usually nice to check in with the PR contributor first before escalating to the maintainers. It tends to come across as more polite and professional. If the contributor doesn’t respond for a while and the PR becomes stale, then escalating to the maintainers would make sense.

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.

Feature: Add search option to languages panel

2 participants