DropZone.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { useDropzone } from 'react-dropzone'
  2. import React, { useMemo, useState, useEffect } from 'react'
  3. import { Upload, Button, DatePicker } from 'antd'
  4. import { UploadOutlined,SearchOutlined } from '@ant-design/icons'
  5. import { sortableContainer, sortableElement } from 'react-sortable-hoc'
  6. import { Router, Route, Link, Redirect, Switch } from 'react-router-dom'
  7. // import {backendURL} from '../actions'
  8. import { Image } from 'antd';
  9. import { arrayMove, arrayMoveImmutable, arrayMoveMutable } from 'array-move'
  10. export function Basic({ onLoad }) {
  11. const { acceptedFiles, getRootProps, getInputProps } = useDropzone()
  12. const files = acceptedFiles.map((file) => (
  13. <li key={file.path}>
  14. {file.path} - {file.size} bytes
  15. </li>
  16. ))
  17. console.log('acceptedFiles',acceptedFiles)
  18. useEffect(() => {
  19. if(acceptedFiles)
  20. onLoad(acceptedFiles)
  21. }
  22. , [acceptedFiles])
  23. return (
  24. <section className="container">
  25. <div {...getRootProps({ className: 'Dropzone' })}>
  26. <input {...getInputProps()} />
  27. <Button icon={<UploadOutlined />}>
  28. Drag 'n' drop some files here, or click to select files
  29. </Button>
  30. </div>
  31. <aside>
  32. <h4 style={{ color: 'black' }}>Files</h4>
  33. <ul>{files}</ul>
  34. </aside>
  35. </section>
  36. )
  37. }
  38. export function ImageDemo({_id,index,url}) {
  39. return (
  40. <SortableItem url={url} key={`item-${_id}`} index={index} />
  41. );
  42. }
  43. export const SortableItem = sortableElement(({ url }) => {
  44. // const [visible, setVisible] = useState(false);
  45. const [visible, setVisible] = useState(false)
  46. console.log('STATE PHOTO ', visible)
  47. // preview={{
  48. // visible,
  49. // src: '/' + value.url,
  50. // onVisibleChange: value => {
  51. // setVisible(value);
  52. // }}}
  53. return (
  54. <li>
  55. {/* <img style={{ maxWidth: '200px', maxHeight: '200px' }} src={ '/' + url} /> */}
  56. <Image
  57. width={200}
  58. style={{ maxWidth: '200px', maxHeight: '200px' }} src={ '/' + url}
  59. // style={{ display: 'none' }}
  60. // src={ '/' + url}
  61. preview={{
  62. visible,
  63. src: '/' + url,
  64. onVisibleChange: visible => {
  65. setVisible(visible);
  66. },
  67. }}
  68. onClick={() => setVisible(!visible)}
  69. />
  70. </li>
  71. )
  72. }
  73. )
  74. // style={{ maxWidth: '200px', maxHeight: '200px' }} src={ '/' + url}
  75. export const SortableContainer = sortableContainer(({ children }) => {
  76. return (
  77. <>
  78. <ul>{children}</ul>
  79. {/* <input value={title}/> */}
  80. </>
  81. )
  82. })