@@ -27,7 +27,7 @@ const props = {
2727<StarlightPage {... props }>
2828 <Header notes ={ notes } />
2929 {
30- notes .map (async (entry ) => {
30+ notes .map (async (entry , idx ) => {
3131 const date = format (entry .data .date , " MMM dd, yyyy" );
3232
3333 const productIds = JSON .stringify (
@@ -37,7 +37,11 @@ const props = {
3737 const { Content } = await render (entry );
3838
3939 return (
40- <div class = " !mt-0 sm:flex" data-products = { productIds } >
40+ <div
41+ class = " !mt-0 sm:flex"
42+ data-products = { productIds }
43+ style = { ` display: ${idx >= 10 ? " none" : " " } ` }
44+ >
4145 <time
4246 datetime = { entry .data .date .toISOString ()}
4347 class = " whitespace-nowrap leading-6 sm:pr-4 sm:text-right"
@@ -68,6 +72,14 @@ const props = {
6872 );
6973 })
7074 }
75+ <div class =" flex items-center justify-center" >
76+ <button
77+ id =" changelogs-next-button"
78+ class =" h-12 cursor-pointer rounded bg-cl1-brand-orange px-6 font-medium text-cl1-black"
79+ >
80+ Load more items
81+ </button >
82+ </div >
7183</StarlightPage >
7284
7385<script >
@@ -76,32 +88,125 @@ const props = {
7688 );
7789
7890 filter?.addEventListener("change", () => {
79- const entries = document.querySelectorAll<HTMLElement>("[data-products]");
91+ const entries = [
92+ ...document.querySelectorAll<HTMLElement>("[data-products]"),
93+ ];
8094
8195 if (!entries) return;
8296
8397 const value = filter.value;
8498
85- if (value === "all") {
86- entries.forEach((entry) => (entry.style.display = ""));
99+ const filtered = entries
100+ .filter((e) => {
101+ if (value === "all") {
102+ return true;
103+ }
87104
88- return;
89- }
105+ if (!e.dataset.products) {
106+ return false;
107+ }
90108
91- for (const entry of entries) {
92- if (!entry.dataset.products) continue;
109+ const products: string[] = JSON.parse(e.dataset.products);
93110
94- const products = JSON.parse(entry.dataset.products);
111+ if (products.includes(value)) {
112+ return true;
113+ }
95114
96- const show = products.includes(value);
115+ return false;
116+ })
117+ .slice(0, 5);
118+
119+ for (const entry of entries) {
120+ const show = filtered.includes(entry);
97121
98122 if (show) {
99123 entry.style.display = "";
100124 } else {
101125 entry.style.display = "none";
102126 }
103127 }
128+
129+ hideButton();
104130 });
131+
132+ const button = document.querySelector<HTMLButtonElement>(
133+ "#changelogs-next-button",
134+ );
135+
136+ button?.addEventListener("click", () => {
137+ const entries = [
138+ ...document.querySelectorAll<HTMLElement>("[data-products]"),
139+ ];
140+
141+ if (!entries) return;
142+
143+ const value = filter!.value;
144+
145+ const hidden = entries
146+ .filter((e) => {
147+ if (e.style.display !== "none") {
148+ return false;
149+ }
150+
151+ if (value === "all") {
152+ return true;
153+ }
154+
155+ if (!e.dataset.products) {
156+ return false;
157+ }
158+
159+ const products: string[] = JSON.parse(e.dataset.products);
160+
161+ if (products.includes(value)) {
162+ return true;
163+ }
164+
165+ return false;
166+ })
167+ .slice(0, 10);
168+
169+ hidden.forEach((e) => (e.style.display = ""));
170+
171+ hideButton();
172+ });
173+
174+ function hideButton() {
175+ const entries = [
176+ ...document.querySelectorAll<HTMLDivElement>("[data-products]"),
177+ ];
178+
179+ if (entries.length === 0) return;
180+
181+ const filtered = entries.filter((p) => {
182+ const value = filter!.value;
183+
184+ if (value === "all") {
185+ return true;
186+ }
187+
188+ if (!p.dataset.products) {
189+ return false;
190+ }
191+
192+ const products: string[] = JSON.parse(p.dataset.products);
193+
194+ if (!products.includes(value)) {
195+ return false;
196+ }
197+
198+ return true;
199+ });
200+
201+ const visible = filtered.filter((p) => p.style.display !== "none");
202+ const hidden = filtered.length - visible.length;
203+
204+ if (hidden >= 10) {
205+ button!.style.display = "";
206+ } else {
207+ button!.style.display = "none";
208+ }
209+ }
105210</script >
106211
107212<style >
0 commit comments