Skip to content

Commit

Permalink
Font collection pagination: add min height to avoid infinite number (#…
Browse files Browse the repository at this point in the history
…59241)

* Add min height to avoid infinite number

* improve syntax

Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>

---------
Co-authored-by: matiasbenedetto <mmaattiiaass@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: carolinan <poena@git.wordpress.org>
  • Loading branch information
5 people authored Feb 22, 2024
1 parent 38d7cb6 commit 2e1d805
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const DEFAULT_CATEGORY = {
slug: 'all',
name: _x( 'All', 'font categories' ),
};

const MIN_WINDOW_HEIGHT = 500;

function FontCollection( { slug } ) {
const requiresPermission = slug === 'google-fonts';

Expand Down Expand Up @@ -118,7 +121,8 @@ function FontCollection( { slug } ) {

// NOTE: The height of the font library modal unavailable to use for rendering font family items is roughly 417px
// The height of each font family item is 61px.
const pageSize = Math.floor( ( window.innerHeight - 417 ) / 61 );
const windowHeight = Math.max( window.innerHeight, MIN_WINDOW_HEIGHT );
const pageSize = Math.floor( ( windowHeight - 417 ) / 61 );
const totalPages = Math.ceil( fonts.length / pageSize );
const itemsStart = ( page - 1 ) * pageSize;
const itemsLimit = page * pageSize;
Expand Down

1 comment on commit 2e1d805

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 2e1d805.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/8005905303
📝 Reported issues:

Please sign in to comment.