@nyris/nyris-webapp 0.3.9 → 0.3.12
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.a97813497ab8d37548141e5e2618d0dc.js → precache-manifest.1b00dd5c15aa0815244681503d6fa9da.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.6e13adbe.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.ef6a9744.chunk.js +2 -0
- package/build/static/js/main.ef6a9744.chunk.js.map +1 -0
- package/package.json +2 -2
- package/src/App.tsx +333 -188
- package/src/actions/nyrisAppActions.ts +69 -65
- package/src/actions/searchActions.ts +301 -195
- 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 +113 -58
- 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 +85 -0
- package/src/components/Sidebar.tsx +44 -34
- package/src/epics/index.ts +173 -104
- package/src/epics/search.ts +214 -139
- package/src/index.css +95 -6
- package/src/index.tsx +147 -145
- package/src/utils.ts +5 -0
- package/build/static/css/main.0481043c.chunk.css +0 -2
- package/build/static/css/main.0481043c.chunk.css.map +0 -1
- package/build/static/js/2.6e13adbe.chunk.js +0 -3
- package/build/static/js/2.6e13adbe.chunk.js.map +0 -1
- package/build/static/js/main.f5da7aa4.chunk.js +0 -2
- package/build/static/js/main.f5da7aa4.chunk.js.map +0 -1
|
@@ -1,76 +1,80 @@
|
|
|
1
|
-
import {AppAction} from "../types";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type NyrisAppPart = 'start' | 'camera' | 'results';
|
|
5
|
-
export type NyrisFeedbackState = 'hidden' | 'question' | 'positive' | 'negative';
|
|
1
|
+
import { AppAction } from "../types";
|
|
6
2
|
|
|
3
|
+
export type NyrisAppPart = "start" | "camera" | "results";
|
|
4
|
+
export type NyrisFeedbackState =
|
|
5
|
+
| "hidden"
|
|
6
|
+
| "question"
|
|
7
|
+
| "positive"
|
|
8
|
+
| "negative";
|
|
7
9
|
|
|
8
10
|
export interface NyrisAppState {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
showPart: NyrisAppPart;
|
|
12
|
+
feedbackState: NyrisFeedbackState;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export type NyrisAction =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
| { type: "SHOW_START" }
|
|
17
|
+
| { type: "SHOW_CAMERA" }
|
|
18
|
+
| { type: "SHOW_RESULTS" }
|
|
19
|
+
| { type: "SHOW_FEEDBACK" }
|
|
20
|
+
| { type: "HIDE_FEEDBACK" }
|
|
21
|
+
| { type: "RESULT_LINK_CLICKED"; position: number; url: string }
|
|
22
|
+
| { type: "RESULT_IMAGE_CLICKED"; position: number; url: string };
|
|
22
23
|
|
|
23
|
-
export const showCamera = ()
|
|
24
|
-
export const showStart = ()
|
|
25
|
-
export const showResults = ()
|
|
26
|
-
export const showFeedback = ()
|
|
27
|
-
export const hideFeedback = ()
|
|
24
|
+
export const showCamera = (): NyrisAction => ({ type: "SHOW_CAMERA" });
|
|
25
|
+
export const showStart = (): NyrisAction => ({ type: "SHOW_START" });
|
|
26
|
+
export const showResults = (): NyrisAction => ({ type: "SHOW_RESULTS" });
|
|
27
|
+
export const showFeedback = (): NyrisAction => ({ type: "SHOW_FEEDBACK" });
|
|
28
|
+
export const hideFeedback = (): NyrisAction => ({ type: "HIDE_FEEDBACK" });
|
|
28
29
|
|
|
29
|
-
const initialNyrisState
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const initialNyrisState: NyrisAppState = {
|
|
31
|
+
showPart: "start",
|
|
32
|
+
feedbackState: "hidden",
|
|
32
33
|
};
|
|
33
34
|
|
|
34
|
-
export function reducer(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
35
|
+
export function reducer(
|
|
36
|
+
state: NyrisAppState = initialNyrisState,
|
|
37
|
+
action: AppAction
|
|
38
|
+
): NyrisAppState {
|
|
39
|
+
switch (action.type) {
|
|
40
|
+
case "SHOW_START":
|
|
41
|
+
return {
|
|
42
|
+
...state,
|
|
43
|
+
showPart: "start",
|
|
44
|
+
};
|
|
45
|
+
case "SHOW_CAMERA":
|
|
46
|
+
return {
|
|
47
|
+
...state,
|
|
48
|
+
showPart: "camera",
|
|
49
|
+
};
|
|
50
|
+
case "SEARCH_REQUEST_START":
|
|
51
|
+
case "REGION_REQUEST_START":
|
|
52
|
+
case "SHOW_RESULTS":
|
|
53
|
+
return {
|
|
54
|
+
...state,
|
|
55
|
+
showPart: "results",
|
|
56
|
+
};
|
|
57
|
+
case "SHOW_FEEDBACK":
|
|
58
|
+
return {
|
|
59
|
+
...state,
|
|
60
|
+
feedbackState: "question",
|
|
61
|
+
};
|
|
62
|
+
case "HIDE_FEEDBACK":
|
|
63
|
+
return {
|
|
64
|
+
...state,
|
|
65
|
+
feedbackState: "hidden",
|
|
66
|
+
};
|
|
67
|
+
case "FEEDBACK_SUBMIT_POSITIVE":
|
|
68
|
+
return {
|
|
69
|
+
...state,
|
|
70
|
+
feedbackState: "positive",
|
|
71
|
+
};
|
|
72
|
+
case "FEEDBACK_SUBMIT_NEGATIVE":
|
|
73
|
+
return {
|
|
74
|
+
...state,
|
|
75
|
+
feedbackState: "negative",
|
|
76
|
+
};
|
|
77
|
+
default:
|
|
78
|
+
return state;
|
|
79
|
+
}
|
|
76
80
|
}
|
|
@@ -1,217 +1,323 @@
|
|
|
1
|
-
import {CanvasWithId} from "../types";
|
|
2
|
-
import {
|
|
1
|
+
import { CanvasWithId } from "../types";
|
|
2
|
+
import {
|
|
3
|
+
Code,
|
|
4
|
+
RectCoords,
|
|
5
|
+
Region,
|
|
6
|
+
selectFirstCenteredRegion,
|
|
7
|
+
Filter,
|
|
8
|
+
} from "@nyris/nyris-api";
|
|
3
9
|
|
|
4
10
|
export type ImageSourceType =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
| { url: string }
|
|
12
|
+
| { file: File }
|
|
13
|
+
| { image: HTMLCanvasElement };
|
|
8
14
|
|
|
9
15
|
export type SearchAction =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
| { type: "FEEDBACK_SUBMIT_POSITIVE" }
|
|
17
|
+
| { type: "FEEDBACK_SUBMIT_NEGATIVE" }
|
|
18
|
+
| { type: "IMAGE_LOADED"; image: CanvasWithId }
|
|
19
|
+
| { type: "REGION_REQUEST_START"; image: HTMLCanvasElement }
|
|
20
|
+
| { type: "REGION_REQUEST_SUCCEED"; regions: Region[] }
|
|
21
|
+
| { type: "REGION_REQUEST_FAIL"; reason: string; exception: any }
|
|
22
|
+
| {
|
|
23
|
+
type: "SEARCH_REQUEST_START";
|
|
24
|
+
image: HTMLCanvasElement;
|
|
25
|
+
normalizedRect?: RectCoords;
|
|
26
|
+
selectedFilters?: Filter[];
|
|
27
|
+
}
|
|
28
|
+
| { type: "SEARCH_REQUEST_START"; file: File }
|
|
29
|
+
| {
|
|
30
|
+
type: "SEARCH_REQUEST_SUCCEED";
|
|
31
|
+
results: any[];
|
|
32
|
+
requestId: string;
|
|
33
|
+
duration: number;
|
|
34
|
+
categoryPredictions: CategoryPrediction[];
|
|
35
|
+
codes: Code[];
|
|
36
|
+
}
|
|
37
|
+
| { type: "SEARCH_REQUEST_FAIL"; reason: string; exception?: any }
|
|
38
|
+
| { type: "REGION_CHANGED"; normalizedRect: RectCoords }
|
|
39
|
+
| ({ type: "LOAD_IMAGE" } & ImageSourceType)
|
|
40
|
+
| { type: "LOAD_FILE"; file: File }
|
|
41
|
+
| { type: "CAD_LOADED"; file: File }
|
|
42
|
+
| { type: "LOAD_FILTERS" }
|
|
43
|
+
| { type: "LOAD_FILTERS_SUCCESS"; filters: Filter[] }
|
|
44
|
+
| { type: "LOAD_FILTERS_FAIL"; reason: string; exception: any }
|
|
45
|
+
| { type: "ADD_TO_SELECTEDFILTERS"; key: string; value: string }
|
|
46
|
+
| { type: "REMOVE_FROM_SELECTEDFILTERS"; key: string; value: string }
|
|
47
|
+
| { type: "CLEAR_SELECTED_FILTERS" }
|
|
48
|
+
| { type: "SEARCH_FILTERS"; key: string; value: string }
|
|
49
|
+
| { type: "FILTER_CHANGED" }
|
|
50
|
+
| { type: "FILTER_CHANGED_FAIL" }
|
|
51
|
+
| { type: "CLEAR_REQUEST_IMAGE" }
|
|
52
|
+
| { type: "UPDATE_FILTERS"; key: string; values: string[] };
|
|
31
53
|
|
|
32
54
|
interface CategoryPrediction {
|
|
33
|
-
|
|
34
|
-
|
|
55
|
+
name: string;
|
|
56
|
+
score: number;
|
|
35
57
|
}
|
|
36
58
|
|
|
37
59
|
export interface SearchState {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
results: any[];
|
|
61
|
+
duration?: number;
|
|
62
|
+
requestId?: string;
|
|
63
|
+
sessionId?: string;
|
|
64
|
+
regions: Region[];
|
|
65
|
+
selectedRegion: RectCoords;
|
|
66
|
+
fetchingRegions: boolean;
|
|
67
|
+
fetchingResults: boolean;
|
|
68
|
+
filterOptions: string[];
|
|
69
|
+
requestImage?: CanvasWithId;
|
|
70
|
+
requestCadFile?: File;
|
|
71
|
+
categoryPredictions: CategoryPrediction[];
|
|
72
|
+
codes: Code[];
|
|
73
|
+
errorMessage: string;
|
|
74
|
+
filters: Filter[];
|
|
75
|
+
selectedFilters: Map<string, string[]>;
|
|
54
76
|
}
|
|
55
77
|
|
|
56
|
-
const initialState
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
const initialState: SearchState = {
|
|
79
|
+
results: [],
|
|
80
|
+
regions: [],
|
|
81
|
+
selectedRegion: { x1: 0.1, x2: 0.9, y1: 0.1, y2: 0.9 },
|
|
82
|
+
requestImage: undefined,
|
|
83
|
+
fetchingResults: false,
|
|
84
|
+
fetchingRegions: false,
|
|
85
|
+
filterOptions: [],
|
|
86
|
+
categoryPredictions: [],
|
|
87
|
+
codes: [],
|
|
88
|
+
errorMessage: "",
|
|
89
|
+
filters: [],
|
|
90
|
+
selectedFilters: new Map<string, string[]>(),
|
|
69
91
|
};
|
|
70
92
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
export const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
export const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
export const loadFile = (file: File): SearchAction => ({
|
|
94
|
+
type: "LOAD_FILE",
|
|
95
|
+
file,
|
|
96
|
+
});
|
|
97
|
+
export const loadUrl = (url: string): SearchAction => ({
|
|
98
|
+
type: "LOAD_IMAGE",
|
|
99
|
+
url,
|
|
100
|
+
});
|
|
101
|
+
export const loadCanvas = (image: HTMLCanvasElement): SearchAction => ({
|
|
102
|
+
type: "LOAD_IMAGE",
|
|
103
|
+
image,
|
|
104
|
+
});
|
|
105
|
+
export const imageLoaded = (
|
|
106
|
+
image: HTMLCanvasElement,
|
|
107
|
+
id: string
|
|
108
|
+
): SearchAction => ({ type: "IMAGE_LOADED", image: { canvas: image, id: id } });
|
|
109
|
+
export const cadFileLoaded = (file: File, id: string): SearchAction => ({
|
|
110
|
+
type: "CAD_LOADED",
|
|
111
|
+
file,
|
|
112
|
+
});
|
|
113
|
+
export const selectionChanged = (normalizedRect: RectCoords): SearchAction => ({
|
|
114
|
+
type: "REGION_CHANGED",
|
|
115
|
+
normalizedRect,
|
|
116
|
+
});
|
|
117
|
+
export const searchRegions = (image: HTMLCanvasElement): SearchAction => ({
|
|
118
|
+
type: "REGION_REQUEST_START",
|
|
119
|
+
image,
|
|
120
|
+
});
|
|
121
|
+
export const searchOffersForImage = (
|
|
122
|
+
image: HTMLCanvasElement,
|
|
123
|
+
normalizedRect?: RectCoords
|
|
124
|
+
): SearchAction => ({
|
|
125
|
+
type: "SEARCH_REQUEST_START",
|
|
126
|
+
image,
|
|
127
|
+
normalizedRect,
|
|
84
128
|
});
|
|
85
|
-
export const searchOffersForCad = (file: File)
|
|
86
|
-
|
|
87
|
-
|
|
129
|
+
export const searchOffersForCad = (file: File): SearchAction => ({
|
|
130
|
+
type: "SEARCH_REQUEST_START",
|
|
131
|
+
file,
|
|
132
|
+
});
|
|
133
|
+
export const submitPositiveFeedback = (): SearchAction => ({
|
|
134
|
+
type: "FEEDBACK_SUBMIT_POSITIVE",
|
|
135
|
+
});
|
|
136
|
+
export const submitNegativeFeedback = (): SearchAction => ({
|
|
137
|
+
type: "FEEDBACK_SUBMIT_NEGATIVE",
|
|
138
|
+
});
|
|
139
|
+
export const loadFilters = (): SearchAction => ({ type: "LOAD_FILTERS" });
|
|
140
|
+
export const addToSelectedFilters = (
|
|
141
|
+
key: string,
|
|
142
|
+
value: string
|
|
143
|
+
): SearchAction => ({ type: "ADD_TO_SELECTEDFILTERS", key, value });
|
|
144
|
+
export const removeFromSelectedFilters = (
|
|
145
|
+
key: string,
|
|
146
|
+
value: string
|
|
147
|
+
): SearchAction => ({ type: "REMOVE_FROM_SELECTEDFILTERS", key, value });
|
|
148
|
+
export const clearAllSelectedFilters = () => ({
|
|
149
|
+
type: "CLEAR_SELECTED_FILTERS",
|
|
150
|
+
});
|
|
151
|
+
export const searchFilters = (key: string, value: string): SearchAction => ({
|
|
152
|
+
type: "SEARCH_FILTERS",
|
|
153
|
+
key,
|
|
154
|
+
value,
|
|
155
|
+
});
|
|
156
|
+
export const filterChanged = (): SearchAction => ({ type: "FILTER_CHANGED" });
|
|
157
|
+
export const clearRequestImage = (): SearchAction => ({
|
|
158
|
+
type: "CLEAR_REQUEST_IMAGE",
|
|
88
159
|
});
|
|
89
|
-
export const submitPositiveFeedback = () : SearchAction => ({ type: 'FEEDBACK_SUBMIT_POSITIVE'});
|
|
90
|
-
export const submitNegativeFeedback = () : SearchAction => ({ type: 'FEEDBACK_SUBMIT_NEGATIVE'});
|
|
91
|
-
export const loadFilters = (): SearchAction => ({type: 'LOAD_FILTERS'});
|
|
92
|
-
export const addToSelectedFilters =(key: string , value: string): SearchAction => ({type : 'ADD_TO_SELECTEDFILTERS' , key , value});
|
|
93
|
-
export const removeFromSelectedFilters = (key: string, value: string) : SearchAction => ({type: 'REMOVE_FROM_SELECTEDFILTERS', key, value});
|
|
94
|
-
export const reducer = (state : SearchState = initialState, action: SearchAction) => {
|
|
95
|
-
switch (action.type) {
|
|
96
|
-
case "IMAGE_LOADED":
|
|
97
|
-
let { image } = action;
|
|
98
|
-
console.log('image', image)
|
|
99
|
-
return {
|
|
100
|
-
...initialState,
|
|
101
|
-
requestImage: image,
|
|
102
|
-
selectedFilters: state.selectedFilters
|
|
103
160
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
161
|
+
export const reducer = (
|
|
162
|
+
state: SearchState = initialState,
|
|
163
|
+
action: SearchAction
|
|
164
|
+
) => {
|
|
165
|
+
switch (action.type) {
|
|
166
|
+
case "IMAGE_LOADED":
|
|
167
|
+
let { image } = action;
|
|
168
|
+
console.log("image", image);
|
|
169
|
+
return {
|
|
170
|
+
...initialState,
|
|
171
|
+
requestImage: image,
|
|
172
|
+
selectedFilters: state.selectedFilters,
|
|
173
|
+
};
|
|
174
|
+
case "CAD_LOADED":
|
|
175
|
+
let { file } = action;
|
|
176
|
+
return {
|
|
177
|
+
...initialState,
|
|
178
|
+
requestCadFile: file,
|
|
179
|
+
};
|
|
180
|
+
case "REGION_REQUEST_START":
|
|
181
|
+
return {
|
|
182
|
+
...state,
|
|
183
|
+
fetchingRegions: true,
|
|
184
|
+
};
|
|
185
|
+
case "REGION_REQUEST_SUCCEED":
|
|
186
|
+
return {
|
|
187
|
+
...state,
|
|
188
|
+
fetchingRegions: false,
|
|
189
|
+
regions: action.regions,
|
|
190
|
+
selectedRegion: selectFirstCenteredRegion(
|
|
191
|
+
action.regions,
|
|
192
|
+
0.3,
|
|
193
|
+
state.selectedRegion
|
|
194
|
+
),
|
|
195
|
+
};
|
|
196
|
+
case "REGION_REQUEST_FAIL":
|
|
197
|
+
return {
|
|
198
|
+
...state,
|
|
199
|
+
fetchingRegions: false,
|
|
200
|
+
errorMessage: action.exception.response.data.detail,
|
|
201
|
+
};
|
|
202
|
+
case "SEARCH_REQUEST_START":
|
|
203
|
+
return {
|
|
204
|
+
...state,
|
|
205
|
+
fetchingResults: true,
|
|
206
|
+
};
|
|
207
|
+
case "SEARCH_REQUEST_SUCCEED":
|
|
208
|
+
let { results, requestId, duration, categoryPredictions, codes } = action;
|
|
209
|
+
return {
|
|
210
|
+
...state,
|
|
211
|
+
results,
|
|
212
|
+
requestId,
|
|
213
|
+
fetchingResults: false,
|
|
214
|
+
sessionId: state.sessionId || requestId,
|
|
215
|
+
categoryPredictions,
|
|
216
|
+
codes,
|
|
217
|
+
duration,
|
|
218
|
+
};
|
|
219
|
+
case "SEARCH_REQUEST_FAIL":
|
|
220
|
+
return {
|
|
221
|
+
...state,
|
|
222
|
+
fetchingResults: false,
|
|
223
|
+
errorMessage: action.reason,
|
|
224
|
+
};
|
|
225
|
+
case "REGION_CHANGED":
|
|
226
|
+
return {
|
|
227
|
+
...state,
|
|
228
|
+
selectedRegion: action.normalizedRect,
|
|
229
|
+
};
|
|
230
|
+
case "LOAD_FILTERS_SUCCESS":
|
|
231
|
+
return {
|
|
232
|
+
...state,
|
|
233
|
+
filters: action.filters,
|
|
234
|
+
};
|
|
235
|
+
case "LOAD_FILTERS_FAIL":
|
|
236
|
+
return {
|
|
237
|
+
...state,
|
|
238
|
+
errorMessage: action.exception.response.data.detail,
|
|
239
|
+
};
|
|
240
|
+
case "ADD_TO_SELECTEDFILTERS":
|
|
241
|
+
return {
|
|
242
|
+
...state,
|
|
243
|
+
selectedFilters: ADDtoSelectedfilters(
|
|
244
|
+
state.selectedFilters,
|
|
245
|
+
action.key,
|
|
246
|
+
action.value
|
|
247
|
+
),
|
|
248
|
+
};
|
|
249
|
+
case "REMOVE_FROM_SELECTEDFILTERS":
|
|
250
|
+
return {
|
|
251
|
+
...state,
|
|
252
|
+
selectedFilters: RemoveFromSelectedFilters(
|
|
253
|
+
state.selectedFilters,
|
|
254
|
+
action.key,
|
|
255
|
+
action.value
|
|
256
|
+
),
|
|
257
|
+
};
|
|
258
|
+
case "CLEAR_SELECTED_FILTERS":
|
|
259
|
+
return {
|
|
260
|
+
...state,
|
|
261
|
+
selectedFilters: new Map<string, string[]>(),
|
|
262
|
+
};
|
|
263
|
+
case "CLEAR_REQUEST_IMAGE":
|
|
264
|
+
return {
|
|
265
|
+
...state,
|
|
266
|
+
requestImage: undefined,
|
|
267
|
+
};
|
|
268
|
+
case "UPDATE_FILTERS":
|
|
269
|
+
return {
|
|
270
|
+
...state,
|
|
271
|
+
filters: UpdateFilters(state.filters, action.key, action.values),
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
return state;
|
|
275
|
+
};
|
|
182
276
|
|
|
277
|
+
function ADDtoSelectedfilters(
|
|
278
|
+
selectedFilters: Map<string, string[]>,
|
|
279
|
+
key: string,
|
|
280
|
+
value: string
|
|
281
|
+
): Map<string, string[]> {
|
|
282
|
+
if (selectedFilters) {
|
|
283
|
+
let values = selectedFilters.get(key);
|
|
284
|
+
if (values) {
|
|
285
|
+
values.push(value);
|
|
286
|
+
} else {
|
|
287
|
+
values = new Array<string>(value);
|
|
183
288
|
}
|
|
184
|
-
|
|
185
|
-
}
|
|
289
|
+
selectedFilters.set(key, values);
|
|
290
|
+
}
|
|
291
|
+
console.log(selectedFilters);
|
|
292
|
+
return selectedFilters;
|
|
293
|
+
}
|
|
186
294
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return selectedFilters;
|
|
295
|
+
function RemoveFromSelectedFilters(
|
|
296
|
+
selectedFilters: Map<string, string[]>,
|
|
297
|
+
key: string,
|
|
298
|
+
value: string
|
|
299
|
+
): Map<string, string[]> {
|
|
300
|
+
if (selectedFilters) {
|
|
301
|
+
let values = selectedFilters.get(key);
|
|
302
|
+
if (values) {
|
|
303
|
+
values = values.filter((x) => x !== value);
|
|
304
|
+
selectedFilters.set(key, values);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
console.log(selectedFilters);
|
|
308
|
+
return selectedFilters;
|
|
202
309
|
}
|
|
203
310
|
|
|
204
|
-
function
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return selectedFilters;
|
|
311
|
+
function UpdateFilters(filters: Filter[], key: string, values: string[]) {
|
|
312
|
+
console.log(filters);
|
|
313
|
+
console.log(key);
|
|
314
|
+
console.log(values);
|
|
315
|
+
console.log(filters.find((x) => x.key === key));
|
|
316
|
+
if (filters && filters.length > 0 && filters.find((x) => x.key === key)) {
|
|
317
|
+
let idx = filters.findIndex((x) => x.key === key);
|
|
318
|
+
filters[idx].values = values;
|
|
319
|
+
console.log(filters);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return filters;
|
|
217
323
|
}
|