Skip to content

Commit

Permalink
Simplify revisions count retrieval by using useGlobalStylesRevisions.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Nov 21, 2024
1 parent 68a7058 commit 2950c1d
Showing 1 changed file with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,12 @@ export function SidebarNavigationItemGlobalStyles( props ) {
export default function SidebarNavigationScreenGlobalStyles() {
const history = useHistory();
const { params } = useLocation();
const { isLoading: isLoadingRevisions } = useGlobalStylesRevisions();
const { isLoading: isLoadingRevisions, revisionsCount } =
useGlobalStylesRevisions();
const { openGeneralSidebar } = useDispatch( editSiteStore );
const { setEditorCanvasContainerView } = unlock(
useDispatch( editSiteStore )
);
const { revisionsCount } = useSelect( ( select ) => {
const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } =
select( coreStore );
const globalStylesId = __experimentalGetCurrentGlobalStylesId();
const globalStyles = globalStylesId
? getEntityRecord( 'root', 'globalStyles', globalStylesId )
: undefined;
return {
revisionsCount:
globalStyles?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0,
};
}, [] );
const { set: setPreference } = useDispatch( preferencesStore );

const openGlobalStyles = useCallback( async () => {
Expand Down Expand Up @@ -94,8 +83,9 @@ export default function SidebarNavigationScreenGlobalStyles() {
}, [ openGlobalStyles, setEditorCanvasContainerView ] );

// If there are no revisions, do not render a footer.
const hasRevisions = revisionsCount > 0;
const shouldShowGlobalStylesFooter = hasRevisions && ! isLoadingRevisions;
const shouldShowGlobalStylesFooter =
!! revisionsCount && ! isLoadingRevisions;

return (
<>
<SidebarNavigationScreen
Expand Down

0 comments on commit 2950c1d

Please sign in to comment.