-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Font Library: refactor FontsGrid component #58503
Conversation
*/ | ||
import FontCard from './font-card'; | ||
|
||
const PAGE_SIZE = 32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pageSize
prop that the FontsGrid component has is never used, so I defined it as a constant.
{ items.map( ( child, i ) => { | ||
if ( i === itemsLimit - 1 ) { | ||
return ( | ||
<div key={ child.key } ref={ setLastItem }> | ||
{ child } | ||
</div> | ||
); | ||
} | ||
return <div key={ child.key }>{ child }</div>; | ||
} ) } | ||
{ fonts.slice( 0, itemsLimit ).map( ( font, i ) => ( | ||
<FontCard | ||
key={ i } | ||
font={ font } | ||
ref={ | ||
i === itemsLimit - 1 ? setLastItem : undefined | ||
} | ||
onChange={ onChange } | ||
/> | ||
) ) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactoring allows us to remove unnecessary div
elements.
Size Change: -48 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @t-hamano, thanks for submitting this PR :)
I've tested it, and it's working fine, but I'm not sure if it's still relevant given the on-going implementation of the pagination as requested in this issue.
@pbking, could you take a look at this and confirm, please?
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@matiasbenedetto I think #58794 will definitely have a higher priority. Therefore, I'm fine with #58794 being advanced before this PR. Once #58794 is merged, I would like to resolve conflicts 👍 |
Indeed, I believe this won't be relevant if we land the pagination branch; that does away with the FontsGrid component. There might be other improvements in there that are relevant and useful. |
This PR now has too many conflicts with trunk. Therefore, I would like to close this PR and submit a new PR if necessary. |
What?
This PR refactors the FontsGrid component to improve code quality.
Why?
The current
FontsGrid
component receiveschildren
. In order to pass thechildren
to theFontsGrid
component, we render theFontCard
component using themap()
function. Inside theFontsGrid
component, we loop through its children again, causing a double loop.We should simply pass the fonts as props to the
FontsGrid
component, and theFontsGrid
component should render based on those props.How?
At the same time as refactoring, I integrated
LibraryFontCard
andFontCard
components. This is because the component names are similar and difficult to identify. Also, theFontCard
component is completely dependent on theLibraryFontCard
component, so there shouldn't be any need to split it.Testing Instructions
The layout and behavior of the Font Library should remain unchanged.