Enhance case search functionality: display recent cases in search results and adjust initial load behavior

This commit is contained in:
Ross
2025-11-16 23:16:06 +00:00
parent 8c8d484dce
commit 279d6344f1
3 changed files with 70 additions and 22 deletions
@@ -1,20 +1,45 @@
{% if cases and cases.exists %}
<div class="list-group">
{% for case in cases %}
<div class="list-group-item d-flex justify-content-between align-items-center">
<div class="flex-fill me-3">
<div class="fw-semibold">{{ case.title }}</div>
<div class="small text-muted">{% if case.description %}{{ case.description|truncatechars:100 }}{% endif %}</div>
</div>
{# Search results #}
{% if q %}
{% if cases and cases.exists %}
<div class="list-group mb-2">
{% for case in cases %}
<div class="list-group-item d-flex justify-content-between align-items-center">
<div class="flex-fill me-3">
<div class="fw-semibold">{{ case.title }}</div>
<div class="small text-muted">{% if case.description %}{{ case.description|truncatechars:100 }}{% endif %}</div>
</div>
<form class="m-0" hx-post="{% url 'atlas:add_case_to_collection' collection.pk %}" hx-target="#full-question-list" hx-swap="beforeend">
{% csrf_token %}
<input type="hidden" name="case" value="{{ case.pk }}">
<button type="submit" class="btn btn-sm btn-primary">Add</button>
</form>
</div>
{% endfor %}
<form class="m-0" hx-post="{% url 'atlas:add_case_to_collection' collection.pk %}" hx-target="#full-question-list" hx-swap="beforeend">
{% csrf_token %}
<input type="hidden" name="case" value="{{ case.pk }}">
<button type="submit" class="btn btn-sm btn-primary">Add</button>
</form>
</div>
{% endfor %}
</div>
{% else %}
<div class="text-muted small mb-2">No cases found.</div>
{% endif %}
{% endif %}
{# Recent cases quick-add (rendered below search results) #}
{% if recent_cases and recent_cases|length > 0 %}
<div>
<div class="small text-muted mb-1">Recently created</div>
<div class="list-group">
{% for case in recent_cases %}
<div class="list-group-item d-flex justify-content-between align-items-center">
<div class="flex-fill me-3">
<div class="fw-semibold">{{ case.title }}</div>
<div class="small text-muted">{% if case.description %}{{ case.description|truncatechars:100 }}{% endif %}</div>
</div>
<form class="m-0" hx-post="{% url 'atlas:add_case_to_collection' collection.pk %}" hx-target="#full-question-list" hx-swap="beforeend">
{% csrf_token %}
<input type="hidden" name="case" value="{{ case.pk }}">
<button type="submit" class="btn btn-sm btn-outline-primary">Add</button>
</form>
</div>
{% endfor %}
</div>
</div>
{% else %}
<div class="text-muted small">No cases found.</div>
{% endif %}
@@ -7,5 +7,9 @@
hx-trigger="keyup changed delay:400ms"
autocomplete="off">
<div id="case-search-results" class="mt-2"></div>
<div id="case-search-results" class="mt-2">
{# Render initial results (search + recent) on initial GET; HTMX searches will replace this div with partial results #}
{% include 'atlas/partials/case_search_results.html' with cases=cases recent_cases=recent_cases collection=collection %}
</div>
</div>