diff --git a/src/plugins/GoogleDrive.js b/src/plugins/GoogleDrive.js index c0430967a..21731f503 100644 --- a/src/plugins/GoogleDrive.js +++ b/src/plugins/GoogleDrive.js @@ -30,22 +30,15 @@ export default class Google extends Plugin { } update (state) { + if (typeof this.core.getState().googleDrive !== 'undefined') { + console.log(this.core.getState().googleDrive.directory) + } if (typeof this.el === 'undefined') { return } const newEl = this.render(this.core.state) yo.update(this.el, newEl) - - // setTimeout(() => { - // const folders = Utils.qsa('.GoogleDriveFolder') - // const files = Utils.qsa('.GoogleDriveFile') - // console.log(folders) - // console.log(files) - - // folders.forEach((folder) => folder.addEventListener('click', (e) => this.getFolder(folder.dataset.id))) - // files.forEach((file) => file.addEventListener('click', (e) => this.getFile(file.dataset.id))) - // }, 5000) } updateState (newState) { @@ -56,6 +49,7 @@ export default class Google extends Plugin { } focus () { + console.log('GoogleDrive: focus') this.checkAuthentication() .then((res) => { if (!this.isAuthenticated) { @@ -91,7 +85,7 @@ export default class Google extends Plugin { .catch((err) => err) } - getFolder (id = this.core.state.googleDrive.directory) { + getFolder (id = 'root') { return fetch(`${this.opts.host}/google/list?dir=${id}`, { method: 'get', credentials: 'include', @@ -129,11 +123,24 @@ export default class Google extends Plugin { }) } - getSubFolder (id) { + getSubFolder (id, title) { this.getFolder(id) - .then((newState) => { - console.log(newState) - this.updateState(newState) + .then((data) => { + const state = this.core.getState().googleDrive + console.log(id) + const index = state.directory.findIndex((dir) => id === dir.id) + let directory + + if (index !== -1) { + directory = state.directory.slice(0, index + 1) + } else { + directory = state.directory.concat([{ + id, + title + }]) + } + + this.updateState(Utils.extend(data, {directory})) }) } @@ -177,7 +184,10 @@ export default class Google extends Plugin { authenticated: false, files: [], folders: [], - directory: 'root' + directory: { + title: 'My Drive', + id: 'root' + } } this.updateState(newState) @@ -196,12 +206,14 @@ export default class Google extends Plugin { } renderBrowser (state) { - const folders = state.folders.map((folder) => yo`