-
Notifications
You must be signed in to change notification settings - Fork 0
Client-side search with filter persistence #9
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,20 +2,27 @@ | |||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| {% block title %}Interne{% endblock %} | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| {% block header_left %} | ||||||||||||||||||||||||||||||||||||||||||||
| <div id="view-filter" class="view-filter"> | ||||||||||||||||||||||||||||||||||||||||||||
| <a href="/" class="view-filter-link{% if filter == "ready" %} active{% endif %}" hx-get="/" hx-target="#entry-list" hx-select="#entry-list" hx-select-oob="#view-filter" hx-swap="outerHTML" hx-push-url="true">Ready</a> | ||||||||||||||||||||||||||||||||||||||||||||
| / | ||||||||||||||||||||||||||||||||||||||||||||
| <a href="/waiting" class="view-filter-link{% if filter == "waiting" %} active{% endif %}" hx-get="/waiting" hx-target="#entry-list" hx-select="#entry-list" hx-select-oob="#view-filter" hx-swap="outerHTML" hx-push-url="true">Waiting</a> | ||||||||||||||||||||||||||||||||||||||||||||
| / | ||||||||||||||||||||||||||||||||||||||||||||
| <a href="/unseen" class="view-filter-link{% if filter == "unseen" %} active{% endif %}" hx-get="/unseen" hx-target="#entry-list" hx-select="#entry-list" hx-select-oob="#view-filter" hx-swap="outerHTML" hx-push-url="true">Unseen</a> | ||||||||||||||||||||||||||||||||||||||||||||
| / | ||||||||||||||||||||||||||||||||||||||||||||
| <a href="/all" class="view-filter-link{% if filter == "all" %} active{% endif %}" hx-get="/all" hx-target="#entry-list" hx-select="#entry-list" hx-select-oob="#view-filter" hx-swap="outerHTML" hx-push-url="true">All</a> | ||||||||||||||||||||||||||||||||||||||||||||
| {% block nav_end %} | ||||||||||||||||||||||||||||||||||||||||||||
| <div class="search-trigger" id="search-trigger"> | ||||||||||||||||||||||||||||||||||||||||||||
| <svg class="search-icon" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg> | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| <div class="search-swap"> | ||||||||||||||||||||||||||||||||||||||||||||
| <span class="date" id="clock"></span> | ||||||||||||||||||||||||||||||||||||||||||||
| <input type="search" class="search-field" id="search-input" placeholder="Search..." autocomplete="off" spellcheck="false"> | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||
| {% endblock %} | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| {% block header_actions %} | ||||||||||||||||||||||||||||||||||||||||||||
| <div class="header-actions"> | ||||||||||||||||||||||||||||||||||||||||||||
| <div id="view-filter" class="view-filter"> | ||||||||||||||||||||||||||||||||||||||||||||
| <a href="/" class="view-filter-link{% if filter == "ready" %} active{% endif %}" hx-get="/" hx-target="#entry-list" hx-select="#entry-list" hx-swap="outerHTML" hx-push-url="true">Ready</a> | ||||||||||||||||||||||||||||||||||||||||||||
| / | ||||||||||||||||||||||||||||||||||||||||||||
| <a href="/waiting" class="view-filter-link{% if filter == "waiting" %} active{% endif %}" hx-get="/waiting" hx-target="#entry-list" hx-select="#entry-list" hx-swap="outerHTML" hx-push-url="true">Waiting</a> | ||||||||||||||||||||||||||||||||||||||||||||
| / | ||||||||||||||||||||||||||||||||||||||||||||
| <a href="/unseen" class="view-filter-link{% if filter == "unseen" %} active{% endif %}" hx-get="/unseen" hx-target="#entry-list" hx-select="#entry-list" hx-swap="outerHTML" hx-push-url="true">Unseen</a> | ||||||||||||||||||||||||||||||||||||||||||||
| / | ||||||||||||||||||||||||||||||||||||||||||||
| <a href="/all" class="view-filter-link{% if filter == "all" %} active{% endif %}" hx-get="/all" hx-target="#entry-list" hx-select="#entry-list" hx-swap="outerHTML" hx-push-url="true">All</a> | ||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||
| <a href="/entries/new">+ New Link</a> | ||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||
| {% endblock %} | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -40,5 +47,74 @@ | |||||||||||||||||||||||||||||||||||||||||||
| {% endfor %} | ||||||||||||||||||||||||||||||||||||||||||||
| {% endif %} | ||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| <script> | ||||||||||||||||||||||||||||||||||||||||||||
| (function() { | ||||||||||||||||||||||||||||||||||||||||||||
| var trigger = document.getElementById('search-trigger'); | ||||||||||||||||||||||||||||||||||||||||||||
| var input = document.getElementById('search-input'); | ||||||||||||||||||||||||||||||||||||||||||||
| var hovering = false; | ||||||||||||||||||||||||||||||||||||||||||||
| var timer; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| function activate() { trigger.classList.add('active'); } | ||||||||||||||||||||||||||||||||||||||||||||
| function deactivate() { | ||||||||||||||||||||||||||||||||||||||||||||
| if (!hovering && !input.value) trigger.classList.remove('active'); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| function filterEntries() { | ||||||||||||||||||||||||||||||||||||||||||||
| var q = input.value.toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||||
| var entries = document.getElementById('entry-list').querySelectorAll('.entry'); | ||||||||||||||||||||||||||||||||||||||||||||
| for (var i = 0; i < entries.length; i++) { | ||||||||||||||||||||||||||||||||||||||||||||
| var haystack = entries[i].getAttribute('data-search').toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| var haystack = entries[i].getAttribute('data-search').toLowerCase(); | |
| var haystack = (entries[i].getAttribute('data-search') || '').toLowerCase(); |
Copilot
AI
Feb 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The htmx:load event listener is attached to document.body, which means it will fire for any htmx load event on the page, not just when the entry list is loaded. While this is functionally safe (it checks if input.value exists), it would be more efficient and clearer to attach the listener to the entry-list element specifically, or check if the loaded content is the entry list before calling filterEntries().
| input.addEventListener('input', function() { | |
| clearTimeout(timer); | |
| timer = setTimeout(filterEntries, 150); | |
| }); | |
| // re-apply search filter after htmx loads new content | |
| document.body.addEventListener('htmx:load', function() { | |
| if (input.value) filterEntries(); | |
| }); | |
| var entryList = document.getElementById('entry-list'); | |
| input.addEventListener('input', function() { | |
| clearTimeout(timer); | |
| timer = setTimeout(filterEntries, 150); | |
| }); | |
| // re-apply search filter after htmx loads new content for the entry list | |
| if (entryList) { | |
| entryList.addEventListener('htmx:load', function() { | |
| if (input.value) filterEntries(); | |
| }); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tags parameter passed to build_entry_view only includes the current tag being viewed, not all tags associated with the entry. This means the data-search attribute in the rendered entry.html will only include one tag, making the search functionality incomplete when viewing entries from a tag page. Consider fetching all tags for these entries using fetch_tags_for_entries similar to how it's done in list_filtered_entries, or document this limitation.