From 0774f2b6fcf3ad666be07398b6a3da46f4c06b21 Mon Sep 17 00:00:00 2001 From: Quentin Rousseau Date: Thu, 16 Jun 2022 00:24:21 -0700 Subject: [PATCH] Release 2.0.0 --- CHANGELOG.md | 4 +++ demo/index.html | 3 +- package.json | 4 +-- src/google-contacts.js | 74 ++++++++++++++++++++++-------------------- src/icon.js | 56 +++++++++++++++++++------------- 5 files changed, 80 insertions(+), 61 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43df3d7..4b94826 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.0 + +- Contact API deprecation solved and People API implementation added + ## 1.0.1 - Fix extractGivenNameFromEntry & extractFamilyNameFromEntry is not defined diff --git a/demo/index.html b/demo/index.html index 68c252a..757b43b 100644 --- a/demo/index.html +++ b/demo/index.html @@ -1,8 +1,7 @@ - +
- \ No newline at end of file diff --git a/package.json b/package.json index 9c086a2..f7ba0da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-google-contacts", - "version": "1.0.1", + "version": "2.0.0", "description": "A Google Button to import user's gmail contacts", "main": "dist/google-contacts.js", "scripts": { @@ -67,7 +67,7 @@ "react-hot-loader": "4.13.0", "react-test-renderer": "17.0.1", "webpack": "5.17.0", - "webpack-cli": "4.4.0", + "webpack-cli": "4.10.0", "webpack-dev-server": "3.11.2" }, "peerDependencies": { diff --git a/src/google-contacts.js b/src/google-contacts.js index d30cad9..bd7fee8 100755 --- a/src/google-contacts.js +++ b/src/google-contacts.js @@ -42,7 +42,7 @@ class GoogleContacts extends Component { } handleImportContacts(res, pageToken = null) { - const { onFailure } = this.props + const { onFailure, maxResults } = this.props if (res) { const authResponse = res.getAuthResponse() @@ -52,7 +52,7 @@ class GoogleContacts extends Component { path: 'https://people.googleapis.com/v1/otherContacts', params: { readMask: 'names,emailAddresses', - pageSize: this.props.maxResults > 1000 ? 1000 : this.props.maxResults, + pageSize: maxResults > 1000 ? 1000 : maxResults, ...(pageToken && { pageToken }) }, headers: { @@ -69,6 +69,7 @@ class GoogleContacts extends Component { } handleNextDataFetch(response, authResponse) { + const { maxResults } = this.props // Parse the response body const parsedData = JSON.parse(response.body) @@ -76,7 +77,7 @@ class GoogleContacts extends Component { this.allData = [...this.allData, ...parsedData.otherContacts] // If we have more data and the number of data we fethced is less than maxResults then fetch again using the nextPageToken - if ('nextPageToken' in parsedData && this.props.maxResults < this.allData.length) { + if ('nextPageToken' in parsedData && maxResults < this.allData.length) { this.handleImportContacts(authResponse, parsedData.nextPageToken) } else { this.handleParseContacts() @@ -118,6 +119,8 @@ class GoogleContacts extends Component { onSuccess } = this.props + const { disable } = this.state + const params = { client_id: clientId, cookie_policy: cookiePolicy, @@ -137,7 +140,7 @@ class GoogleContacts extends Component { if (e) { e.preventDefault() // to prevent submit if used within form } - if (!this.state.disabled) { + if (!disable) { const _signIn = () => { const auth2 = window.gapi.auth2.getAuthInstance() const options = { prompt } @@ -166,8 +169,9 @@ class GoogleContacts extends Component { } render() { - const { tag, type, className, disabledStyle, buttonText, children, render, theme, icon } = this.props - const disabled = this.state.disabled || this.props.disabled + const { tag, type, className, disabledStyle, buttonText, children, render, theme, icon, disabled: disabledProps } = this.props + const { active, hovered, disabled: disabledState } = this.state + const disabled = disabledState || disabledProps if (render) { return render({ onClick: this.signIn }) @@ -204,7 +208,7 @@ class GoogleContacts extends Component { return Object.assign({}, initialStyle, disabledStyle) } - if (this.state.active) { + if (active) { if (theme === 'dark') { return Object.assign({}, initialStyle, activeStyle) } @@ -212,7 +216,7 @@ class GoogleContacts extends Component { return Object.assign({}, initialStyle, activeStyle) } - if (this.state.hovered) { + if (hovered) { return Object.assign({}, initialStyle, hoveredStyle) } @@ -232,7 +236,7 @@ class GoogleContacts extends Component { className }, [ - icon && , + icon && , {children || buttonText} @@ -244,50 +248,50 @@ class GoogleContacts extends Component { } GoogleContacts.propTypes = { - onSuccess: PropTypes.func.isRequired, - onFailure: PropTypes.func.isRequired, - clientId: PropTypes.string.isRequired, - jsSrc: PropTypes.string, - onRequest: PropTypes.func, + accessType: PropTypes.string, buttonText: PropTypes.node, + children: PropTypes.node, className: PropTypes.string, - redirectUri: PropTypes.string, + clientId: PropTypes.string.isRequired, cookiePolicy: PropTypes.string, - loginHint: PropTypes.string, - hostedDomain: PropTypes.string, - children: PropTypes.node, - disabledStyle: PropTypes.object, - prompt: PropTypes.string, - tag: PropTypes.string, disabled: PropTypes.bool, + disabledStyle: PropTypes.object, discoveryDocs: PropTypes.array, - uxMode: PropTypes.string, - responseType: PropTypes.string, - type: PropTypes.string, - accessType: PropTypes.string, + hostedDomain: PropTypes.string, + icon: PropTypes.bool, + jsSrc: PropTypes.string, + loginHint: PropTypes.string, + maxResults: PropTypes.number, + onFailure: PropTypes.func.isRequired, + onRequest: PropTypes.func, + onSuccess: PropTypes.func.isRequired, + prompt: PropTypes.string, + redirectUri: PropTypes.string, render: PropTypes.func, + responseType: PropTypes.string, + tag: PropTypes.string, theme: PropTypes.string, - icon: PropTypes.bool, - maxResults: PropTypes.number + type: PropTypes.string, + uxMode: PropTypes.string } GoogleContacts.defaultProps = { - type: 'button', - tag: 'button', - buttonText: 'Import from Gmail', accessType: 'online', - prompt: 'consent', + buttonText: 'Import from Gmail', cookiePolicy: 'single_host_origin', - uxMode: 'popup', disabled: false, - maxResults: 999, disabledStyle: { opacity: 0.6 }, icon: true, - theme: 'light', + jsSrc: 'https://apis.google.com/js/api.js', + maxResults: 999, onRequest: () => {}, - jsSrc: 'https://apis.google.com/js/api.js' + prompt: 'consent', + tag: 'button', + theme: 'light', + type: 'button', + uxMode: 'popup' } export default GoogleContacts diff --git a/src/icon.js b/src/icon.js index 7de9a7c..82b8522 100644 --- a/src/icon.js +++ b/src/icon.js @@ -1,24 +1,36 @@ import React from 'react' -export default ({ active }) => ( -
- - - - - - - - - -
-) +export default function Icon({ active }) { + return ( +
+ + + + + + + + + +
+ ) +}