Skip to content

Commit

Permalink
Photos picker: Integrate GooglePhotos connection upgrade (#97117)
Browse files Browse the repository at this point in the history
* Photos picker: Disable session fetching if there is no feature flag

* Update logic to refetch connection if it's an invalid status

* Photos picker: create upgrade component

* Integrate google photos connection upgrade screen
  • Loading branch information
bogiii authored Dec 6, 2024
1 parent 58aeca9 commit 6143c15
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
4 changes: 3 additions & 1 deletion client/data/media/with-google-photos-picker-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export const withGooglePhotosPickerSession = createHigherOrderComponent( ( Wrapp
);
const photosPickerSession = useSelector( ( state ) => getGooglePhotosPickerSession( state ) );

const { data: cachedSession } = useGooglePhotosPickerSessionQuery( cachedSessionId );
const { data: cachedSession } = useGooglePhotosPickerSessionQuery( cachedSessionId, {
enabled: !! photosPickerApiEnabled,
} );
const { createSession, isPending } = useCreateGooglePhotosPickerSessionMutation();
const { mutate: deletePickerSession } = useDeleteGooglePhotosPickerSessionMutation();

Expand Down
13 changes: 12 additions & 1 deletion client/my-sites/media-library/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
MEDIA_IMAGE_THUMBNAIL,
SCALE_TOUCH_GRID,
} from 'calypso/lib/media/constants';
import GooglePhotosPickerButton from 'calypso/my-sites/media-library/google-photos-picker-button';
import InlineConnection from 'calypso/sites/marketing/connections/inline-connection';
import { pauseGuidedTour, resumeGuidedTour } from 'calypso/state/guided-tours/actions';
import { getGuidedTourState } from 'calypso/state/guided-tours/selectors';
Expand All @@ -37,6 +36,8 @@ import {
import { getSiteSlug, isJetpackSite } from 'calypso/state/sites/selectors';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import MediaLibraryExternalHeader from './external-media-header';
import GooglePhotosAuthUpgrade from './google-photos-auth-upgrade';
import GooglePhotosPickerButton from './google-photos-picker-button';
import MediaLibraryHeader from './header';
import MediaLibraryList from './list';
import './content.scss';
Expand Down Expand Up @@ -142,6 +143,12 @@ export class MediaLibraryContent extends Component {
return false;
}

hasGoogleInvalidConnection( props ) {
const { googleConnection, source } = props;

return source === 'google_photos' && googleConnection && googleConnection.status === 'invalid';
}

renderErrors() {
const { isJetpack, mediaValidationErrorTypes, site, siteSlug, translate } = this.props;
return map( groupBy( mediaValidationErrorTypes ), ( occurrences, errorType ) => {
Expand Down Expand Up @@ -409,6 +416,10 @@ export class MediaLibraryContent extends Component {
);
}

if ( this.hasGoogleInvalidConnection( this.props ) ) {
return <GooglePhotosAuthUpgrade connection={ this.props.googleConnection } />;
}

if ( this.needsToBeConnected() ) {
return this.renderConnectExternalMedia();
}
Expand Down
46 changes: 46 additions & 0 deletions client/my-sites/media-library/google-photos-auth-upgrade.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Button } from '@wordpress/components';
import { useTranslate } from 'i18n-calypso';
import { useState } from 'react';
import { useDispatch } from 'calypso/state';
import { deleteStoredKeyringConnection } from 'calypso/state/sharing/keyring/actions';
import type { Connection } from 'calypso/sites/marketing/connections/types';

interface Props {
connection: Connection;
}
const GooglePhotosAutUpgrade = ( props: Props ) => {
const translate = useTranslate();
const dispatch = useDispatch();
const { connection } = props;
const [ isDisconnecting, setIsDisconnecting ] = useState( false );

return (
<div className="media-library__connect-message">
<p>
<img
src="/calypso/images/sharing/google-photos-logo-text.svg?v=20241124"
width="400"
alt={ translate( 'Google Photos' ) }
/>
</p>
<p>
{ translate(
"We've updated our Google Photos service. You will need to disconnect and reconnect to continue accessing your photos."
) }
</p>

<Button
variant="secondary"
isBusy={ isDisconnecting }
onClick={ () => {
dispatch( deleteStoredKeyringConnection( connection ) );
setIsDisconnecting( true );
} }
>
{ translate( 'Disconnect from Google Photos' ) }
</Button>
</div>
);
};

export default GooglePhotosAutUpgrade;
12 changes: 8 additions & 4 deletions client/my-sites/media-library/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ const isConnected = ( state, source ) =>
! sourceNeedsKeyring( source ) ||
some( getKeyringConnections( state ), { type: 'other', status: 'ok', service: source } );

const needsKeyring = ( state, source ) =>
sourceNeedsKeyring( source ) &&
! isKeyringConnectionsFetching( state ) &&
! some( getKeyringConnections( state ), { type: 'other', status: 'ok' } );
const needsKeyring = ( state, source ) => {
return (
sourceNeedsKeyring( source ) &&
! isKeyringConnectionsFetching( state ) &&
( ! some( getKeyringConnections( state ), { type: 'other', status: 'ok' } ) ||
! some( getKeyringConnections( state ), { type: 'other', status: 'invalid' } ) )
);
};

class MediaLibrary extends Component {
static propTypes = {
Expand Down

0 comments on commit 6143c15

Please sign in to comment.