diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.js
index 02f5f1a617..f5e94d7274 100644
--- a/examples/demo-app/src/app.js
+++ b/examples/demo-app/src/app.js
@@ -97,6 +97,15 @@ const GlobalStyle = styled.div`
}
`;
+const CONTAINER_STYLE = {
+ transition: 'margin 1s, height 1s',
+ position: 'absolute',
+ width: '100%',
+ height: '100%',
+ left: 0,
+ top: 0
+};
+
class App extends Component {
state = {
showBanner: false,
@@ -416,16 +425,7 @@ class App extends Component {
>
-
+
{({height, width}) => (
{
+ const link = this._authLink();
- const handleToken = async e => {
- // TODO: add security step to validate which domain the message is coming from
- if (authWindow) {
- authWindow.close();
- }
+ const authWindow = window.open(link, '_blank', 'width=1024,height=716');
- window.removeEventListener('message', handleToken);
+ const handleToken = async event => {
+ // if user has dev tools this will skip all the react-devtools events
+ if (!event.data.token) {
+ return;
+ }
- if (!e.data.token) {
- Console.warn('Failed to login to Dropbox');
- return;
- }
+ if (authWindow) {
+ authWindow.close();
+ window.removeEventListener('message', handleToken);
+ }
- this._dropbox.setAccessToken(e.data.token);
- // save user name
- const user = await this._getUser();
-
- if (window.localStorage) {
- window.localStorage.setItem(
- 'dropbox',
- JSON.stringify({
- // dropbox token doesn't expire unless revoked by the user
- token: e.data.token,
- user,
- timestamp: new Date()
- })
- );
- }
+ const {token} = event.data;
- if (typeof onCloudLoginSuccess === 'function') {
- onCloudLoginSuccess();
- }
- };
-
- window.addEventListener('message', handleToken);
- }
+ if (!token) {
+ reject('Failed to login to Dropbox');
+ return;
+ }
- async downloadMap(loadParams) {
- const token = this.getAccessToken();
- if (!token) {
- this.login(() => this.downloadMap(loadParams));
- }
- const result = await this._dropbox.filesDownload(loadParams);
- const json = await this._readFile(result.fileBlob);
+ this._dropbox.setAccessToken(token);
+ // save user name
+ const user = await this.getUser();
+
+ if (window.localStorage) {
+ window.localStorage.setItem(
+ 'dropbox',
+ JSON.stringify({
+ // dropbox token doesn't expire unless revoked by the user
+ token: token,
+ user,
+ timestamp: new Date()
+ })
+ );
+ }
- const response = {
- map: json,
- format: 'keplergl'
- };
+ resolve(user);
+ };
- this._loadParam = loadParams;
- return response;
+ window.addEventListener('message', handleToken);
+ });
}
+ /**
+ * returns a list of maps
+ */
async listMaps() {
// list files
try {
// https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesListFolder__anchor
const response = await this._dropbox.filesListFolder({
- path: this._path
+ path: `${this._path}`
});
const {pngs, visualizations} = this._parseEntries(response);
// https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesGetThumbnailBatch__anchor
@@ -148,15 +139,14 @@ export default class DropboxProvider extends Provider {
);
// append to visualizations
- thumbnails &&
- thumbnails.forEach(thb => {
- if (thb['.tag'] === 'success' && thb.thumbnail) {
- const matchViz = visualizations[pngs[thb.metadata.id] && pngs[thb.metadata.id].name];
- if (matchViz) {
- matchViz.thumbnail = `${IMAGE_URL_PREFIX}${thb.thumbnail}`;
- }
+ (thumbnails || []).forEach(thb => {
+ if (thb['.tag'] === 'success' && thb.thumbnail) {
+ const matchViz = visualizations[pngs[thb.metadata.id] && pngs[thb.metadata.id].name];
+ if (matchViz) {
+ matchViz.thumbnail = `${IMAGE_URL_PREFIX}${thb.thumbnail}`;
}
- });
+ }
+ });
// dropbox returns
return Object.values(visualizations).reverse();
@@ -166,49 +156,10 @@ export default class DropboxProvider extends Provider {
}
}
- getUserName() {
- // load user from
- if (window.localStorage) {
- const jsonString = window.localStorage.getItem('dropbox');
- const user = jsonString && JSON.parse(jsonString).user;
- return user;
- }
- return null;
- }
-
- async logout(onCloudLogoutSuccess) {
- const token = this._dropbox.getAccessToken();
-
- if (token) {
- await this._dropbox.authTokenRevoke();
- if (window.localStorage) {
- window.localStorage.removeItem('dropbox');
- }
- // re instantiate dropbox
- this._initializeDropbox();
- onCloudLogoutSuccess();
- }
- }
-
- isEnabled() {
- return this.clientId !== null;
- }
-
- hasPrivateStorage() {
- return PRIVATE_STORAGE_ENABLED;
- }
-
- hasSharingUrl() {
- return SHARING_ENABLED;
- }
-
/**
*
* @param mapData map data and config in one json object {map: {datasets: Array