@nyris/nyris-webapp 0.3.6 → 0.3.13
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 +11 -11
- package/build/index.html +1 -1
- package/build/{precache-manifest.bffed513ca17d8ac16af1cc3aaa7d908.js → precache-manifest.793f0a4375602ec8cd0fba83bf0e3e67.js} +9 -9
- package/build/service-worker.js +1 -1
- package/build/static/css/main.0c9239ba.chunk.css +2 -0
- package/build/static/css/main.0c9239ba.chunk.css.map +1 -0
- package/build/static/js/2.520bb6d6.chunk.js +3 -0
- package/build/static/js/{2.4e9a4ce1.chunk.js.LICENSE.txt → 2.520bb6d6.chunk.js.LICENSE.txt} +0 -0
- package/build/static/js/2.520bb6d6.chunk.js.map +1 -0
- package/build/static/js/main.8405239a.chunk.js +2 -0
- package/build/static/js/main.8405239a.chunk.js.map +1 -0
- package/package.json +2 -2
- package/src/App.tsx +346 -213
- package/src/actions/nyrisAppActions.ts +69 -65
- package/src/actions/searchActions.ts +301 -196
- package/src/components/CategoryFilter.tsx +16 -13
- package/src/components/Codes.tsx +20 -16
- package/src/components/ExampleImages.tsx +27 -17
- package/src/components/Feedback.tsx +78 -48
- package/src/components/FiltersList.tsx +106 -59
- package/src/components/Header.tsx +29 -17
- package/src/components/PredictedCategories.tsx +15 -12
- package/src/components/Result.tsx +186 -113
- package/src/components/SelectedFiltersSummary.tsx +84 -0
- package/src/components/Sidebar.tsx +41 -32
- package/src/epics/index.ts +173 -104
- package/src/epics/search.ts +209 -177
- package/src/index.css +98 -9
- package/src/index.tsx +148 -144
- package/src/utils.ts +5 -0
- package/build/static/css/main.2a76dc8a.chunk.css +0 -2
- package/build/static/css/main.2a76dc8a.chunk.css.map +0 -1
- package/build/static/js/2.4e9a4ce1.chunk.js +0 -3
- package/build/static/js/2.4e9a4ce1.chunk.js.map +0 -1
- package/build/static/js/main.ec93aa4d.chunk.js +0 -2
- package/build/static/js/main.ec93aa4d.chunk.js.map +0 -1
- package/src/Demo2.tsx +0 -220
package/src/epics/index.ts
CHANGED
|
@@ -1,154 +1,223 @@
|
|
|
1
|
-
import {combineEpics, ofType} from "redux-observable";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { combineEpics, ofType } from "redux-observable";
|
|
2
|
+
import {
|
|
3
|
+
debounceTime,
|
|
4
|
+
delay,
|
|
5
|
+
ignoreElements,
|
|
6
|
+
map,
|
|
7
|
+
switchMap,
|
|
8
|
+
tap,
|
|
9
|
+
withLatestFrom,
|
|
10
|
+
} from "rxjs/operators";
|
|
11
|
+
import { showFeedback, showResults } from "../actions/nyrisAppActions";
|
|
12
|
+
import { EpicConf } from "./types";
|
|
5
13
|
import feedbackEpics from "./feedback";
|
|
6
14
|
import searchEpics from "./search";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
import {
|
|
16
|
+
searchOffersForImage,
|
|
17
|
+
searchOffersForCad,
|
|
18
|
+
searchRegions,
|
|
19
|
+
} from "../actions/searchActions";
|
|
20
|
+
import { AppAction } from "../types";
|
|
21
|
+
import { selectFirstCenteredRegion } from "@nyris/nyris-api";
|
|
22
|
+
|
|
23
|
+
const historyEpic: EpicConf = (action$, state$, { history }) =>
|
|
24
|
+
action$.pipe(
|
|
25
|
+
ofType("SHOW_RESULTS", "SHOW_START"),
|
|
15
26
|
withLatestFrom(state$),
|
|
16
27
|
tap(([action, state]) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
+
let { type } = action;
|
|
29
|
+
console.log("action");
|
|
30
|
+
console.log(state.search.selectedFilters);
|
|
31
|
+
// action to clear all filters
|
|
32
|
+
if (type === "SHOW_RESULTS" && history.location.pathname !== "/results") {
|
|
33
|
+
history.push("/results");
|
|
34
|
+
}
|
|
35
|
+
if (type === "SHOW_START" && history.location.pathname !== "/") {
|
|
36
|
+
history.goBack();
|
|
37
|
+
}
|
|
28
38
|
}),
|
|
29
39
|
ignoreElements()
|
|
30
|
-
);
|
|
40
|
+
);
|
|
31
41
|
|
|
32
|
-
const onSearchSuccessShowResults: EpicConf = (action$) =>
|
|
33
|
-
|
|
34
|
-
map(showResults)
|
|
35
|
-
);
|
|
42
|
+
const onSearchSuccessShowResults: EpicConf = (action$) =>
|
|
43
|
+
action$.pipe(ofType("SEARCH_REQUEST_SUCCEED"), map(showResults));
|
|
36
44
|
|
|
37
|
-
const onSearchSuccessRedirectToSite: EpicConf = (action$, state$) =>
|
|
38
|
-
|
|
45
|
+
const onSearchSuccessRedirectToSite: EpicConf = (action$, state$) =>
|
|
46
|
+
action$.pipe(
|
|
47
|
+
ofType("SEARCH_REQUEST_SUCCEED"),
|
|
39
48
|
withLatestFrom(state$),
|
|
40
|
-
tap(([action, {settings}]) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
tap(([action, { settings }]) => {
|
|
50
|
+
if (
|
|
51
|
+
action.type !== "SEARCH_REQUEST_SUCCEED" ||
|
|
52
|
+
!action.results ||
|
|
53
|
+
action.results.length !== 1
|
|
54
|
+
) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const firstLink = action.results[0].l;
|
|
59
|
+
const instantRedirectPatterns = settings.instantRedirectPatterns;
|
|
60
|
+
if (!instantRedirectPatterns.find((r) => new RegExp(r).test(firstLink))) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
window.location.href = firstLink;
|
|
51
64
|
}),
|
|
52
65
|
ignoreElements()
|
|
53
|
-
);
|
|
66
|
+
);
|
|
54
67
|
|
|
55
|
-
const onSearchSuccessShowFeedbackDelayed: EpicConf = (action$) =>
|
|
56
|
-
|
|
68
|
+
const onSearchSuccessShowFeedbackDelayed: EpicConf = (action$) =>
|
|
69
|
+
action$.pipe(
|
|
70
|
+
ofType("SEARCH_REQUEST_SUCCEED"),
|
|
57
71
|
delay(3000),
|
|
58
72
|
map(showFeedback)
|
|
59
|
-
);
|
|
73
|
+
);
|
|
60
74
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
ofType(
|
|
75
|
+
const startSearchOnImageLoaded: EpicConf = (action$, state$) =>
|
|
76
|
+
action$.pipe(
|
|
77
|
+
ofType("IMAGE_LOADED"),
|
|
64
78
|
withLatestFrom(state$),
|
|
65
|
-
switchMap(async ([action, {settings}])
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
79
|
+
switchMap(async ([action, { settings }]): Promise<AppAction> => {
|
|
80
|
+
if (action.type !== "IMAGE_LOADED") {
|
|
81
|
+
throw new Error(`Wrong action type ${action.type}`);
|
|
82
|
+
}
|
|
69
83
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
84
|
+
let { image } = action;
|
|
85
|
+
|
|
86
|
+
if (settings.regions) {
|
|
87
|
+
return searchRegions(image.canvas);
|
|
88
|
+
}
|
|
89
|
+
return searchOffersForImage(image.canvas);
|
|
76
90
|
})
|
|
77
|
-
);
|
|
91
|
+
);
|
|
78
92
|
|
|
79
|
-
const startSearchOnCadLoaded: EpicConf = (action$, state$) =>
|
|
80
|
-
|
|
93
|
+
const startSearchOnCadLoaded: EpicConf = (action$, state$) =>
|
|
94
|
+
action$.pipe(
|
|
95
|
+
ofType("CAD_LOADED"),
|
|
81
96
|
withLatestFrom(state$),
|
|
82
|
-
switchMap(async ([action, {settings}])
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
switchMap(async ([action, { settings }]): Promise<AppAction> => {
|
|
98
|
+
if (action.type !== "CAD_LOADED") {
|
|
99
|
+
throw new Error(`Wrong action type ${action.type}`);
|
|
100
|
+
}
|
|
101
|
+
let { file } = action;
|
|
102
|
+
return searchOffersForCad(file);
|
|
88
103
|
})
|
|
89
|
-
);
|
|
104
|
+
);
|
|
90
105
|
|
|
91
|
-
const startSearchOnRegionsSuccessful: EpicConf = (action$, state$) =>
|
|
92
|
-
|
|
106
|
+
const startSearchOnRegionsSuccessful: EpicConf = (action$, state$) =>
|
|
107
|
+
action$.pipe(
|
|
108
|
+
ofType("REGION_REQUEST_SUCCEED"),
|
|
93
109
|
withLatestFrom(state$),
|
|
94
|
-
switchMap(
|
|
95
|
-
|
|
96
|
-
|
|
110
|
+
switchMap(
|
|
111
|
+
async ([
|
|
112
|
+
action,
|
|
113
|
+
{
|
|
114
|
+
search: { requestImage },
|
|
115
|
+
},
|
|
116
|
+
]): Promise<AppAction> => {
|
|
117
|
+
if (action.type !== "REGION_REQUEST_SUCCEED") {
|
|
118
|
+
throw new Error(`Wrong action type ${action.type}`);
|
|
97
119
|
}
|
|
98
120
|
if (!requestImage) {
|
|
99
|
-
|
|
121
|
+
throw new Error(`No requestImage`);
|
|
100
122
|
}
|
|
101
123
|
let { regions } = action;
|
|
102
124
|
|
|
103
|
-
let selection = selectFirstCenteredRegion(regions, 0.3, {
|
|
125
|
+
let selection = selectFirstCenteredRegion(regions, 0.3, {
|
|
126
|
+
x1: 0,
|
|
127
|
+
x2: 1,
|
|
128
|
+
y1: 0,
|
|
129
|
+
y2: 1,
|
|
130
|
+
});
|
|
104
131
|
return searchOffersForImage(requestImage.canvas, selection);
|
|
105
|
-
|
|
106
|
-
)
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
);
|
|
107
135
|
|
|
108
|
-
const startSearchOnRegionsFailed: EpicConf = (action$, state$) =>
|
|
109
|
-
|
|
136
|
+
const startSearchOnRegionsFailed: EpicConf = (action$, state$) =>
|
|
137
|
+
action$.pipe(
|
|
138
|
+
ofType("REGION_REQUEST_FAIL"),
|
|
110
139
|
withLatestFrom(state$),
|
|
111
|
-
switchMap(
|
|
112
|
-
|
|
113
|
-
|
|
140
|
+
switchMap(
|
|
141
|
+
async ([
|
|
142
|
+
action,
|
|
143
|
+
{
|
|
144
|
+
search: { requestImage },
|
|
145
|
+
},
|
|
146
|
+
]): Promise<AppAction> => {
|
|
147
|
+
if (action.type !== "REGION_REQUEST_FAIL") {
|
|
148
|
+
throw new Error(`Wrong action type ${action.type}`);
|
|
114
149
|
}
|
|
115
150
|
if (!requestImage) {
|
|
116
|
-
|
|
151
|
+
throw new Error(`No requestImage`);
|
|
117
152
|
}
|
|
118
153
|
|
|
119
154
|
return searchOffersForImage(requestImage.canvas);
|
|
120
|
-
|
|
121
|
-
)
|
|
155
|
+
}
|
|
156
|
+
)
|
|
157
|
+
);
|
|
122
158
|
|
|
123
|
-
const startSearchOnRegionChange: EpicConf = (action$, state$) =>
|
|
124
|
-
|
|
159
|
+
const startSearchOnRegionChange: EpicConf = (action$, state$) =>
|
|
160
|
+
action$.pipe(
|
|
161
|
+
ofType("REGION_CHANGED"),
|
|
125
162
|
debounceTime(1200),
|
|
126
163
|
withLatestFrom(state$),
|
|
127
|
-
switchMap(
|
|
128
|
-
|
|
129
|
-
|
|
164
|
+
switchMap(
|
|
165
|
+
async ([
|
|
166
|
+
action,
|
|
167
|
+
{
|
|
168
|
+
search: { requestImage },
|
|
169
|
+
},
|
|
170
|
+
]): Promise<AppAction> => {
|
|
171
|
+
if (action.type !== "REGION_CHANGED") {
|
|
172
|
+
throw new Error(`Wrong action type ${action.type}`);
|
|
130
173
|
}
|
|
131
174
|
if (!requestImage) {
|
|
132
|
-
|
|
175
|
+
throw new Error(`No requestImage`);
|
|
133
176
|
}
|
|
134
177
|
let { normalizedRect } = action;
|
|
135
178
|
return searchOffersForImage(requestImage.canvas, normalizedRect);
|
|
136
|
-
|
|
137
|
-
)
|
|
179
|
+
}
|
|
180
|
+
)
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
const startSearchOnFilterChange: EpicConf = (action$, state$) =>
|
|
184
|
+
action$.pipe(
|
|
185
|
+
ofType("FILTER_CHANGED"),
|
|
186
|
+
withLatestFrom(state$),
|
|
187
|
+
switchMap(
|
|
188
|
+
async ([
|
|
189
|
+
action,
|
|
190
|
+
{
|
|
191
|
+
search: { requestImage },
|
|
192
|
+
},
|
|
193
|
+
]): Promise<AppAction> => {
|
|
194
|
+
if (action.type !== "FILTER_CHANGED") {
|
|
195
|
+
throw new Error(`Wrong action type ${action.type}`);
|
|
196
|
+
}
|
|
197
|
+
if (requestImage) {
|
|
198
|
+
return searchOffersForImage(requestImage.canvas);
|
|
199
|
+
} else {
|
|
200
|
+
return { type: "FILTER_CHANGED_FAIL" };
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
)
|
|
204
|
+
);
|
|
138
205
|
|
|
206
|
+
//const startSearchOnClearingAllFilters:
|
|
139
207
|
|
|
140
208
|
const rootEpic = combineEpics(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
209
|
+
searchEpics,
|
|
210
|
+
feedbackEpics,
|
|
211
|
+
historyEpic,
|
|
212
|
+
startSearchOnImageLoaded,
|
|
213
|
+
startSearchOnCadLoaded,
|
|
214
|
+
startSearchOnRegionsSuccessful,
|
|
215
|
+
startSearchOnRegionsFailed,
|
|
216
|
+
startSearchOnRegionChange,
|
|
217
|
+
onSearchSuccessShowResults,
|
|
218
|
+
onSearchSuccessShowFeedbackDelayed,
|
|
219
|
+
onSearchSuccessRedirectToSite,
|
|
220
|
+
startSearchOnFilterChange
|
|
152
221
|
);
|
|
153
222
|
|
|
154
223
|
export default rootEpic;
|