-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Social: Create a social service connect button
This is currently a proof of concept where we get the available external services and render a connect button, which in turn triggers the authentication flow for each service. To test it, the site must be sandboxed with D146389-code applied.
- Loading branch information
Showing
9 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
projects/js-packages/publicize-components/src/components/connect-button/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Button } from '@automattic/jetpack-components'; | ||
import { useCallback } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { requestExternalAccess } from '../../utils/request-external-access.js'; | ||
|
||
const ConnectButton = ( { connectUrl, onClose, className } ) => { | ||
const requestConnection = useCallback( | ||
() => requestExternalAccess( connectUrl, onClose ), | ||
[ connectUrl, onClose ] | ||
); | ||
return ( | ||
<Button className={ className } variant="secondary" onClick={ requestConnection }> | ||
{ __( 'Connect', 'jetpack' ) } | ||
</Button> | ||
); | ||
}; | ||
|
||
export default ConnectButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './get-share-message-max-length'; | ||
export * from './get-supported-additional-connections'; | ||
export * from './request-external-access'; | ||
export * from './types'; |
34 changes: 34 additions & 0 deletions
34
projects/js-packages/publicize-components/src/utils/request-external-access.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import PopupMonitor from '@automattic/popup-monitor'; | ||
|
||
/** | ||
* The callback function of the requestExternalAccess utility. | ||
* @callback requestCallback | ||
* @param {object} result - Received authentication data. | ||
* @param {number} result.keyring_id | ||
* @param {string} result.id_token | ||
* @param {object} result.user | ||
*/ | ||
|
||
/** | ||
* Utility for requesting authorization of sharing services. | ||
* @param {string} url - The URL to be loaded in the newly opened window. | ||
* @param {requestCallback} cb - The callback that handles the response. | ||
*/ | ||
export const requestExternalAccess = ( url, cb ) => { | ||
const popupMonitor = new PopupMonitor(); | ||
let lastMessage; | ||
|
||
popupMonitor.open( | ||
url, | ||
null, | ||
'toolbar=0,location=0,status=0,menubar=0,' + popupMonitor.getScreenCenterSpecs( 780, 700 ) | ||
); | ||
|
||
popupMonitor.once( 'close', () => { | ||
cb( lastMessage?.ID ? lastMessage : {} ); | ||
} ); | ||
|
||
popupMonitor.on( 'message', message => { | ||
lastMessage = message?.data; | ||
} ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters