Kaynağa Gözat

Do everything on single click, and update Provider with new Utils.getFileType behavior

handleFileDoubleClick, handleFolderDoubleClick --> handleFileClick,
handleFolderClick
Artur Paikin 7 yıl önce
ebeveyn
işleme
561f002de5

+ 5 - 0
src/core/Utils.js

@@ -182,6 +182,11 @@ function getFileType (file) {
     'mp3': 'audio/mp3'
   }
 
+  // no smart detection for remote files, just trust the provider
+  if (file.isRemote) {
+    return Promise.resolve(file.type.split('/'))
+  }
+
   const fileExtension = getFileNameAndExtension(file.name)[1]
 
   // 1. try to determine file type from magic bytes with file-type module

+ 3 - 3
src/generic-provider-views/Browser.js

@@ -40,9 +40,9 @@ module.exports = (props) => {
             activeRow: props.isActiveRow,
             sortByTitle: props.sortByTitle,
             sortByDate: props.sortByDate,
-            handleRowClick: props.handleRowClick,
-            handleFileDoubleClick: props.addFile,
-            handleFolderDoubleClick: props.getNextFolder,
+            // handleRowClick: props.handleRowClick,
+            handleFileClick: props.addFile,
+            handleFolderClick: props.getNextFolder,
             getItemName: props.getItemName,
             getItemIcon: props.getItemIcon
           })}

+ 4 - 4
src/generic-provider-views/Table.js

@@ -23,8 +23,8 @@ module.exports = (props) => {
             title: props.getItemName(folder),
             active: props.activeRow(folder),
             getItemIcon: () => props.getItemIcon(folder),
-            handleClick: () => props.handleRowClick(folder),
-            handleDoubleClick: () => props.handleFolderDoubleClick(folder),
+            // handleClick: () => props.handleRowClick(folder),
+            handleClick: () => props.handleFolderClick(folder),
             columns: props.columns
           })
         })}
@@ -33,8 +33,8 @@ module.exports = (props) => {
             title: props.getItemName(file),
             active: props.activeRow(file),
             getItemIcon: () => props.getItemIcon(file),
-            handleClick: () => props.handleRowClick(file),
-            handleDoubleClick: () => props.handleFileDoubleClick(file),
+            // handleClick: () => props.handleRowClick(file),
+            handleClick: () => props.handleFileClick(file),
             columns: props.columns
           })
         })}

+ 1 - 1
src/generic-provider-views/TableRow.js

@@ -4,7 +4,7 @@ const Column = require('./TableColumn')
 module.exports = (props) => {
   const classes = props.active ? 'BrowserTable-row is-active' : 'BrowserTable-row'
   return html`
-    <tr onclick=${props.handleClick} ondblclick=${props.handleDoubleClick} class=${classes}>
+    <tr onclick=${props.handleClick} class=${classes}>
       ${Column({
         getItemIcon: props.getItemIcon,
         value: props.title

+ 16 - 14
src/generic-provider-views/index.js

@@ -49,7 +49,7 @@ module.exports = class View {
     this.filterQuery = this.filterQuery.bind(this)
     this.getFolder = this.getFolder.bind(this)
     this.getNextFolder = this.getNextFolder.bind(this)
-    this.handleRowClick = this.handleRowClick.bind(this)
+    // this.handleRowClick = this.handleRowClick.bind(this)
     this.logout = this.logout.bind(this)
     this.handleAuth = this.handleAuth.bind(this)
     this.handleDemoAuth = this.handleDemoAuth.bind(this)
@@ -139,11 +139,13 @@ module.exports = class View {
       }
     }
 
-    if (Utils.getFileType(tagFile)[0] === 'image') {
-      tagFile.preview = `${this.plugin.opts.host}/${this.Provider.id}/thumbnail/${this.plugin.getItemRequestPath(file)}`
-    }
-    console.log('adding file')
-    this.plugin.core.emitter.emit('core:file-add', tagFile)
+    Utils.getFileType(tagFile).then(fileType => {
+      if (Utils.isPreviewSupported(fileType[1])) {
+        tagFile.preview = `${this.plugin.opts.host}/${this.Provider.id}/thumbnail/${this.plugin.getItemRequestPath(file)}`
+      }
+      this.plugin.core.log('Adding remote file')
+      this.plugin.core.emitter.emit('core:file-add', tagFile)
+    })
   }
 
   /**
@@ -169,14 +171,14 @@ module.exports = class View {
    * Used to set active file/folder.
    * @param  {Object} file   Active file/folder
    */
-  handleRowClick (file) {
-    const state = this.plugin.core.getState()[this.plugin.stateId]
-    const newState = Object.assign({}, state, {
-      activeRow: this.plugin.getItemId(file)
-    })
-
-    this.updateState(newState)
-  }
+  // handleRowClick (file) {
+  //   const state = this.plugin.core.getState()[this.plugin.stateId]
+  //   const newState = Object.assign({}, state, {
+  //     activeRow: this.plugin.getItemId(file)
+  //   })
+
+  //   this.updateState(newState)
+  // }
 
   filterQuery (e) {
     const state = this.plugin.core.getState()[this.plugin.stateId]