Skip to content

Commit fa4fdf6

Browse files
committed
chore: code clean up, add some documentation
1 parent d4cfe53 commit fa4fdf6

8 files changed

Lines changed: 40 additions & 20 deletions

File tree

libraries/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ def get_v3_context_data(self, queryset=None, **kwargs):
204204
"placeholder": "Search",
205205
"deselectable": True,
206206
},
207+
# Sort is applied client-side via libraryFilter.sortItems(); no
208+
# queryset.order_by() here. The default alphabetical order comes
209+
# from the view's `ordering = "library__name"`.
207210
{
208211
"type": "dropdown",
209212
"name": "sort",

static/css/v3/forms.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@
314314
border-color: var(--color-stroke-weak);
315315
border-bottom-left-radius: 0;
316316
border-bottom-right-radius: 0;
317-
border-bottom-color: var(--color-stroke-weak, #0508161A);
317+
border-bottom-color: var(--color-stroke-weak);
318318
}
319319

320320
.dropdown--has-value .dropdown__trigger,

static/css/v3/library-page.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ html.dark .library-page-hero .hero-image-dark {
111111
align-items: center;
112112
}
113113

114-
.library-page_list-header-justify {
114+
.library-page__list-header-justify {
115115
justify-self: center;
116116
padding-left: calc(16px + var(--space-large));
117117
}

templates/v3/includes/_field_combo_multi.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{% if selected_values %}
2020
<script type="application/json" id="field-{{ name }}-selected">{{ selected_values|to_json }}</script>
2121
{% endif %}
22-
<div class="field{% if error %} field--error{% endif %}{% if extra_class %} {{ extra_class }}{% endif %}"
22+
<div class="field {% if error %}field--error{% endif %} {% if extra_class %}{{ extra_class }}{% endif %}"
2323
@clear-all-filters.window="clearAll()"
2424
{# djlint:off #}
2525
x-data="{
@@ -82,7 +82,7 @@
8282
x-show="!jsReady"
8383
:disabled="jsReady">
8484
{% for value, label in options %}
85-
<option value="{{ value }}"{% if value in selected_values %} selected{% endif %}>{{ label }}</option>
85+
<option value="{{ value }}" {% if value in selected_values %}selected{% endif %}>{{ label }}</option>
8686
{% endfor %}
8787
</select>
8888
<div class="dropdown dropdown--combo" :class="{ 'dropdown--open': open{% if deselectable %}, 'dropdown--has-value': selectedValues.length > 0{% endif %} }" x-cloak>
@@ -129,7 +129,6 @@
129129
class="dropdown__clear-btn"
130130
@click.stop="clearAll()"
131131
x-show="selectedValues.length > 0"
132-
x-cloak
133132
aria-label="Clear all selections"
134133
tabindex="-1">
135134
{% include "includes/icon.html" with icon_name="close" icon_class="dropdown__clear-icon" %}

templates/v3/includes/_field_dropdown.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Usage:
1818
{% include "v3/includes/_field_dropdown.html" with name="country" label="Country" options=country_options placeholder="Select a country" %}
1919
{% endcomment %}
20-
<div class="field{% if error %} field--error{% endif %}{% if extra_class %} {{ extra_class }}{% endif %}"
20+
<div class="field {% if error %}field--error{% endif %} {% if extra_class %}{{ extra_class }}{% endif %}"
2121
{% if alpine_error %}:class="{ 'field--error': {{ alpine_error }} }"{% endif %}
2222
{% if not exclude_from_clear %}@clear-all-filters.window="clear()"{% endif %}
2323
@field-disabled-values.window="if ($event.detail.name === '{{ name }}') disabledValues = $event.detail.values"
@@ -73,7 +73,7 @@
7373
@change="$dispatch('field-change', { name: '{{ name }}', value: $event.target.value, label: $event.target.options[$event.target.selectedIndex].text })">
7474
{% if placeholder %}<option value="">{{ placeholder }}</option>{% endif %}
7575
{% for value, label in options %}
76-
<option value="{{ value }}"{% if value == selected %} selected{% endif %}>{{ label }}</option>
76+
<option value="{{ value }}" {% if value == selected %}selected{% endif %}>{{ label }}</option>
7777
{% endfor %}
7878
</select>
7979
<div class="dropdown" :class="{ 'dropdown--open': open{% if deselectable %}, 'dropdown--has-value': selected && selected !== defaultValue{% endif %} }" x-cloak>
@@ -153,7 +153,7 @@
153153
<p class="field__error" role="alert" aria-live="polite" x-show="false">{{ error }}</p>
154154
{% endif %}
155155
{% if help_text %}
156-
<p class="field__help" id="field-{{ name }}-help" x-show="!{{ alpine_error }}"{% if error %} style="display:none"{% endif %}>{{ help_text }}</p>
156+
<p class="field__help" id="field-{{ name }}-help" x-show="!{{ alpine_error }}" {% if error %}style="display:none"{% endif %}>{{ help_text }}</p>
157157
{% endif %}
158158
{% else %}
159159
{% if error %}

templates/v3/includes/_field_text.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
Search field (no error handling):
4141
{% include "v3/includes/_field_text.html" with name="q" placeholder="Search..." submit_icon="arrow-right" submit_label="Search" %}
4242
{% endcomment %}
43-
<div class="field{% if error %} field--error{% endif %}{% if extra_class %} {{ extra_class }}{% endif %}"
43+
<div class="field {% if error %}field--error{% endif %} {% if extra_class %}{{ extra_class }}{% endif %}"
4444
{# djlint:off #}
4545
{% if validate_type == "email" %}
4646
data-validate
@@ -59,7 +59,7 @@
5959
{% elif alpine_error %}:class="{ 'field--error': {{ alpine_error }} }"{% endif %}>
6060
{# djlint:on #}
6161
{% if label %}<label class="field__label" for="field-{{ name }}">{{ label }}</label>{% endif %}
62-
<div class="field__control{% if disabled %} field__control--disabled{% endif %}"
62+
<div class="field__control {% if disabled %}field__control--disabled{% endif %}"
6363
{% if submit_icon %}x-data="{ q: '{{ value|default:''|escapejs }}' }"{% endif %}>
6464
{% if icon_left %}
6565
<span class="field__icon" aria-hidden="true">
@@ -82,7 +82,7 @@
8282
{% elif help_text %}
8383
aria-describedby="field-{{ name }}-help"
8484
{% endif %}
85-
{% if validate_type == "email" %}x-model="value" @blur="touched = true"{% elif submit_icon %}x-model="q"{% if dispatch_field_change %} @input.debounce.150ms="$dispatch('field-change', { name: '{{ name }}', value: q })"{% endif %}{% endif %}>
85+
{% if validate_type == "email" %}x-model="value" @blur="touched = true"{% elif submit_icon %}x-model="q" {% if dispatch_field_change %}@input.debounce.150ms="$dispatch('field-change', { name: '{{ name }}', value: q })"{% endif %}{% endif %}>
8686
{% if submit_icon %}
8787
<button type="submit"
8888
class="field__submit"

templates/v3/includes/_library_item.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Usage (card):
2121
{% include "v3/includes/_library_item.html" with variant="card" library_name="Boost.Asio" description="Portable networking and low-level I/O." categories=cats cpp_version="C++ 11" author=author doc_url="/libs/asio/doc/" %}
2222
{% endcomment %}
23-
{% if variant == "list" %}<li class="library-item library-item--list"{% if library_slug %} data-slug="{{ library_slug }}"{% endif %} {{ extra_attrs|safe }}>{% else %}<div class="library-item library-item--card"{% if library_slug %} data-slug="{{ library_slug }}"{% endif %} {{ extra_attrs|safe }}>{% endif %}
23+
{% if variant == "list" %}<li class="library-item library-item--list" {% if library_slug %}data-slug="{{ library_slug }}"{% endif %} {{ extra_attrs|safe }}>{% else %}<div class="library-item library-item--card" {% if library_slug %}data-slug="{{ library_slug }}"{% endif %} {{ extra_attrs|safe }}>{% endif %}
2424

2525
<div class="library-item__header">
2626
{% if library_url %}

templates/v3/library_page.html

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,27 @@
3737
{{ library_dataset|json_script:"library-data" }}
3838
{{ library_filter_defaults|json_script:"library-filter-defaults" }}
3939
<script>
40-
/* Defined inline so the factory is on window before Alpine evaluates x-data
40+
/* libraryFilter() — page-scoped Alpine component that owns search/filter/sort.
41+
All three pipelines are client-side; the server returns the full dataset
42+
for the selected Boost version, embedded as the `library-data` script tag.
43+
44+
State:
45+
dataset, defaults — loaded once from script tags at init().
46+
grading, minCpp, — current filter selections, hydrated from URL
47+
maxCpp, categories, params and mirrored back via syncUrl().
48+
query, sort
49+
searchHits/Scores — Fuse output keyed by slug (null when no query).
50+
visibleCount — drives empty-state visibility from toggleItems().
51+
52+
Wiring: child field components dispatch `field-change` events; the parent
53+
listens, updates state, calls apply() which runs search → URL sync →
54+
toggle → sort → empty-state in order.
55+
56+
Defined inline so the factory is on window before Alpine evaluates x-data
4157
on this page — defer-script load ordering can otherwise race Alpine.start. */
4258
window.libraryFilter = function () {
59+
// Keep in sync with LibraryVersion.CPP_STANDARD_DISPLAY_NAMES — used for
60+
// min/max C++ range ranking and the disabled-option constraints.
4361
const CPP_STANDARDS = [
4462
{ key: '98', year: 1998, label: 'C++98' },
4563
{ key: '03', year: 2003, label: 'C++03' },
@@ -112,6 +130,8 @@
112130
this.query = params.get('q') || '';
113131
this.sort = params.get('sort') || this.defaults.sort;
114132

133+
// Child fields dispatch `field-change` with {name, value}; route to
134+
// the matching state slot, enforce min/max C++ ordering, then apply().
115135
this.$el.addEventListener('field-change', (event) => {
116136
const { name, value } = event.detail;
117137
if (name === 'grading') this.grading = value || 'all';
@@ -277,8 +297,9 @@
277297
items.forEach((el) => {
278298
const data = bySlug.get(el.dataset.slug);
279299
const show = data ? this.matches(data) : true;
280-
// Inline style beats the `[hidden]` attribute, which is overridden
281-
// by .library-item--list / --card's `display: grid`.
300+
// Inline style beats `[hidden]`. The item containers use
301+
// `display: grid` (with subgrid on .library-item--list), which
302+
// overrides the default `[hidden] { display: none }` rule.
282303
el.style.display = show ? '' : 'none';
283304
if (show) visible += 1;
284305
});
@@ -359,6 +380,7 @@
359380
};
360381
};
361382
</script>
383+
362384
<div class="library-page__container" x-data="libraryFilter()">
363385
<section class="library-page-hero" aria-label="Hero">
364386
<h1 class="hero-title">Find a battle-tested library for the problem you're solving right now.</h1>
@@ -382,7 +404,7 @@ <h1 class="hero-title">Find a battle-tested library for the problem you're solvi
382404
<div class="library-page__list-header-flex"><span class="library-page__list-header-text">Description</span>{% include "includes/icon.html" with icon_name="chevron-down" icon_size=16 %}</div>
383405
<div class="library-page__list-header-flex"><span class="library-page__list-header-text">Category</span>{% include "includes/icon.html" with icon_name="chevron-down" icon_size=16 %}</div>
384406
<div class="library-page__list-header-flex"><span class="library-page__list-header-text">Author</span>{% include "includes/icon.html" with icon_name="chevron-down" icon_size=16 %}</div>
385-
<div class="library-page__list-header-flex library-page_list-header-justify"><span class="library-page__list-header-text">Version</span>{% include "includes/icon.html" with icon_name="chevron-down" icon_size=16 %}</div>
407+
<div class="library-page__list-header-flex library-page__list-header-justify"><span class="library-page__list-header-text">Version</span>{% include "includes/icon.html" with icon_name="chevron-down" icon_size=16 %}</div>
386408
<div></div>
387409
</li>
388410
{% for item in object_list %}
@@ -420,7 +442,3 @@ <h2 class="library-page__category-header">{{ result.category }} {% if result.ico
420442
{% endif %}
421443
</div>
422444
{% endblock %}
423-
424-
{% block footer_js %}
425-
{{ block.super }}
426-
{% endblock %}

0 commit comments

Comments
 (0)