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>

# Conflicts:
#	packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js
  • Loading branch information
matiasbenedetto authored and getdave committed Feb 27, 2024
1 parent 78a4740 commit 914e64e
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const DEFAULT_CATEGORY = {
};

const LOCAL_STORAGE_ITEM = 'wp-font-library-google-fonts-permission';
const MIN_WINDOW_HEIGHT = 500;

function FontCollection( { slug } ) {
const requiresPermission = slug === 'google-fonts';
Expand Down Expand Up @@ -143,7 +144,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

0 comments on commit 914e64e

Please sign in to comment.