Skip to content
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: add option to revoke access to Google Fonts #59205

Merged
merged 5 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import {
FlexItem,
Flex,
Button,
DropdownMenu,
} from '@wordpress/components';
import { debounce } from '@wordpress/compose';
import { sprintf, __, _x } from '@wordpress/i18n';
import { search, closeSmall } from '@wordpress/icons';
import { search, closeSmall, moreVertical } from '@wordpress/icons';

/**
* Internal dependencies
Expand Down Expand Up @@ -76,6 +77,14 @@ function FontCollection( { slug } ) {
return () => window.removeEventListener( 'storage', handleStorage );
}, [ slug, requiresPermission ] );

const revokeAccess = () => {
window.localStorage.setItem(
'wp-font-library-google-fonts-permission',
carolinan marked this conversation as resolved.
Show resolved Hide resolved
'false'
);
window.dispatchEvent( new Event( 'storage' ) );
};

useEffect( () => {
const fetchFontCollection = async () => {
try {
Expand Down Expand Up @@ -223,11 +232,31 @@ function FontCollection( { slug } ) {
);
}

let actionsComponent = null;
if ( ! renderConfirmDialog && ! selectedFont ) {
carolinan marked this conversation as resolved.
Show resolved Hide resolved
actionsComponent = (
<DropdownMenu
icon={ moreVertical }
label={ __( 'Actions' ) }
popoverProps={ {
position: 'bottom left',
} }
controls={ [
{
title: __( 'Revoke access to Google Fonts' ),
onClick: revokeAccess,
},
] }
/>
);
}

carolinan marked this conversation as resolved.
Show resolved Hide resolved
return (
<TabPanelLayout
title={
! selectedFont ? selectedCollection.name : selectedFont.name
}
actions={ actionsComponent }
description={
! selectedFont
? selectedCollection.description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Button,
Notice,
FlexBlock,
FlexItem,
} from '@wordpress/components';
import { chevronLeft } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
Expand All @@ -27,6 +28,7 @@ function TabPanelLayout( {
handleBack,
children,
footer,
actions,
} ) {
const { setNotice } = useContext( FontLibraryContext );

Expand All @@ -35,7 +37,11 @@ function TabPanelLayout( {
<Spacer margin={ 4 } />
<VStack spacing={ 4 } justify="space-between">
<VStack spacing={ 2 }>
<HStack justify="flex-start">
<HStack
justify={
!! handleBack ? 'flex-start' : 'space-between'
}
>
{ !! handleBack && (
<Button
variant="tertiary"
Expand All @@ -54,6 +60,7 @@ function TabPanelLayout( {
{ title }
</Heading>
) }
{ actions && <FlexItem>{ actions }</FlexItem> }
</HStack>
{ description && <Text>{ description }</Text> }
{ notice && (
Expand Down
Loading