1- use leptos:: prelude:: * ;
1+ use leptos:: { leptos_dom :: logging :: console_warn , prelude:: * } ;
22
33use crate :: components:: sponsor_block:: { SponsorBlock , SponsorVariant } ;
44
@@ -80,6 +80,8 @@ fn sponsors() -> impl IntoView {
8080 } ,
8181 ] ;
8282
83+ // Sponsors will be "popped" from the buffer, so reverse it
84+ // to get the same order as written
8385 sponsors_buf. reverse ( ) ;
8486
8587 const SPONSOR_BRICKS : usize = 26 ;
@@ -120,7 +122,7 @@ fn sponsors() -> impl IntoView {
120122 next_id
121123 } ;
122124
123- BRICKS . map ( |b| match b {
125+ let view = BRICKS . map ( |b| match b {
124126 SponsorBrick :: Sponsor ( c) if let Some ( sponsor) = sponsors_buf. pop ( ) => {
125127 view ! {
126128 <SponsorBlock index=next_id( ) variant=sponsor. variant class=c>
@@ -133,11 +135,29 @@ fn sponsors() -> impl IntoView {
133135 }
134136 }
135137 . into_any ( ) ,
138+ // If there's no more sponsors, just show it as random empty brick.
139+ // This allows to design and assign spaces to sponsors even if not enough
136140 SponsorBrick :: Sponsor ( c) | SponsorBrick :: Empty ( c) => view ! { <SponsorBlock index=next_id( ) variant=SponsorVariant :: random_colored( ) class=c /> }
137141 . into_any ( ) ,
142+ // Reserve an entire brick.
143+ // Consult "What the hell???" section (below) to know more about this.
138144 SponsorBrick :: Space ( c) => view ! { <div class=format!( "col-span-4 {c}" ) /> }
139145 . into_any ( ) ,
140- } )
146+ } ) ;
147+
148+ if !sponsors_buf. is_empty ( ) {
149+ console_warn ( & format ! (
150+ "{} Sponsors left. Some sponsors are not rendered: {}" ,
151+ sponsors_buf. len( ) ,
152+ sponsors_buf
153+ . into_iter( )
154+ . map( |s| s. alt)
155+ . collect:: <Vec <_>>( )
156+ . join( ", " )
157+ ) ) ;
158+ }
159+
160+ view
141161}
142162
143163#[ component]
@@ -156,9 +176,17 @@ pub fn OurSponsorsSection() -> impl IntoView {
156176 <img src="/assets/new/logos/ferris-hero.png" alt="" width="300" />
157177 </div>
158178
179+ // What the hell???
180+ // R: The grid is composed from every brick section (each brick's top-connections)
181+ // to align correctly in any™ position a brick is located. The cols are just an
182+ // arbritrary amount of bricks that looks good in each breakpoint.
159183 <div
160184 style="--brick: 38px 35px 35px 34px;"
161- class="grid grid-cols-[repeat(3,var(--brick))] sm:grid-cols-[repeat(4,var(--brick))] md:grid-cols-[repeat(5,var(--brick))] lg:grid-cols-[repeat(7,var(--brick))]"
185+ class="grid \
186+ grid-cols-[repeat(3,var(--brick))] \
187+ sm:grid-cols-[repeat(4,var(--brick))] \
188+ md:grid-cols-[repeat(5,var(--brick))] \
189+ lg:grid-cols-[repeat(7,var(--brick))]"
162190 >
163191 { sponsors}
164192 </div>
0 commit comments