@nyris/nyris-webapp 0.3.3 → 0.3.4
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/build/asset-manifest.json +8 -8
- package/build/index.html +1 -1
- package/build/{precache-manifest.01ce682577e62add75aa397b2a944b75.js → precache-manifest.9800bdc87f5a2c5d6d8a5d1a5287598f.js} +9 -9
- package/build/service-worker.js +1 -1
- package/build/static/js/2.29ddd567.chunk.js +3 -0
- package/build/static/js/{2.d1562c08.chunk.js.LICENSE.txt → 2.29ddd567.chunk.js.LICENSE.txt} +0 -9
- package/build/static/js/2.29ddd567.chunk.js.map +1 -0
- package/build/static/js/main.c35ded37.chunk.js +2 -0
- package/build/static/js/main.c35ded37.chunk.js.map +1 -0
- package/package.json +3 -3
- package/src/App.tsx +3 -6
- package/src/Store/Nyris.ts +7 -7
- package/src/Store/Search.ts +11 -10
- package/src/Store/Store.ts +12 -5
- package/src/components/DragDropFile.tsx +9 -9
- package/src/components/Feedback.tsx +2 -2
- package/src/components/Footer.tsx +1 -1
- package/src/components/HeaderMd.tsx +4 -5
- package/src/index.tsx +2 -1
- package/src/modules/LandingPage/{indexApp.tsx → App.tsx} +53 -227
- package/src/modules/LandingPage/{indexAppMD.tsx → AppMD.tsx} +49 -151
- package/src/modules/LandingPage/index.tsx +193 -0
- package/src/modules/LandingPage/indexNewVersion.tsx +7 -14
- package/src/modules/LandingPage/propsType.ts +43 -0
- package/src/page/result/index.tsx +11 -16
- package/src/services/findRegionsCustom.ts +0 -197
- package/src/services/image.ts +11 -14
- package/src/services/session.ts +6 -6
- package/src/services/types.ts +1 -15
- package/src/types.ts +0 -1
- package/build/static/js/2.d1562c08.chunk.js +0 -3
- package/build/static/js/2.d1562c08.chunk.js.map +0 -1
- package/build/static/js/main.5c08aba4.chunk.js +0 -2
- package/build/static/js/main.5c08aba4.chunk.js.map +0 -1
- package/src/App.test.tsx +0 -49
- package/src/Store/epics/feedback.ts +0 -59
- package/src/Store/epics/types.ts +0 -12
- package/src/components/preview/preview.tsx +0 -433
|
@@ -16,35 +16,12 @@ import {
|
|
|
16
16
|
} from "@material-ui/core";
|
|
17
17
|
import { PhotoCamera, ArrowBack, Image } from "@material-ui/icons";
|
|
18
18
|
import Icon from "@material-ui/core/Icon";
|
|
19
|
-
import React, { useCallback, useEffect, useState } from "react";
|
|
20
19
|
import { NodeGroup } from "react-move";
|
|
21
20
|
import classNames from "classnames";
|
|
22
|
-
import {
|
|
23
|
-
import
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
cadExtensions,
|
|
27
|
-
isCadFile,
|
|
28
|
-
isImageFile,
|
|
29
|
-
ImageSearchOptions,
|
|
30
|
-
} from "@nyris/nyris-api";
|
|
31
|
-
import NyrisAPI from "@nyris/nyris-api";
|
|
32
|
-
import {
|
|
33
|
-
loadCadFileLoad,
|
|
34
|
-
loadFile,
|
|
35
|
-
loadFileSelectRegion,
|
|
36
|
-
loadingActionRegions,
|
|
37
|
-
loadingActionResults,
|
|
38
|
-
searchFileImageNonRegion,
|
|
39
|
-
// selectionChanged,
|
|
40
|
-
} from "Store/Search";
|
|
41
|
-
import { showCamera, showFeedback, showResults, showStart } from "Store/Nyris";
|
|
42
|
-
import _, { debounce, isEmpty } from "lodash";
|
|
43
|
-
import { serviceImage, serviceImageNonRegion } from "services/image";
|
|
44
|
-
import { findByImage } from "services/findByImage";
|
|
45
|
-
import { feedbackRegionEpic } from "services/Feedback";
|
|
46
|
-
import { MDSettings } from "../../types";
|
|
47
|
-
import Preview from "components/preview/preview";
|
|
21
|
+
import {Capture, Preview} from "@nyris/nyris-react-components";
|
|
22
|
+
import _ from "lodash";
|
|
23
|
+
import {AppProps} from "./propsType";
|
|
24
|
+
import React from "react";
|
|
48
25
|
|
|
49
26
|
const useStyles = makeStyles((theme) => ({
|
|
50
27
|
icon: {
|
|
@@ -123,106 +100,43 @@ const makeFileHandler = (action: any) => (e: any) => {
|
|
|
123
100
|
}
|
|
124
101
|
};
|
|
125
102
|
|
|
126
|
-
const LandingPageAppMD
|
|
127
|
-
const dispatch = useAppDispatch();
|
|
103
|
+
const LandingPageAppMD = (props: AppProps) => {
|
|
128
104
|
const classes = useStyles();
|
|
129
|
-
const [rectCoords, setRectCoords] = useState<any>();
|
|
130
|
-
const searchState = useAppSelector((state) => state);
|
|
131
|
-
const { settings, search, nyris } = searchState;
|
|
132
|
-
const { showPart } = nyris;
|
|
133
105
|
const {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
106
|
+
handlers,
|
|
107
|
+
showPart,
|
|
108
|
+
acceptTypes,
|
|
109
|
+
settings,
|
|
110
|
+
search,
|
|
111
|
+
loading,
|
|
112
|
+
previewImage
|
|
113
|
+
} = props;
|
|
114
|
+
|
|
115
|
+
const mdSettings = settings.themePage.materialDesign;
|
|
116
|
+
|
|
117
|
+
const {
|
|
139
118
|
results,
|
|
140
|
-
|
|
119
|
+
regions,
|
|
120
|
+
previewSelection,
|
|
141
121
|
} = search;
|
|
142
|
-
const { themePage }: any = settings;
|
|
143
|
-
useEffect(() => {
|
|
144
|
-
if (isEmpty(rectCoords)) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
onSearchOffersForImage(rectCoords);
|
|
148
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
149
|
-
}, [rectCoords]);
|
|
150
|
-
|
|
151
|
-
const loading = fetchingRegions || fetchingResults;
|
|
152
122
|
|
|
153
|
-
const
|
|
123
|
+
const {
|
|
124
|
+
onLinkClick,
|
|
125
|
+
onFileDropped,
|
|
126
|
+
onCaptureComplete,
|
|
127
|
+
onCaptureCanceled,
|
|
128
|
+
onSelectFile,
|
|
129
|
+
onCameraClick,
|
|
130
|
+
onShowStart,
|
|
131
|
+
onSelectionChange,
|
|
132
|
+
} = handlers;
|
|
154
133
|
|
|
155
134
|
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
156
|
-
onDrop: (fs: File[]) =>
|
|
135
|
+
onDrop: (fs: File[]) => {
|
|
136
|
+
onFileDropped(fs[0]);
|
|
137
|
+
},
|
|
157
138
|
});
|
|
158
139
|
|
|
159
|
-
// const minPreviewHeight = 400;
|
|
160
|
-
// const halfOfTheScreenHeight = Math.floor(window.innerHeight * 0.45);
|
|
161
|
-
// const maxPreviewHeight = Math.max(minPreviewHeight, halfOfTheScreenHeight);
|
|
162
|
-
const acceptTypes = ["image/*"]
|
|
163
|
-
.concat(settings.cadSearch ? cadExtensions : [])
|
|
164
|
-
.join(",");
|
|
165
|
-
|
|
166
|
-
const isCheckImageFile = async (file: any) => {
|
|
167
|
-
dispatch(showResults(""));
|
|
168
|
-
dispatch(loadingActionResults(""));
|
|
169
|
-
dispatch(showFeedback(""));
|
|
170
|
-
if (isImageFile(file) || typeof file === "string") {
|
|
171
|
-
if (settings.regions) {
|
|
172
|
-
serviceImage(file, searchState).then((res) => {
|
|
173
|
-
dispatch(loadFile(res));
|
|
174
|
-
return dispatch(showFeedback(""));
|
|
175
|
-
});
|
|
176
|
-
} else {
|
|
177
|
-
serviceImageNonRegion(file, searchState, rectCoords).then((res) => {
|
|
178
|
-
dispatch(searchFileImageNonRegion(res));
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
// return serviceImage(file, settings).then((res) => {
|
|
182
|
-
// return dispatch(loadFile(res));
|
|
183
|
-
// });
|
|
184
|
-
}
|
|
185
|
-
if (isCadFile(file)) {
|
|
186
|
-
return dispatch(loadCadFileLoad(file));
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
const feedbackClickEpic = async (position: any, _url: string) => {
|
|
191
|
-
try {
|
|
192
|
-
const api = new NyrisAPI(settings);
|
|
193
|
-
const sessionId = search.sessionId || search.requestId;
|
|
194
|
-
if (sessionId && requestId) {
|
|
195
|
-
await api.sendFeedback(sessionId, requestId, {
|
|
196
|
-
event: "click",
|
|
197
|
-
data: { positions: [position] },
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
} catch (error) {
|
|
201
|
-
console.log("err feedbackClickEpic", error);
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
const handlerRectCoords = debounce((value) => {
|
|
206
|
-
setRectCoords(value);
|
|
207
|
-
}, 1200);
|
|
208
|
-
|
|
209
|
-
const debounceRectCoords = useCallback(
|
|
210
|
-
(value) => handlerRectCoords(value),
|
|
211
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
212
|
-
[]
|
|
213
|
-
);
|
|
214
|
-
const onSearchOffersForImage = (r: RectCoords) => {
|
|
215
|
-
const { canvas }: any = requestImage;
|
|
216
|
-
let options: ImageSearchOptions = {
|
|
217
|
-
cropRect: r,
|
|
218
|
-
};
|
|
219
|
-
feedbackRegionEpic(searchState, r);
|
|
220
|
-
dispatch(loadingActionRegions(""));
|
|
221
|
-
return findByImage(canvas, options, settings).then((res) => {
|
|
222
|
-
dispatch(loadFileSelectRegion(res));
|
|
223
|
-
return dispatch(showFeedback(""));
|
|
224
|
-
});
|
|
225
|
-
};
|
|
226
140
|
|
|
227
141
|
return (
|
|
228
142
|
<React.Fragment>
|
|
@@ -235,10 +149,8 @@ const LandingPageAppMD: React.FC<any> = () => {
|
|
|
235
149
|
<CssBaseline />
|
|
236
150
|
{showPart === "camera" && (
|
|
237
151
|
<Capture
|
|
238
|
-
onCaptureComplete={
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
onCaptureCanceled={() => dispatch(showStart)}
|
|
152
|
+
onCaptureComplete={onCaptureComplete}
|
|
153
|
+
onCaptureCanceled={onCaptureCanceled}
|
|
242
154
|
useAppText="Use default camera app"
|
|
243
155
|
/>
|
|
244
156
|
)}
|
|
@@ -259,9 +171,7 @@ const LandingPageAppMD: React.FC<any> = () => {
|
|
|
259
171
|
<Button
|
|
260
172
|
variant={"contained"}
|
|
261
173
|
color={"primary"}
|
|
262
|
-
onClick={
|
|
263
|
-
return dispatch(showCamera);
|
|
264
|
-
}}
|
|
174
|
+
onClick={onCameraClick}
|
|
265
175
|
>
|
|
266
176
|
Take a picture
|
|
267
177
|
</Button>
|
|
@@ -274,7 +184,7 @@ const LandingPageAppMD: React.FC<any> = () => {
|
|
|
274
184
|
accept={acceptTypes}
|
|
275
185
|
id="raised-button-file"
|
|
276
186
|
type="file"
|
|
277
|
-
onChange={makeFileHandler(
|
|
187
|
+
onChange={makeFileHandler(onSelectFile)}
|
|
278
188
|
style={{
|
|
279
189
|
width: ".1px",
|
|
280
190
|
height: ".1px",
|
|
@@ -324,9 +234,7 @@ const LandingPageAppMD: React.FC<any> = () => {
|
|
|
324
234
|
id="raised-button-file"
|
|
325
235
|
type="file"
|
|
326
236
|
{...getInputProps()}
|
|
327
|
-
onChange={makeFileHandler(
|
|
328
|
-
return isCheckImageFile(e);
|
|
329
|
-
})}
|
|
237
|
+
onChange={makeFileHandler(onSelectFile)}
|
|
330
238
|
style={{
|
|
331
239
|
width: ".1px",
|
|
332
240
|
height: ".1px",
|
|
@@ -356,22 +264,13 @@ const LandingPageAppMD: React.FC<any> = () => {
|
|
|
356
264
|
)}
|
|
357
265
|
maxWidth="md"
|
|
358
266
|
>
|
|
359
|
-
{
|
|
267
|
+
{previewImage && (
|
|
360
268
|
<Card style={{ marginBottom: "4em" }} raised={true}>
|
|
361
269
|
<Preview
|
|
362
|
-
key={
|
|
363
|
-
onSelectionChange={
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}}
|
|
367
|
-
image={requestImage?.canvas}
|
|
368
|
-
initialRegion={
|
|
369
|
-
!selectedRegion
|
|
370
|
-
? regions[0]
|
|
371
|
-
? regions[0]
|
|
372
|
-
: { x1: 0, x2: 1, y1: 0, y2: 1 }
|
|
373
|
-
: selectedRegion
|
|
374
|
-
}
|
|
270
|
+
key={previewImage?.id}
|
|
271
|
+
onSelectionChange={onSelectionChange}
|
|
272
|
+
image={previewImage?.canvas}
|
|
273
|
+
selection={previewSelection}
|
|
375
274
|
regions={regions}
|
|
376
275
|
maxWidth={400}
|
|
377
276
|
maxHeight={500}
|
|
@@ -424,13 +323,13 @@ const LandingPageAppMD: React.FC<any> = () => {
|
|
|
424
323
|
component="h5"
|
|
425
324
|
className={classes.withElipsis}
|
|
426
325
|
>
|
|
427
|
-
{result[mdSettings
|
|
326
|
+
{result[mdSettings?.resultFirstRowProperty!!]}
|
|
428
327
|
</Typography>
|
|
429
328
|
<Typography
|
|
430
329
|
variant="body2"
|
|
431
330
|
className={classes.withElipsis}
|
|
432
331
|
>
|
|
433
|
-
{result[mdSettings
|
|
332
|
+
{result[mdSettings?.resultSecondRowProperty!!]}
|
|
434
333
|
</Typography>
|
|
435
334
|
</CardContent>
|
|
436
335
|
{result.l && (
|
|
@@ -442,26 +341,25 @@ const LandingPageAppMD: React.FC<any> = () => {
|
|
|
442
341
|
color="primary"
|
|
443
342
|
onClick={
|
|
444
343
|
() => {
|
|
445
|
-
|
|
344
|
+
onLinkClick(
|
|
446
345
|
result.position,
|
|
447
346
|
result.l
|
|
448
347
|
);
|
|
449
348
|
}
|
|
450
|
-
// handlers.onLinkClick(result.position, result.l)
|
|
451
349
|
}
|
|
452
350
|
onAuxClick={() => {
|
|
453
|
-
|
|
351
|
+
onLinkClick(
|
|
454
352
|
result.position,
|
|
455
353
|
result.l
|
|
456
354
|
);
|
|
457
355
|
}}
|
|
458
356
|
>
|
|
459
|
-
{mdSettings
|
|
357
|
+
{mdSettings?.resultLinkIcon && (
|
|
460
358
|
<React.Fragment>
|
|
461
359
|
<Icon>{mdSettings.resultLinkIcon}</Icon>{" "}
|
|
462
360
|
</React.Fragment>
|
|
463
361
|
)}
|
|
464
|
-
{mdSettings
|
|
362
|
+
{mdSettings?.resultLinkText}
|
|
465
363
|
</Button>
|
|
466
364
|
</CardActions>
|
|
467
365
|
)}
|
|
@@ -486,7 +384,7 @@ const LandingPageAppMD: React.FC<any> = () => {
|
|
|
486
384
|
aria-label="back"
|
|
487
385
|
className={classes.fab}
|
|
488
386
|
color="primary"
|
|
489
|
-
onClick={
|
|
387
|
+
onClick={onShowStart}
|
|
490
388
|
>
|
|
491
389
|
<ArrowBack />
|
|
492
390
|
</Fab>
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
RectCoords,
|
|
4
|
+
cadExtensions,
|
|
5
|
+
isCadFile,
|
|
6
|
+
isImageFile,
|
|
7
|
+
ImageSearchOptions,
|
|
8
|
+
} from "@nyris/nyris-api";
|
|
9
|
+
|
|
10
|
+
import { useAppDispatch, useAppSelector } from "Store/Store";
|
|
11
|
+
import {
|
|
12
|
+
loadCadFileLoad,
|
|
13
|
+
setSearchResults,
|
|
14
|
+
loadFileSelectRegion,
|
|
15
|
+
loadingActionRegions,
|
|
16
|
+
loadingActionResults,
|
|
17
|
+
searchFileImageNonRegion,
|
|
18
|
+
} from "Store/Search";
|
|
19
|
+
import {
|
|
20
|
+
feedbackNegative,
|
|
21
|
+
feedbackSubmitPositive,
|
|
22
|
+
hideFeedback,
|
|
23
|
+
showCamera,
|
|
24
|
+
showFeedback,
|
|
25
|
+
showResults,
|
|
26
|
+
showStart,
|
|
27
|
+
} from "Store/Nyris";
|
|
28
|
+
import { serviceImage, serviceImageNonRegion } from "services/image";
|
|
29
|
+
import { findByImage } from "services/findByImage";
|
|
30
|
+
import { debounce, isEmpty } from "lodash";
|
|
31
|
+
import { feedbackClickEpic } from "services/Feedback";
|
|
32
|
+
import AppMD from "./AppMD";
|
|
33
|
+
import App from "./App";
|
|
34
|
+
import {AppHandlers, AppProps} from "./propsType";
|
|
35
|
+
import {defaultMdSettings} from "../../defaults";
|
|
36
|
+
|
|
37
|
+
const LandingPageApp = () => {
|
|
38
|
+
const dispatch = useAppDispatch();
|
|
39
|
+
const searchState = useAppSelector((state) => state);
|
|
40
|
+
const [rectCoords, setRectCoords] = useState<any>();
|
|
41
|
+
const defaultSelection = {x1: 0.1, x2: 0.9, y1: 0.1, y2: 0.9};
|
|
42
|
+
const [selection, setSelection] = useState<RectCoords>(defaultSelection);
|
|
43
|
+
|
|
44
|
+
const { settings, search, nyris } = searchState;
|
|
45
|
+
const {
|
|
46
|
+
fetchingRegions,
|
|
47
|
+
fetchingResults,
|
|
48
|
+
requestImage,
|
|
49
|
+
selectedRegion,
|
|
50
|
+
} = search;
|
|
51
|
+
const { showPart } = nyris;
|
|
52
|
+
|
|
53
|
+
const isDefaultRect = (r: RectCoords) => r.x1 === 0 && r.x2 === 1 && r.y1 === 0 && r.y2 === 1;
|
|
54
|
+
|
|
55
|
+
// update selection, if it is not the default one
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (!isDefaultRect(selectedRegion)) {
|
|
58
|
+
setSelection(selectedRegion);
|
|
59
|
+
}
|
|
60
|
+
}, [selectedRegion]);
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (isEmpty(rectCoords)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
onSearchOffersForImage(rectCoords);
|
|
68
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
|
+
}, [rectCoords]);
|
|
70
|
+
|
|
71
|
+
const acceptTypes = ["image/*"]
|
|
72
|
+
.concat(settings.cadSearch ? cadExtensions : [])
|
|
73
|
+
.join(",");
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
function scrollTop() {
|
|
77
|
+
// TODO might require polyfill for ios and edge
|
|
78
|
+
window.scrollTo({ top: 0, left: 0, behavior: "smooth" });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const onLinkClick = (_position: number, url: string) => {
|
|
82
|
+
feedbackClickEpic(searchState, _position).catch(console.warn);
|
|
83
|
+
if (url) {
|
|
84
|
+
window.open(url);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
// TODO: search image file home page
|
|
88
|
+
const isCheckImageFile = (file: any) => {
|
|
89
|
+
dispatch(loadingActionResults());
|
|
90
|
+
dispatch(showResults());
|
|
91
|
+
dispatch(showFeedback());
|
|
92
|
+
if (isImageFile(file) || typeof file === "string") {
|
|
93
|
+
return serviceImage(file, searchState.settings).then((res) => {
|
|
94
|
+
dispatch(setSearchResults(res));
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (isCadFile(file)) {
|
|
98
|
+
return dispatch(loadCadFileLoad(file));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
//
|
|
102
|
+
|
|
103
|
+
const searchByUrl = (url: string, position?: number) => {
|
|
104
|
+
dispatch(loadingActionResults());
|
|
105
|
+
dispatch(showResults());
|
|
106
|
+
if (position) {
|
|
107
|
+
feedbackClickEpic(searchState, position);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (settings.regions) {
|
|
111
|
+
serviceImage(url, searchState.settings).then((res) => {
|
|
112
|
+
dispatch(setSearchResults(res));
|
|
113
|
+
dispatch(showFeedback());
|
|
114
|
+
});
|
|
115
|
+
} else {
|
|
116
|
+
serviceImageNonRegion(url, searchState, rectCoords).then((res) => {
|
|
117
|
+
dispatch(searchFileImageNonRegion(res));
|
|
118
|
+
dispatch(showFeedback());
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const handlerRectCoords = debounce((value) => {
|
|
124
|
+
return setRectCoords(value);
|
|
125
|
+
}, 1200);
|
|
126
|
+
|
|
127
|
+
const debouncedSetRectCoords = useCallback(
|
|
128
|
+
(value) => handlerRectCoords(value),
|
|
129
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
130
|
+
[]
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const onSearchOffersForImage = (r: RectCoords) => {
|
|
134
|
+
const { canvas }: any = requestImage;
|
|
135
|
+
let options: ImageSearchOptions = {
|
|
136
|
+
cropRect: r,
|
|
137
|
+
};
|
|
138
|
+
dispatch(loadingActionRegions());
|
|
139
|
+
return findByImage(canvas, options, settings).then((res) => {
|
|
140
|
+
dispatch(loadFileSelectRegion(res));
|
|
141
|
+
return dispatch(showFeedback());
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const handlers : AppHandlers = {
|
|
146
|
+
onExampleImageClick: url => searchByUrl(url),
|
|
147
|
+
onCameraClick: () => dispatch(showCamera),
|
|
148
|
+
onCaptureCanceled: () => dispatch(showStart),
|
|
149
|
+
onCaptureComplete: (i) => isCheckImageFile(i),
|
|
150
|
+
onCloseFeedback: () => dispatch(hideFeedback),
|
|
151
|
+
onFileDropped: (f) => isCheckImageFile(f),
|
|
152
|
+
onImageClick: (position, url) => searchByUrl(url, position),
|
|
153
|
+
onLinkClick: onLinkClick,
|
|
154
|
+
onPositiveFeedback: () => {
|
|
155
|
+
dispatch(feedbackSubmitPositive());
|
|
156
|
+
// TODO submit positive feedback to the api
|
|
157
|
+
},
|
|
158
|
+
onNegativeFeedback: () => {
|
|
159
|
+
dispatch(feedbackNegative());
|
|
160
|
+
// TODO submit negative feedback to the api
|
|
161
|
+
},
|
|
162
|
+
onSelectFile: (f) => isCheckImageFile(f),
|
|
163
|
+
onSelectionChange: r => {
|
|
164
|
+
setSelection(r);
|
|
165
|
+
debouncedSetRectCoords(r);
|
|
166
|
+
},
|
|
167
|
+
onShowStart: () => {
|
|
168
|
+
dispatch(showStart());
|
|
169
|
+
scrollTop();
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
let props : AppProps = {
|
|
174
|
+
search: {
|
|
175
|
+
...search,
|
|
176
|
+
previewSelection: selection
|
|
177
|
+
},
|
|
178
|
+
settings,
|
|
179
|
+
previewImage: search.requestImage,
|
|
180
|
+
acceptTypes,
|
|
181
|
+
showPart,
|
|
182
|
+
handlers,
|
|
183
|
+
loading: fetchingRegions || fetchingResults,
|
|
184
|
+
mdSettings: settings.themePage.materialDesign || defaultMdSettings,
|
|
185
|
+
feedbackState: nyris.feedbackState,
|
|
186
|
+
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
return settings.themePage.materialDesign?.active? <AppMD {...props}/> : <App {...props}/>;
|
|
190
|
+
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export default LandingPageApp;
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from "react-instantsearch-dom";
|
|
15
15
|
import algoliasearch from "algoliasearch/lite";
|
|
16
16
|
import CustomSearchBox from "components/input/inputSearch";
|
|
17
|
-
import
|
|
17
|
+
import {createSessionByApi} from "../../services/session";
|
|
18
18
|
|
|
19
19
|
interface Props {}
|
|
20
20
|
|
|
@@ -25,25 +25,17 @@ function AppNewVersion(props: Props) {
|
|
|
25
25
|
const { settings, search }: any = searchState;
|
|
26
26
|
const [searchStateInput, setSearchStateInput] = useState<any>({});
|
|
27
27
|
const [isLoading, setLoading] = useState<boolean>(false);
|
|
28
|
-
const nyrisApi = new NyrisAPICT(settings);
|
|
29
28
|
const { apiKeyAlgolia, appIdAlgolia, indexNameAlgolia } = settings;
|
|
30
29
|
const searchClient = algoliasearch(appIdAlgolia, apiKeyAlgolia);
|
|
31
30
|
searchClient.initIndex(indexNameAlgolia);
|
|
32
31
|
|
|
33
32
|
useEffect(() => {
|
|
34
33
|
const createSession = async () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const payload: any = {
|
|
38
|
-
sessionId: res.data.session,
|
|
39
|
-
requestId: res.data.id,
|
|
40
|
-
};
|
|
41
|
-
dispatch(setUpdateSession(payload));
|
|
42
|
-
});
|
|
43
|
-
} catch (error) {}
|
|
34
|
+
let payload = await createSessionByApi(searchState.settings);
|
|
35
|
+
dispatch(setUpdateSession(payload));
|
|
44
36
|
};
|
|
45
37
|
|
|
46
|
-
createSession();
|
|
38
|
+
createSession().catch(console.log);
|
|
47
39
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
48
40
|
}, []);
|
|
49
41
|
|
|
@@ -64,9 +56,10 @@ function AppNewVersion(props: Props) {
|
|
|
64
56
|
const nonEmptyFilter: any[] = !search?.requestImage
|
|
65
57
|
? []
|
|
66
58
|
: ["sku:DOES_NOT_EXIST<score=1>"];
|
|
59
|
+
// Build filter using reverse position for stable item order
|
|
67
60
|
const filterSkus: any = search?.results
|
|
68
|
-
? search?.results.map(
|
|
69
|
-
(f: any) => `sku:'${f.sku}'<score=${
|
|
61
|
+
? search?.results.slice().reverse().map(
|
|
62
|
+
(f: any, i: number) => `sku:'${f.sku}'<score=${i}>`
|
|
70
63
|
)
|
|
71
64
|
: "";
|
|
72
65
|
const filtersString = [...nonEmptyFilter, ...filterSkus].join(" OR ");
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {CategoryPrediction, Code, RectCoords, Region} from "@nyris/nyris-api";
|
|
2
|
+
import {AppSettings, CanvasWithId, MDSettings} from "../../types";
|
|
3
|
+
import {NyrisAppPart, NyrisFeedbackState} from "../../Store/Nyris";
|
|
4
|
+
|
|
5
|
+
export interface AppHandlers {
|
|
6
|
+
onExampleImageClick: (url: string) => void;
|
|
7
|
+
onImageClick: (position: number, url: string) => void;
|
|
8
|
+
onLinkClick: (position: number, url: string) => void;
|
|
9
|
+
onFileDropped: (file: File) => void;
|
|
10
|
+
onCaptureComplete: (image: HTMLCanvasElement) => void;
|
|
11
|
+
onCaptureCanceled: () => void;
|
|
12
|
+
onSelectFile: (f: File) => void;
|
|
13
|
+
onCameraClick: () => void;
|
|
14
|
+
onShowStart: () => void;
|
|
15
|
+
onSelectionChange: (r: RectCoords) => void;
|
|
16
|
+
onPositiveFeedback: () => void;
|
|
17
|
+
onNegativeFeedback: () => void;
|
|
18
|
+
onCloseFeedback: () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export interface AppProps {
|
|
23
|
+
search: {
|
|
24
|
+
results: any[];
|
|
25
|
+
requestId?: string;
|
|
26
|
+
duration?: number;
|
|
27
|
+
categoryPredictions: CategoryPrediction[];
|
|
28
|
+
codes: Code[];
|
|
29
|
+
filterOptions: string[];
|
|
30
|
+
errorMessage?: string;
|
|
31
|
+
regions: Region[];
|
|
32
|
+
previewSelection: RectCoords;
|
|
33
|
+
toastErrorMessage?: string;
|
|
34
|
+
};
|
|
35
|
+
acceptTypes: string,
|
|
36
|
+
previewImage?: CanvasWithId;
|
|
37
|
+
settings: AppSettings;
|
|
38
|
+
loading: boolean;
|
|
39
|
+
showPart: NyrisAppPart;
|
|
40
|
+
feedbackState: NyrisFeedbackState;
|
|
41
|
+
handlers: AppHandlers;
|
|
42
|
+
mdSettings: MDSettings;
|
|
43
|
+
}
|
|
@@ -31,7 +31,7 @@ import DetailItem from "components/DetailItem";
|
|
|
31
31
|
import FileCopyOutlinedIcon from "@material-ui/icons/FileCopyOutlined";
|
|
32
32
|
import { RectCoords } from "@nyris/nyris-api";
|
|
33
33
|
import {
|
|
34
|
-
|
|
34
|
+
setSearchResults,
|
|
35
35
|
loadingActionResults,
|
|
36
36
|
searchFileImageNonRegion,
|
|
37
37
|
selectionChanged,
|
|
@@ -52,9 +52,9 @@ import {
|
|
|
52
52
|
serviceImage,
|
|
53
53
|
serviceImageNonRegion,
|
|
54
54
|
} from "services/image";
|
|
55
|
-
import Preview from "components/preview/preview";
|
|
56
55
|
import NyrisAPI from "@nyris/nyris-api";
|
|
57
56
|
import LoadingScreenCustom from "components/LoadingScreen";
|
|
57
|
+
import { Preview } from "@nyris/nyris-react-components";
|
|
58
58
|
|
|
59
59
|
interface Props {}
|
|
60
60
|
|
|
@@ -144,7 +144,7 @@ function ResultComponent(props: Props) {
|
|
|
144
144
|
};
|
|
145
145
|
dispatch(updateResultChangePosition(payload));
|
|
146
146
|
setLoading(false);
|
|
147
|
-
return dispatch(showFeedback(
|
|
147
|
+
return dispatch(showFeedback());
|
|
148
148
|
});
|
|
149
149
|
} else {
|
|
150
150
|
serviceImageNonRegion(canvas, StateGlobal, null).then((res: any) => {
|
|
@@ -153,7 +153,7 @@ function ResultComponent(props: Props) {
|
|
|
153
153
|
requestImage: requestImage,
|
|
154
154
|
};
|
|
155
155
|
dispatch(updateResultChangePosition(payload));
|
|
156
|
-
return dispatch(showFeedback(
|
|
156
|
+
return dispatch(showFeedback());
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
};
|
|
@@ -202,17 +202,18 @@ function ResultComponent(props: Props) {
|
|
|
202
202
|
|
|
203
203
|
// Search image with url or file
|
|
204
204
|
const getUrlToCanvasFile = (url: string, position?: number) => {
|
|
205
|
-
dispatch(showResults(
|
|
206
|
-
dispatch(loadingActionResults(
|
|
205
|
+
dispatch(showResults());
|
|
206
|
+
dispatch(loadingActionResults());
|
|
207
207
|
if (position) {
|
|
208
208
|
feedbackClickEpic(StateGlobal, position);
|
|
209
209
|
return;
|
|
210
210
|
}
|
|
211
211
|
if (settings.regions) {
|
|
212
|
-
serviceImage(url,
|
|
213
|
-
|
|
212
|
+
serviceImage(url, settings).then((res ) => {
|
|
213
|
+
console.log("res", res)
|
|
214
|
+
dispatch(setSearchResults(res));
|
|
214
215
|
setLoading(false);
|
|
215
|
-
return dispatch(showFeedback(
|
|
216
|
+
return dispatch(showFeedback());
|
|
216
217
|
});
|
|
217
218
|
|
|
218
219
|
return;
|
|
@@ -313,13 +314,7 @@ function ResultComponent(props: Props) {
|
|
|
313
314
|
return;
|
|
314
315
|
}}
|
|
315
316
|
image={requestImage?.canvas}
|
|
316
|
-
|
|
317
|
-
!selectedRegion
|
|
318
|
-
? regions[0]
|
|
319
|
-
? regions[0]
|
|
320
|
-
: { x1: 0, x2: 1, y1: 0, y2: 1 }
|
|
321
|
-
: selectedRegion
|
|
322
|
-
}
|
|
317
|
+
selection={selectedRegion}
|
|
323
318
|
regions={regions}
|
|
324
319
|
maxWidth={400}
|
|
325
320
|
maxHeight={500}
|