Code Monkey home page Code Monkey logo

Comments (4)

omcg33 avatar omcg33 commented on June 1, 2024

export const Uploader = React.memo((props: IProps) => {
  const {
    owner,
    concurrent = false,
    maxConcurrent = 5,
    multiple = false,
    grouped = false,
    accept,
    onItemFinish,
    onBatchFinish,
    listeners,
    maxUploadCount = Number.MAX_SAFE_INTEGER,
    dropzoneProps,
    enhancer,
    params = {},
    ...rest
  } = props
  const previewMethodsRef = useRef<any>();
  const defaultListeners = useMemo(() => ({
    [UPLOADER_EVENTS.BATCH_FINISH]: (batch) => {
      const { id, items } = batch;

      if (typeof onBatchFinish === "function") {
        const data = parseResponse(items[0].uploadResponse);
        console.log(`BATCH Finish - ${id}  ${JSON.stringify(data)}`);
        onBatchFinish(data);
      }
      //
      // if (previewMethodsRef.current?.clear) {
      //   previewMethodsRef!.current.clear();
      // }
    },
    [UPLOADER_EVENTS.ITEM_FINISH]: (item) => {
      if (typeof onItemFinish === "function") {
        const data = parseResponse(item.uploadResponse);
        console.log(`Item Finish - ${item.id} : ${item.file.name} ${JSON.stringify(data)}`);
        onItemFinish(data);
      }
    },
  }), []);
  const [previews, setPreviews] = useState();
  const getPreviewProps = useCallback((item, url, type) => ({ id: item.id, url, type }), []);
  const enhancerComposed = enhancer ? composeEnhancers(retryEnhancer, enhancer) : retryEnhancer;

  console.log(previews);

  return (
    <UploadyProvider
      // debug
      accept={accept}
      concurrent={concurrent}
      maxConcurrent={maxConcurrent}
      multiple={multiple}
      listeners={listeners ?? defaultListeners}
      grouped={grouped}
      forceJsonResponse
      enhancer={enhancerComposed}
      {...rest}
    >
      <UploadPreviews
        rememberPreviousBatches
        previewMethodsRef={previewMethodsRef}
        previewComponentProps={getPreviewProps}
        PreviewComponent={PreviewImage}
        onPreviewsChanged={setPreviews}
      />

      {
        (previews && previews.length < (multiple ? maxUploadCount : 1))
          ? <Dropzone {...dropzoneProps} accept={accept} multiple={multiple}/>
          : null as any
      }
    </UploadyProvider>
  )
})

from react-uploady.

yoavniran avatar yoavniran commented on June 1, 2024

@omcg33 please check with 0.6.0. fix for this was just released

from react-uploady.

omcg33 avatar omcg33 commented on June 1, 2024

Retry works, but i got something strange.
I abort and retry items in batch of 7 items, and got this error

batchHelpers.js:13 Uncaught (in promise) TypeError: Cannot read property 'batch' of undefined
    at getBatchFromState (batchHelpers.js:13)
    at triggerUploaderBatchEvent (batchHelpers.js:106)
    at cleanUpFinishedBatch (batchHelpers.js:98)
    at processFinishedRequest.js:65
    at processBatchItems.js:94

And all my not uploaded items is disappeared!

Steps to reproduce:

  1. Slow network speed
  2. Upload 10 items in 1 batch on multiply
  3. Abort and retry all of items step by step
  4. Wait then about 20% of items will be uploaded
  5. Items disappeared and you got error

from react-uploady.

yoavniran avatar yoavniran commented on June 1, 2024

Thanks. will look into it.
in the meantime, can you plz open a new bug?

from react-uploady.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.