Skip to content

Commit 121683d

Browse files
committed
offload to search
1 parent 69092f5 commit 121683d

File tree

3 files changed

+23
-113
lines changed

3 files changed

+23
-113
lines changed

src/components/changelog/ProductSelect.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ export default function ProductSelect({ products, groups }: Props) {
6565
select.value = option.value;
6666
select.dispatchEvent(event);
6767
}
68+
69+
const search = document.querySelector<HTMLAnchorElement>(
70+
"#changelog-search-button",
71+
);
72+
73+
if (search) {
74+
if (
75+
options
76+
.find((opt) => opt.label === "Products")
77+
?.options?.includes(option)
78+
) {
79+
search.href = `/search/?contentType=Changelog+entry&product=${encodeURIComponent(option.label)}`;
80+
} else {
81+
search.href = `/search/?contentType=Changelog+entry`;
82+
}
83+
}
6884
};
6985

7086
return (

src/pages/changelog/historical/[page].astro

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/pages/changelog/index.astro

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ const props = {
104104
})
105105
}
106106
<div class="flex items-center justify-center">
107-
<button
108-
id="changelogs-next-button"
109-
class="bg-cl1-brand-orange text-cl1-black h-12 cursor-pointer rounded-sm px-6 font-medium"
107+
<a
108+
id="changelog-search-button"
109+
href="/search/?contentType=Changelog+entry"
110+
class="bg-cl1-brand-orange text-cl1-black mr-2 flex h-12 items-center justify-center rounded-sm px-6 font-medium no-underline"
110111
>
111-
Load more items
112-
</button>
112+
Search for historical entries
113+
</a>
113114
</div>
114115
</StarlightPage>
115116

@@ -118,10 +119,6 @@ const props = {
118119
"#changelogs-next-filter",
119120
);
120121

121-
const button = document.querySelector<HTMLButtonElement>(
122-
"#changelogs-next-button",
123-
);
124-
125122
const url = new URL(window.location.href);
126123

127124
if (filter && url.searchParams.has("product")) {
@@ -144,21 +141,6 @@ const props = {
144141
return products.includes(value);
145142
}
146143

147-
button?.addEventListener("click", () => {
148-
const hidden = [
149-
...document.querySelectorAll<HTMLElement>("[data-products]"),
150-
]
151-
.filter(
152-
(e) =>
153-
e.classList.contains("hidden!") && filterByProduct(e, filter!.value),
154-
)
155-
.slice(0, 10);
156-
157-
hidden.forEach((e) => e.classList.remove("hidden!"));
158-
159-
hideButton();
160-
});
161-
162144
function updateFilter() {
163145
const entries = [
164146
...document.querySelectorAll<HTMLElement>("[data-products]"),
@@ -170,7 +152,7 @@ const props = {
170152

171153
const filtered = entries
172154
.filter((e) => filterByProduct(e, value))
173-
.slice(0, 10);
155+
.slice(0, 5);
174156

175157
for (const entry of entries) {
176158
const show = filtered.includes(entry);
@@ -191,27 +173,6 @@ const props = {
191173
}
192174

193175
history.replaceState(null, "", url.href);
194-
195-
hideButton();
196-
}
197-
198-
function hideButton() {
199-
const entries = [
200-
...document.querySelectorAll<HTMLDivElement>("[data-products]"),
201-
];
202-
203-
if (entries.length === 0) return;
204-
205-
const filtered = entries.filter((p) => filterByProduct(p, filter!.value));
206-
207-
const visible = filtered.filter((p) => !p.classList.contains("hidden!"));
208-
const hidden = filtered.length - visible.length;
209-
210-
if (hidden > 0) {
211-
button!.classList.remove("hidden!");
212-
} else {
213-
button!.classList.add("hidden!");
214-
}
215176
}
216177
</script>
217178

0 commit comments

Comments
 (0)