@nyris/nyris-webapp 0.3.74 → 0.3.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@nyris/nyris-webapp",
3
- "version": "0.3.74",
3
+ "version": "0.3.75",
4
4
  "dependencies": {
5
5
  "@auth0/auth0-react": "^2.2.4",
6
6
  "@emailjs/browser": "^4.3.3",
7
- "@nyris/nyris-api": "^0.3.74",
8
- "@nyris/nyris-react-components": "^0.3.74",
7
+ "@nyris/nyris-api": "^0.3.75",
8
+ "@nyris/nyris-react-components": "^0.3.75",
9
9
  "@radix-ui/react-accordion": "^1.2.2",
10
10
  "@radix-ui/react-dialog": "^1.1.4",
11
11
  "@radix-ui/react-popover": "^1.1.4",
@@ -24,12 +24,12 @@ function DragDropFile(props: Props) {
24
24
  const { singleImageSearch } = useImageSearch();
25
25
  const { cadSearch } = useCadSearch();
26
26
 
27
- const handleUpload = (files: File[]) => {
27
+ const handleUpload = (file: File) => {
28
28
  navigate('/result');
29
29
 
30
- if (isCadFile(files[0])) {
30
+ if (isCadFile(file)) {
31
31
  cadSearch({
32
- file: files[0],
32
+ file: file,
33
33
  settings: window.settings,
34
34
  newSearch: true,
35
35
  }).then(res => {});
@@ -38,7 +38,7 @@ function DragDropFile(props: Props) {
38
38
  }
39
39
 
40
40
  singleImageSearch({
41
- image: files[0],
41
+ image: file,
42
42
  settings: window.settings,
43
43
  showFeedback: true,
44
44
  }).then(() => {});
@@ -78,9 +78,10 @@ function DragDropFile(props: Props) {
78
78
  </div>
79
79
  <input
80
80
  onChange={e => {
81
+ console.log({ e });
81
82
  e.stopPropagation();
82
- if (e.target.files) {
83
- handleUpload(Array.from(e.target.files));
83
+ if (e.target.files && e.target.files[0]) {
84
+ handleUpload(e.target.files[0]);
84
85
  e.target.value = '';
85
86
  }
86
87
  }}
@@ -140,7 +140,7 @@ function Product(props: Props) {
140
140
  <img
141
141
  src={main_image_link}
142
142
  key={main_image_link}
143
- alt="image_item"
143
+ alt=""
144
144
  className="img-style product-image"
145
145
  style={{
146
146
  width: '100%',
@@ -1,7 +1,7 @@
1
1
  import { useState, useCallback } from 'react';
2
2
 
3
3
  interface UseDragAndDropOptions {
4
- onDropCallback?: (files: File[]) => void;
4
+ onDropCallback?: (file: File) => void;
5
5
  }
6
6
 
7
7
  interface UseDragAndDropReturn {
@@ -13,6 +13,23 @@ interface UseDragAndDropReturn {
13
13
  };
14
14
  }
15
15
 
16
+ const getImageFromUrl = async (
17
+ url: string,
18
+ onDownload: (file: File) => void,
19
+ ) => {
20
+ try {
21
+ const response = await fetch(url);
22
+ const blob = await response.blob();
23
+ const file = new File([blob], 'image.png', { type: blob.type });
24
+ // URL.createObjectURL(file);
25
+ if (onDownload) {
26
+ onDownload(file);
27
+ }
28
+ } catch (err) {
29
+ console.error('Failed to fetch image:', err);
30
+ }
31
+ };
32
+
16
33
  const useDragAndDrop = ({
17
34
  onDropCallback,
18
35
  }: UseDragAndDropOptions = {}): UseDragAndDropReturn => {
@@ -29,13 +46,21 @@ const useDragAndDrop = ({
29
46
  }, []);
30
47
 
31
48
  const onDrop = useCallback(
32
- (event: React.DragEvent) => {
49
+ async (event: React.DragEvent) => {
33
50
  event.preventDefault();
34
51
  setIsDragging(false);
35
52
 
36
- const droppedFiles = Array.from(event.dataTransfer.files);
53
+ const url =
54
+ event.dataTransfer.getData('text/uri-list') ||
55
+ event.dataTransfer.getData('text/plain');
56
+
57
+ if (url && url.startsWith('http') && onDropCallback) {
58
+ getImageFromUrl(url, onDropCallback);
59
+ return;
60
+ }
61
+
37
62
  if (onDropCallback) {
38
- onDropCallback(droppedFiles);
63
+ onDropCallback(event.dataTransfer.files[0]);
39
64
  }
40
65
  },
41
66
  [onDropCallback],