@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.
Files changed (37) hide show
  1. package/build/asset-manifest.json +11 -11
  2. package/build/index.html +1 -1
  3. package/build/{precache-manifest.bffed513ca17d8ac16af1cc3aaa7d908.js → precache-manifest.793f0a4375602ec8cd0fba83bf0e3e67.js} +9 -9
  4. package/build/service-worker.js +1 -1
  5. package/build/static/css/main.0c9239ba.chunk.css +2 -0
  6. package/build/static/css/main.0c9239ba.chunk.css.map +1 -0
  7. package/build/static/js/2.520bb6d6.chunk.js +3 -0
  8. package/build/static/js/{2.4e9a4ce1.chunk.js.LICENSE.txt → 2.520bb6d6.chunk.js.LICENSE.txt} +0 -0
  9. package/build/static/js/2.520bb6d6.chunk.js.map +1 -0
  10. package/build/static/js/main.8405239a.chunk.js +2 -0
  11. package/build/static/js/main.8405239a.chunk.js.map +1 -0
  12. package/package.json +2 -2
  13. package/src/App.tsx +346 -213
  14. package/src/actions/nyrisAppActions.ts +69 -65
  15. package/src/actions/searchActions.ts +301 -196
  16. package/src/components/CategoryFilter.tsx +16 -13
  17. package/src/components/Codes.tsx +20 -16
  18. package/src/components/ExampleImages.tsx +27 -17
  19. package/src/components/Feedback.tsx +78 -48
  20. package/src/components/FiltersList.tsx +106 -59
  21. package/src/components/Header.tsx +29 -17
  22. package/src/components/PredictedCategories.tsx +15 -12
  23. package/src/components/Result.tsx +186 -113
  24. package/src/components/SelectedFiltersSummary.tsx +84 -0
  25. package/src/components/Sidebar.tsx +41 -32
  26. package/src/epics/index.ts +173 -104
  27. package/src/epics/search.ts +209 -177
  28. package/src/index.css +98 -9
  29. package/src/index.tsx +148 -144
  30. package/src/utils.ts +5 -0
  31. package/build/static/css/main.2a76dc8a.chunk.css +0 -2
  32. package/build/static/css/main.2a76dc8a.chunk.css.map +0 -1
  33. package/build/static/js/2.4e9a4ce1.chunk.js +0 -3
  34. package/build/static/js/2.4e9a4ce1.chunk.js.map +0 -1
  35. package/build/static/js/main.ec93aa4d.chunk.js +0 -2
  36. package/build/static/js/main.ec93aa4d.chunk.js.map +0 -1
  37. package/src/Demo2.tsx +0 -220
@@ -1,154 +1,223 @@
1
- import {combineEpics, ofType} from "redux-observable";
2
- import {debounceTime, delay, ignoreElements, map, switchMap, tap, withLatestFrom} from "rxjs/operators";
3
- import {showFeedback, showResults} from "../actions/nyrisAppActions";
4
- import {EpicConf} from "./types";
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 {searchOffersForImage, searchOffersForCad, searchRegions} from "../actions/searchActions";
8
- import {AppAction} from "../types";
9
- import {selectFirstCenteredRegion} from "@nyris/nyris-api";
10
-
11
-
12
-
13
- const historyEpic: EpicConf = (action$, state$, {history}) => action$.pipe(
14
- ofType('SHOW_RESULTS', 'SHOW_START'),
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
- let { type } = action;
18
- console.log("action");
19
- console.log(state.search.selectedFilters);
20
- // action to clear all filters
21
- if (type === 'SHOW_RESULTS' && history.location.pathname !== '/results') {
22
- history.push('/results');
23
- }
24
- if (type === 'SHOW_START' && history.location.pathname !== '/') {
25
-
26
- history.goBack();
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$) => action$.pipe(
33
- ofType('SEARCH_REQUEST_SUCCEED'),
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$) => action$.pipe(
38
- ofType('SEARCH_REQUEST_SUCCEED'),
45
+ const onSearchSuccessRedirectToSite: EpicConf = (action$, state$) =>
46
+ action$.pipe(
47
+ ofType("SEARCH_REQUEST_SUCCEED"),
39
48
  withLatestFrom(state$),
40
- tap(([action, {settings}]) => {
41
- if (action.type !== 'SEARCH_REQUEST_SUCCEED' || !action.results || action.results.length !== 1) {
42
- return;
43
- }
44
-
45
- const firstLink = action.results[0].l;
46
- const instantRedirectPatterns = settings.instantRedirectPatterns;
47
- if (!instantRedirectPatterns.find(r => new RegExp(r).test(firstLink))) {
48
- return;
49
- }
50
- window.location.href = firstLink;
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$) => action$.pipe(
56
- ofType('SEARCH_REQUEST_SUCCEED'),
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
- const startSearchOnImageLoaded: EpicConf = (action$, state$) => action$.pipe(
63
- ofType('IMAGE_LOADED'),
75
+ const startSearchOnImageLoaded: EpicConf = (action$, state$) =>
76
+ action$.pipe(
77
+ ofType("IMAGE_LOADED"),
64
78
  withLatestFrom(state$),
65
- switchMap(async ([action, {settings}]) : Promise<AppAction> => {
66
- if (action.type !== 'IMAGE_LOADED') {
67
- throw new Error(`Wrong action type ${action.type}`);
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
- let { image } = action;
71
-
72
- if (settings.regions) {
73
- return searchRegions(image.canvas);
74
- }
75
- return searchOffersForImage(image.canvas);
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$) => action$.pipe(
80
- ofType('CAD_LOADED'),
93
+ const startSearchOnCadLoaded: EpicConf = (action$, state$) =>
94
+ action$.pipe(
95
+ ofType("CAD_LOADED"),
81
96
  withLatestFrom(state$),
82
- switchMap(async ([action, {settings}]) : Promise<AppAction> => {
83
- if (action.type !== 'CAD_LOADED') {
84
- throw new Error(`Wrong action type ${action.type}`);
85
- }
86
- let { file } = action;
87
- return searchOffersForCad(file);
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$) => action$.pipe(
92
- ofType('REGION_REQUEST_SUCCEED'),
106
+ const startSearchOnRegionsSuccessful: EpicConf = (action$, state$) =>
107
+ action$.pipe(
108
+ ofType("REGION_REQUEST_SUCCEED"),
93
109
  withLatestFrom(state$),
94
- switchMap(async ([action, { search: { requestImage}}]) : Promise<AppAction> => {
95
- if (action.type !== 'REGION_REQUEST_SUCCEED') {
96
- throw new Error(`Wrong action type ${action.type}`);
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
- throw new Error(`No requestImage`);
121
+ throw new Error(`No requestImage`);
100
122
  }
101
123
  let { regions } = action;
102
124
 
103
- let selection = selectFirstCenteredRegion(regions, 0.3, {x1: 0, x2: 1, y1: 0, y2: 1});
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$) => action$.pipe(
109
- ofType('REGION_REQUEST_FAIL'),
136
+ const startSearchOnRegionsFailed: EpicConf = (action$, state$) =>
137
+ action$.pipe(
138
+ ofType("REGION_REQUEST_FAIL"),
110
139
  withLatestFrom(state$),
111
- switchMap(async ([action, { search: { requestImage}}]) : Promise<AppAction> => {
112
- if (action.type !== 'REGION_REQUEST_FAIL') {
113
- throw new Error(`Wrong action type ${action.type}`);
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
- throw new Error(`No requestImage`);
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$) => action$.pipe(
124
- ofType('REGION_CHANGED'),
159
+ const startSearchOnRegionChange: EpicConf = (action$, state$) =>
160
+ action$.pipe(
161
+ ofType("REGION_CHANGED"),
125
162
  debounceTime(1200),
126
163
  withLatestFrom(state$),
127
- switchMap(async ([action, { search: { requestImage}}]) : Promise<AppAction> => {
128
- if (action.type !== 'REGION_CHANGED') {
129
- throw new Error(`Wrong action type ${action.type}`);
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
- throw new Error(`No requestImage`);
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
- searchEpics,
142
- feedbackEpics,
143
- historyEpic,
144
- startSearchOnImageLoaded,
145
- startSearchOnCadLoaded,
146
- startSearchOnRegionsSuccessful,
147
- startSearchOnRegionsFailed,
148
- startSearchOnRegionChange,
149
- onSearchSuccessShowResults,
150
- onSearchSuccessShowFeedbackDelayed,
151
- onSearchSuccessRedirectToSite
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;