Forráskód Böngészése

add `reason` to the docs

Artur Paikin 4 éve
szülő
commit
f9093c59d2
2 módosított fájl, 25 hozzáadás és 1 törlés
  1. 10 0
      website/src/docs/dashboard.md
  2. 15 1
      website/src/docs/uppy.md

+ 10 - 0
website/src/docs/dashboard.md

@@ -193,6 +193,16 @@ See also `disableStatusBar` option, which can hide the progress and upload butto
 
 Sometimes you might want to let users remove an uploaded file. Enabling this option only shows the remove `X` button in the Dashboard UI, but to actually send a request you should listen to [`file-removed`](https://uppy.io/docs/uppy/#file-removed) event and add your logic there.
 
+```js
+uppy.on('file-removed', (file, reason) => {
+  if (reason === 'removed-by-user') {
+    sendDeleteRequestForFile(file)
+  }
+})
+```
+
+For an implementation example, please see [#2301](https://github.com/transloadit/uppy/issues/2301#issue-628931176)).
+
 ### `note: null`
 
 Optionally, specify a string of text that explains something about the upload for the user. This is a place to explain any `restrictions` that are put in place. For example: `'Images and video only, 2–3 files, up to 1 MB'`.

+ 15 - 1
website/src/docs/uppy.md

@@ -660,11 +660,25 @@ uppy.on('file-added', (file) => {
 Fired each time a file is removed.
 
 ```javascript
-uppy.on('file-removed', (file) => {
+uppy.on('file-removed', (file, reason) => {
   console.log('Removed file', file)
 })
 ```
 
+Reason is provided as a second argument, so that you can distinguish when a user manually removed a file in the UI vs API calling `uppy.reset()` or `uppy.cancel()`. See [#2301](https://github.com/transloadit/uppy/issues/2301#issue-628931176) for details.
+
+Current reasons are: `removed-by-user` and `cancel-all`.
+
+```js
+uppy.on('file-removed', (file, reason) => {
+  removeFileFromUploadingCounterUI(file)
+
+  if (reason === 'removed-by-user') {
+    sendDeleteRequestForFile(file)
+  }
+})
+```
+
 ### `upload`
 
 Fired when upload starts.