@nyris/nyris-webapp 0.3.4 → 0.3.5
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.9800bdc87f5a2c5d6d8a5d1a5287598f.js → precache-manifest.bbb31f2ce7710d7eb3175b1b48241d24.js} +8 -8
- package/build/service-worker.js +1 -1
- package/build/static/js/2.4a55bc61.chunk.js +3 -0
- package/build/static/js/{2.29ddd567.chunk.js.LICENSE.txt → 2.4a55bc61.chunk.js.LICENSE.txt} +0 -0
- package/build/static/js/2.4a55bc61.chunk.js.map +1 -0
- package/build/static/js/main.2660f94a.chunk.js +2 -0
- package/build/static/js/main.2660f94a.chunk.js.map +1 -0
- package/package.json +3 -3
- package/src/App.tsx +1 -2
- package/src/Store/Search.ts +39 -66
- package/src/components/DragDropFile.tsx +22 -18
- package/src/modules/LandingPage/index.tsx +59 -83
- package/src/modules/LandingPage/indexNewVersion.tsx +8 -8
- package/src/page/result/index.tsx +47 -97
- package/src/services/Feedback.ts +46 -47
- package/src/services/image.ts +28 -95
- package/src/services/session.ts +9 -12
- package/src/services/types.ts +1 -33
- package/src/types.ts +12 -7
- package/build/static/js/2.29ddd567.chunk.js +0 -3
- package/build/static/js/2.29ddd567.chunk.js.map +0 -1
- package/build/static/js/main.c35ded37.chunk.js +0 -2
- package/build/static/js/main.c35ded37.chunk.js.map +0 -1
- package/src/Store/common.d.ts +0 -10
- package/src/services/findByImage.ts +0 -24
- package/src/services/findRegionsCustom.ts +0 -15
- package/src/services/nyris.ts +0 -123
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nyris/nyris-webapp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"homepage": "./",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@babel/runtime": "^7.17.2",
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"@material-ui/data-grid": "^4.0.0-alpha.37",
|
|
9
9
|
"@material-ui/icons": "^4.4.1",
|
|
10
10
|
"@material-ui/lab": "^4.0.0-alpha.60",
|
|
11
|
-
"@nyris/nyris-api": "^0.3.
|
|
12
|
-
"@nyris/nyris-react-components": "^0.3.
|
|
11
|
+
"@nyris/nyris-api": "^0.3.5",
|
|
12
|
+
"@nyris/nyris-react-components": "^0.3.5",
|
|
13
13
|
"@reduxjs/toolkit": "^1.6.1",
|
|
14
14
|
"@types/blueimp-load-image": "^2.23.4",
|
|
15
15
|
"@types/classnames": "^2.2.9",
|
package/src/App.tsx
CHANGED
|
@@ -6,10 +6,9 @@ import "index.css";
|
|
|
6
6
|
import { useAppSelector } from "Store/Store";
|
|
7
7
|
import LandingPageApp from "modules/LandingPage/index";
|
|
8
8
|
import AppNewVersion from "modules/LandingPage/indexNewVersion";
|
|
9
|
-
import {AppState} from "./types";
|
|
10
9
|
|
|
11
10
|
function App(): JSX.Element {
|
|
12
|
-
const { settings } = useAppSelector
|
|
11
|
+
const { settings } = useAppSelector((state) => state);
|
|
13
12
|
const { themePage } = settings;
|
|
14
13
|
let SelectedApp = themePage.searchSuite?.active ? AppNewVersion : LandingPageApp;
|
|
15
14
|
|
package/src/Store/Search.ts
CHANGED
|
@@ -2,37 +2,6 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
|
|
2
2
|
import { CanvasWithId } from "types";
|
|
3
3
|
import { Code, RectCoords, Region } from "@nyris/nyris-api";
|
|
4
4
|
|
|
5
|
-
export type ImageSourceType =
|
|
6
|
-
| { url: string }
|
|
7
|
-
| { file: File }
|
|
8
|
-
| { image: HTMLCanvasElement };
|
|
9
|
-
|
|
10
|
-
export type SearchAction =
|
|
11
|
-
| { type: "FEEDBACK_SUBMIT_POSITIVE" }
|
|
12
|
-
| { type: "FEEDBACK_SUBMIT_NEGATIVE" }
|
|
13
|
-
| { type: "IMAGE_LOADED"; image: CanvasWithId }
|
|
14
|
-
| { type: "REGION_REQUEST_START"; image: HTMLCanvasElement }
|
|
15
|
-
| { type: "REGION_REQUEST_SUCCEED"; regions: Region[] }
|
|
16
|
-
| { type: "REGION_REQUEST_FAIL"; reason: string; exception: any }
|
|
17
|
-
| {
|
|
18
|
-
type: "SEARCH_REQUEST_START";
|
|
19
|
-
image: HTMLCanvasElement;
|
|
20
|
-
normalizedRect?: RectCoords;
|
|
21
|
-
}
|
|
22
|
-
| { type: "SEARCH_REQUEST_START"; file: File }
|
|
23
|
-
| {
|
|
24
|
-
type: "SEARCH_REQUEST_SUCCEED";
|
|
25
|
-
results: any[];
|
|
26
|
-
requestId: string;
|
|
27
|
-
duration: number;
|
|
28
|
-
categoryPredictions: CategoryPrediction[];
|
|
29
|
-
codes: Code[];
|
|
30
|
-
}
|
|
31
|
-
| { type: "SEARCH_REQUEST_FAIL"; reason: string; exception?: any }
|
|
32
|
-
| { type: "REGION_CHANGED"; normalizedRect: RectCoords }
|
|
33
|
-
| ({ type: "LOAD_IMAGE" } & ImageSourceType)
|
|
34
|
-
| { type: "LOAD_FILE"; file: File }
|
|
35
|
-
| { type: "CAD_LOADED"; file: File };
|
|
36
5
|
|
|
37
6
|
interface CategoryPrediction {
|
|
38
7
|
name: string;
|
|
@@ -45,12 +14,11 @@ export interface SearchState {
|
|
|
45
14
|
requestId?: string;
|
|
46
15
|
sessionId?: string;
|
|
47
16
|
regions: Region[];
|
|
48
|
-
selectedRegion
|
|
17
|
+
selectedRegion?: RectCoords;
|
|
49
18
|
fetchingRegions: boolean;
|
|
50
19
|
fetchingResults: boolean;
|
|
51
20
|
filterOptions: string[];
|
|
52
21
|
requestImage?: CanvasWithId;
|
|
53
|
-
requestCadFile?: File;
|
|
54
22
|
categoryPredictions: CategoryPrediction[];
|
|
55
23
|
codes: Code[];
|
|
56
24
|
errorMessage: string;
|
|
@@ -65,7 +33,7 @@ export interface SearchState {
|
|
|
65
33
|
const initialState: SearchState = {
|
|
66
34
|
results: [],
|
|
67
35
|
regions: [],
|
|
68
|
-
selectedRegion:
|
|
36
|
+
selectedRegion: undefined,
|
|
69
37
|
requestImage: undefined,
|
|
70
38
|
fetchingResults: false,
|
|
71
39
|
fetchingRegions: false,
|
|
@@ -88,39 +56,43 @@ const initialState: SearchState = {
|
|
|
88
56
|
setSearchResults: (state, data) => {
|
|
89
57
|
const { payload } = data;
|
|
90
58
|
const {
|
|
91
|
-
requestImage,
|
|
92
59
|
results,
|
|
93
60
|
requestId,
|
|
94
61
|
categoryPredictions,
|
|
95
62
|
codes,
|
|
96
63
|
duration,
|
|
97
|
-
regions,
|
|
98
|
-
selectedRegion,
|
|
99
64
|
filters,
|
|
100
65
|
} = payload;
|
|
101
66
|
return {
|
|
102
67
|
...state,
|
|
103
68
|
filters,
|
|
104
|
-
requestImage,
|
|
105
69
|
results,
|
|
106
70
|
requestId,
|
|
107
71
|
categoryPredictions,
|
|
108
72
|
codes,
|
|
109
73
|
duration,
|
|
110
74
|
sessionId: state.sessionId || requestId,
|
|
111
|
-
regions,
|
|
112
|
-
selectedRegion,
|
|
113
75
|
fetchingResults: false,
|
|
114
76
|
};
|
|
115
77
|
},
|
|
116
78
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
79
|
+
setRegions: (state, data: PayloadAction<Region[]>) => ({
|
|
80
|
+
...state,
|
|
81
|
+
regions: data.payload
|
|
82
|
+
}),
|
|
83
|
+
|
|
84
|
+
setSelectedRegion: (state, data: PayloadAction<RectCoords|undefined>) => ({
|
|
85
|
+
...state,
|
|
86
|
+
selectedRegion: data.payload
|
|
87
|
+
}),
|
|
88
|
+
|
|
89
|
+
setRequestImage: (state, data: PayloadAction<HTMLCanvasElement>) => ({
|
|
120
90
|
...state,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
91
|
+
requestImage: {
|
|
92
|
+
canvas: data.payload,
|
|
93
|
+
id: Math.random().toString()
|
|
94
|
+
}
|
|
95
|
+
}),
|
|
124
96
|
|
|
125
97
|
selectionChanged: (state, data: PayloadAction<RectCoords>) => {
|
|
126
98
|
const { payload } = data;
|
|
@@ -145,12 +117,6 @@ const initialState: SearchState = {
|
|
|
145
117
|
fetchingRegions: false,
|
|
146
118
|
};
|
|
147
119
|
},
|
|
148
|
-
submitPositiveFeedback: () => {
|
|
149
|
-
return;
|
|
150
|
-
},
|
|
151
|
-
submitNegativeFeedback: () => {
|
|
152
|
-
return;
|
|
153
|
-
},
|
|
154
120
|
loadingActionResults: (state) => {
|
|
155
121
|
return {
|
|
156
122
|
...state,
|
|
@@ -171,7 +137,6 @@ const initialState: SearchState = {
|
|
|
171
137
|
duration,
|
|
172
138
|
categoryPredictions,
|
|
173
139
|
codes,
|
|
174
|
-
requestImage,
|
|
175
140
|
} = payload;
|
|
176
141
|
return {
|
|
177
142
|
...state,
|
|
@@ -180,32 +145,31 @@ const initialState: SearchState = {
|
|
|
180
145
|
duration,
|
|
181
146
|
categoryPredictions,
|
|
182
147
|
codes,
|
|
183
|
-
requestImage,
|
|
184
148
|
fetchingResults: false,
|
|
185
149
|
};
|
|
186
150
|
},
|
|
187
|
-
changeValueTextSearch: (state
|
|
151
|
+
changeValueTextSearch: (state, data: PayloadAction<any>) => {
|
|
188
152
|
const { payload } = data;
|
|
189
153
|
return {
|
|
190
154
|
...state,
|
|
191
155
|
valueTextSearch: payload,
|
|
192
156
|
};
|
|
193
157
|
},
|
|
194
|
-
resultSearchText: (state
|
|
158
|
+
resultSearchText: (state, data: PayloadAction<any>) => {
|
|
195
159
|
const { payload } = data;
|
|
196
160
|
return {
|
|
197
161
|
...state,
|
|
198
162
|
resultSearchText: payload,
|
|
199
163
|
};
|
|
200
164
|
},
|
|
201
|
-
updateResults: (state
|
|
165
|
+
updateResults: (state, data: PayloadAction<any>) => {
|
|
202
166
|
const { payload } = data;
|
|
203
167
|
return {
|
|
204
168
|
...state,
|
|
205
169
|
results: payload,
|
|
206
170
|
};
|
|
207
171
|
},
|
|
208
|
-
reset: (state
|
|
172
|
+
reset: (state, data: PayloadAction<any>) => {
|
|
209
173
|
return {
|
|
210
174
|
results: [],
|
|
211
175
|
regions: [],
|
|
@@ -223,22 +187,21 @@ const initialState: SearchState = {
|
|
|
223
187
|
loadingSearchAlgolia: false,
|
|
224
188
|
};
|
|
225
189
|
},
|
|
226
|
-
configureFilter: (state
|
|
190
|
+
configureFilter: (state, data: PayloadAction<any>) => {
|
|
227
191
|
const { payload } = data;
|
|
228
192
|
return {
|
|
229
193
|
...state,
|
|
230
194
|
configureFilter: payload,
|
|
231
195
|
};
|
|
232
196
|
},
|
|
233
|
-
setUpdateSession: (state
|
|
197
|
+
setUpdateSession: (state, data: PayloadAction<string>) => {
|
|
234
198
|
const { payload } = data;
|
|
235
199
|
return {
|
|
236
200
|
...state,
|
|
237
|
-
|
|
238
|
-
sessionId: payload.sessionId,
|
|
201
|
+
sessionId: payload,
|
|
239
202
|
};
|
|
240
203
|
},
|
|
241
|
-
updateResultChangePosition: (state
|
|
204
|
+
updateResultChangePosition: (state, data: PayloadAction<any>) => {
|
|
242
205
|
const { payload } = data;
|
|
243
206
|
const { results } = payload;
|
|
244
207
|
return {
|
|
@@ -246,16 +209,25 @@ const initialState: SearchState = {
|
|
|
246
209
|
results,
|
|
247
210
|
};
|
|
248
211
|
},
|
|
212
|
+
|
|
213
|
+
setError: (state, data: PayloadAction<string>) => {
|
|
214
|
+
return {
|
|
215
|
+
...state,
|
|
216
|
+
fetchingRegions: false,
|
|
217
|
+
fetchingResults: false,
|
|
218
|
+
errorMessage: data.payload
|
|
219
|
+
}
|
|
220
|
+
}
|
|
249
221
|
},
|
|
250
222
|
});
|
|
251
223
|
|
|
252
224
|
export const {
|
|
253
225
|
setSearchResults,
|
|
254
226
|
selectionChanged,
|
|
255
|
-
|
|
256
|
-
submitNegativeFeedback,
|
|
257
|
-
loadCadFileLoad,
|
|
227
|
+
setRequestImage,
|
|
258
228
|
loadFileSelectRegion,
|
|
229
|
+
setRegions,
|
|
230
|
+
setSelectedRegion,
|
|
259
231
|
loadingActionResults,
|
|
260
232
|
loadingActionRegions,
|
|
261
233
|
searchFileImageNonRegion,
|
|
@@ -266,5 +238,6 @@ export const {
|
|
|
266
238
|
configureFilter,
|
|
267
239
|
setUpdateSession,
|
|
268
240
|
updateResultChangePosition,
|
|
241
|
+
setError,
|
|
269
242
|
} = searchSlice.actions;
|
|
270
243
|
export default searchSlice.reducer;
|
|
@@ -4,17 +4,18 @@ import { useDropzone } from "react-dropzone";
|
|
|
4
4
|
import IconSearch from "common/assets/icons/icon_search_image.svg";
|
|
5
5
|
import { makeFileHandler } from "@nyris/nyris-react-components";
|
|
6
6
|
import { useAppDispatch, useAppSelector } from "Store/Store";
|
|
7
|
-
import {
|
|
7
|
+
import {createImage, findByImage, findRegions} from "services/image";
|
|
8
8
|
import {
|
|
9
9
|
setSearchResults,
|
|
10
10
|
loadingActionResults,
|
|
11
|
-
|
|
11
|
+
setRequestImage, setRegions, setSelectedRegion,
|
|
12
12
|
} from "Store/Search";
|
|
13
13
|
import { showFeedback, showResults } from "Store/Nyris";
|
|
14
14
|
import { useHistory } from "react-router-dom";
|
|
15
15
|
import ExampleImages from "./ExampleImages";
|
|
16
16
|
import { feedbackClickEpic } from "services/Feedback";
|
|
17
17
|
import { useState } from "react";
|
|
18
|
+
import {RectCoords} from "@nyris/nyris-api";
|
|
18
19
|
|
|
19
20
|
interface Props {
|
|
20
21
|
acceptTypes: any;
|
|
@@ -28,11 +29,10 @@ function DragDropFile(props: Props) {
|
|
|
28
29
|
const { acceptTypes, onChangeLoading, isLoading } = props;
|
|
29
30
|
const searchState = useAppSelector((state) => state);
|
|
30
31
|
const { settings } = searchState;
|
|
31
|
-
const [rectCoords] = useState<any>(undefined);
|
|
32
32
|
const [isLoadingLoadFile, setLoadingLoadFile] = useState<any>(false);
|
|
33
33
|
|
|
34
34
|
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
35
|
-
onDrop: (fs: File[]) => {
|
|
35
|
+
onDrop: async (fs: File[]) => {
|
|
36
36
|
onChangeLoading(true);
|
|
37
37
|
console.log("321");
|
|
38
38
|
let payload: any;
|
|
@@ -40,7 +40,10 @@ function DragDropFile(props: Props) {
|
|
|
40
40
|
setLoadingLoadFile(true);
|
|
41
41
|
console.log("fs", fs);
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
let image = await createImage(fs[0]);
|
|
44
|
+
dispatch(setRequestImage(image));
|
|
45
|
+
// TODO support regions
|
|
46
|
+
return findByImage(image, searchState.settings).then((res: any) => {
|
|
44
47
|
console.log("res?.results", res);
|
|
45
48
|
|
|
46
49
|
res?.results.map((item: any) => {
|
|
@@ -65,7 +68,7 @@ function DragDropFile(props: Props) {
|
|
|
65
68
|
},
|
|
66
69
|
});
|
|
67
70
|
|
|
68
|
-
const getUrlToCanvasFile = (url: string, position?: number) => {
|
|
71
|
+
const getUrlToCanvasFile = async (url: string, position?: number) => {
|
|
69
72
|
onChangeLoading(true);
|
|
70
73
|
dispatch(showResults());
|
|
71
74
|
dispatch(loadingActionResults());
|
|
@@ -73,20 +76,21 @@ function DragDropFile(props: Props) {
|
|
|
73
76
|
feedbackClickEpic(searchState, position);
|
|
74
77
|
}
|
|
75
78
|
|
|
79
|
+
let image = await createImage(url);
|
|
80
|
+
dispatch(setRequestImage(image));
|
|
81
|
+
let searchRegion: RectCoords| undefined = undefined;
|
|
76
82
|
if (settings.regions) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return dispatch(showFeedback());
|
|
82
|
-
});
|
|
83
|
-
} else {
|
|
84
|
-
serviceImageNonRegion(url, searchState, rectCoords).then((res) => {
|
|
85
|
-
onChangeLoading(false);
|
|
86
|
-
history.push("/result");
|
|
87
|
-
dispatch(searchFileImageNonRegion(res));
|
|
88
|
-
});
|
|
83
|
+
let res = await findRegions(image, settings);
|
|
84
|
+
dispatch(setRegions(res.regions));
|
|
85
|
+
searchRegion = res.selectedRegion;
|
|
86
|
+
dispatch(setSelectedRegion(searchRegion));
|
|
89
87
|
}
|
|
88
|
+
return findByImage(image, searchState.settings, searchRegion).then((res) => {
|
|
89
|
+
dispatch(setSearchResults(res));
|
|
90
|
+
onChangeLoading(false);
|
|
91
|
+
history.push("/result");
|
|
92
|
+
return dispatch(showFeedback());
|
|
93
|
+
});
|
|
90
94
|
};
|
|
91
95
|
|
|
92
96
|
return (
|
|
@@ -3,42 +3,35 @@ import {
|
|
|
3
3
|
RectCoords,
|
|
4
4
|
cadExtensions,
|
|
5
5
|
isCadFile,
|
|
6
|
-
isImageFile,
|
|
7
|
-
ImageSearchOptions,
|
|
8
6
|
} from "@nyris/nyris-api";
|
|
9
7
|
|
|
10
8
|
import { useAppDispatch, useAppSelector } from "Store/Store";
|
|
11
9
|
import {
|
|
12
|
-
loadCadFileLoad,
|
|
13
10
|
setSearchResults,
|
|
14
|
-
loadFileSelectRegion,
|
|
15
|
-
loadingActionRegions,
|
|
16
11
|
loadingActionResults,
|
|
17
|
-
searchFileImageNonRegion,
|
|
12
|
+
searchFileImageNonRegion, selectionChanged, setRequestImage, setRegions, setSelectedRegion, setError,
|
|
18
13
|
} from "Store/Search";
|
|
19
14
|
import {
|
|
20
15
|
feedbackNegative,
|
|
21
16
|
feedbackSubmitPositive,
|
|
22
17
|
hideFeedback,
|
|
23
18
|
showCamera,
|
|
24
|
-
showFeedback,
|
|
25
|
-
showResults,
|
|
19
|
+
showFeedback, showResults,
|
|
26
20
|
showStart,
|
|
27
21
|
} from "Store/Nyris";
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import { feedbackClickEpic } from "services/Feedback";
|
|
22
|
+
import {createImage, findByCadFile, findByImage, findRegions} from "services/image";
|
|
23
|
+
import { debounce } from "lodash";
|
|
24
|
+
import {feedbackClickEpic, feedbackRegionEpic, feedbackSuccessEpic} from "services/Feedback";
|
|
32
25
|
import AppMD from "./AppMD";
|
|
33
26
|
import App from "./App";
|
|
34
27
|
import {AppHandlers, AppProps} from "./propsType";
|
|
35
28
|
import {defaultMdSettings} from "../../defaults";
|
|
36
29
|
|
|
30
|
+
const defaultSelection = {x1: 0.1, x2: 0.9, y1: 0.1, y2: 0.9};
|
|
31
|
+
|
|
37
32
|
const LandingPageApp = () => {
|
|
38
33
|
const dispatch = useAppDispatch();
|
|
39
34
|
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
35
|
const [selection, setSelection] = useState<RectCoords>(defaultSelection);
|
|
43
36
|
|
|
44
37
|
const { settings, search, nyris } = searchState;
|
|
@@ -50,24 +43,15 @@ const LandingPageApp = () => {
|
|
|
50
43
|
} = search;
|
|
51
44
|
const { showPart } = nyris;
|
|
52
45
|
|
|
53
|
-
const isDefaultRect = (r: RectCoords) => r.x1 === 0 && r.x2 === 1 && r.y1 === 0 && r.y2 === 1;
|
|
54
|
-
|
|
55
46
|
// update selection, if it is not the default one
|
|
56
47
|
useEffect(() => {
|
|
57
|
-
if (
|
|
48
|
+
if (selectedRegion) {
|
|
58
49
|
setSelection(selectedRegion);
|
|
50
|
+
} else {
|
|
51
|
+
setSelection(defaultSelection);
|
|
59
52
|
}
|
|
60
53
|
}, [selectedRegion]);
|
|
61
54
|
|
|
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
55
|
const acceptTypes = ["image/*"]
|
|
72
56
|
.concat(settings.cadSearch ? cadExtensions : [])
|
|
73
57
|
.join(",");
|
|
@@ -84,82 +68,74 @@ const LandingPageApp = () => {
|
|
|
84
68
|
window.open(url);
|
|
85
69
|
}
|
|
86
70
|
};
|
|
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
71
|
|
|
110
|
-
|
|
111
|
-
|
|
72
|
+
const startSearch = async (file: File | HTMLCanvasElement | string) => {
|
|
73
|
+
try {
|
|
74
|
+
dispatch(loadingActionResults());
|
|
75
|
+
dispatch(showResults());
|
|
76
|
+
if (file instanceof File && isCadFile(file)) {
|
|
77
|
+
let res = await findByCadFile(file, settings);
|
|
112
78
|
dispatch(setSearchResults(res));
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
79
|
+
} else {
|
|
80
|
+
let image = await createImage(file);
|
|
81
|
+
dispatch(setRequestImage(image));
|
|
82
|
+
let searchRegion : RectCoords | undefined;
|
|
83
|
+
if (settings.regions) {
|
|
84
|
+
let {
|
|
85
|
+
regions: foundRegions,
|
|
86
|
+
selectedRegion: suggestedRegion
|
|
87
|
+
} = await findRegions(image, settings);
|
|
88
|
+
searchRegion = suggestedRegion;
|
|
89
|
+
dispatch(setRegions(foundRegions));
|
|
90
|
+
dispatch(setSelectedRegion(searchRegion))
|
|
91
|
+
}
|
|
92
|
+
return findByImage(image, searchState.settings, searchRegion).then((res) => {
|
|
93
|
+
dispatch(setSearchResults(res));
|
|
94
|
+
dispatch(showFeedback());
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
} catch (e) {
|
|
98
|
+
// TODO show error messages
|
|
99
|
+
dispatch(setError("There was an error while performing the request. Please try again later."));
|
|
120
100
|
}
|
|
121
|
-
};
|
|
122
101
|
|
|
123
|
-
|
|
124
|
-
return setRectCoords(value);
|
|
125
|
-
}, 1200);
|
|
102
|
+
};
|
|
126
103
|
|
|
127
104
|
const debouncedSetRectCoords = useCallback(
|
|
128
|
-
(value
|
|
129
|
-
|
|
130
|
-
|
|
105
|
+
debounce(value => {
|
|
106
|
+
dispatch(selectionChanged(value));
|
|
107
|
+
feedbackRegionEpic(searchState, value);
|
|
108
|
+
findByImage(requestImage!!.canvas, settings, value).then((res) => {
|
|
109
|
+
dispatch(searchFileImageNonRegion(res));
|
|
110
|
+
dispatch(showFeedback());
|
|
111
|
+
}).catch(e => console.warn('catch', e));
|
|
112
|
+
}, 1200),
|
|
113
|
+
[requestImage, searchState]
|
|
131
114
|
);
|
|
132
115
|
|
|
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
116
|
const handlers : AppHandlers = {
|
|
146
|
-
onExampleImageClick: url =>
|
|
117
|
+
onExampleImageClick: url => {
|
|
118
|
+
startSearch(url);
|
|
119
|
+
},
|
|
147
120
|
onCameraClick: () => dispatch(showCamera),
|
|
148
121
|
onCaptureCanceled: () => dispatch(showStart),
|
|
149
|
-
onCaptureComplete: (i) =>
|
|
122
|
+
onCaptureComplete: (i) => startSearch(i),
|
|
150
123
|
onCloseFeedback: () => dispatch(hideFeedback),
|
|
151
|
-
onFileDropped: (f) =>
|
|
152
|
-
onImageClick: (position, url) =>
|
|
124
|
+
onFileDropped: (f) => startSearch(f),
|
|
125
|
+
onImageClick: (position, url) => {
|
|
126
|
+
startSearch(url);
|
|
127
|
+
feedbackClickEpic(searchState, position);
|
|
128
|
+
},
|
|
153
129
|
onLinkClick: onLinkClick,
|
|
154
130
|
onPositiveFeedback: () => {
|
|
155
131
|
dispatch(feedbackSubmitPositive());
|
|
156
|
-
|
|
132
|
+
feedbackSuccessEpic(searchState, true);
|
|
157
133
|
},
|
|
158
134
|
onNegativeFeedback: () => {
|
|
159
135
|
dispatch(feedbackNegative());
|
|
160
|
-
|
|
136
|
+
feedbackSuccessEpic(searchState, false);
|
|
161
137
|
},
|
|
162
|
-
onSelectFile: (f) =>
|
|
138
|
+
onSelectFile: (f) => startSearch(f),
|
|
163
139
|
onSelectionChange: r => {
|
|
164
140
|
setSelection(r);
|
|
165
141
|
debouncedSetRectCoords(r);
|
|
@@ -15,23 +15,23 @@ import {
|
|
|
15
15
|
import algoliasearch from "algoliasearch/lite";
|
|
16
16
|
import CustomSearchBox from "components/input/inputSearch";
|
|
17
17
|
import {createSessionByApi} from "../../services/session";
|
|
18
|
+
import {AlgoliaSettings} from "../../types";
|
|
18
19
|
|
|
19
20
|
interface Props {}
|
|
20
21
|
|
|
21
22
|
function AppNewVersion(props: Props) {
|
|
22
23
|
const dispatch = useAppDispatch();
|
|
23
24
|
const history = useHistory();
|
|
24
|
-
const
|
|
25
|
-
const { settings, search }: any = searchState;
|
|
25
|
+
const { settings, search } = useAppSelector((state) => state);
|
|
26
26
|
const [searchStateInput, setSearchStateInput] = useState<any>({});
|
|
27
27
|
const [isLoading, setLoading] = useState<boolean>(false);
|
|
28
|
-
const {
|
|
29
|
-
const searchClient = algoliasearch(
|
|
30
|
-
searchClient.initIndex(
|
|
28
|
+
const { apiKey, appId, indexName } = settings.algolia as AlgoliaSettings;
|
|
29
|
+
const searchClient = algoliasearch(appId, apiKey);
|
|
30
|
+
searchClient.initIndex(indexName);
|
|
31
31
|
|
|
32
32
|
useEffect(() => {
|
|
33
33
|
const createSession = async () => {
|
|
34
|
-
let payload = await createSessionByApi(
|
|
34
|
+
let payload = await createSessionByApi(settings);
|
|
35
35
|
dispatch(setUpdateSession(payload));
|
|
36
36
|
};
|
|
37
37
|
|
|
@@ -67,10 +67,10 @@ function AppNewVersion(props: Props) {
|
|
|
67
67
|
return (
|
|
68
68
|
<Box className={`box-content-main ${isLoading ? "loading" : ""}`}>
|
|
69
69
|
<InstantSearch
|
|
70
|
-
indexName={
|
|
70
|
+
indexName={indexName}
|
|
71
71
|
searchClient={searchClient}
|
|
72
72
|
searchState={searchStateInput}
|
|
73
|
-
onSearchStateChange={(state
|
|
73
|
+
onSearchStateChange={(state) => {
|
|
74
74
|
setSearchStateInput(state);
|
|
75
75
|
dispatch(changeValueTextSearch(state));
|
|
76
76
|
history.push("/result");
|