@nyris/nyris-webapp 0.3.4 → 0.3.9
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 +18 -32
- package/build/index.html +1 -1
- package/build/{precache-manifest.9800bdc87f5a2c5d6d8a5d1a5287598f.js → precache-manifest.a97813497ab8d37548141e5e2618d0dc.js} +13 -89
- package/build/service-worker.js +1 -1
- package/build/static/css/2.43a1c8b7.chunk.css +2 -0
- package/build/static/css/2.43a1c8b7.chunk.css.map +1 -0
- package/build/static/css/main.0481043c.chunk.css +2 -0
- package/build/static/css/main.0481043c.chunk.css.map +1 -0
- package/build/static/js/2.6e13adbe.chunk.js +3 -0
- package/build/static/js/2.6e13adbe.chunk.js.LICENSE.txt +79 -0
- package/build/static/js/2.6e13adbe.chunk.js.map +1 -0
- package/build/static/js/main.f5da7aa4.chunk.js +2 -0
- package/build/static/js/main.f5da7aa4.chunk.js.map +1 -0
- package/build/static/js/{runtime-main.b418ff16.js → runtime-main.f5553a9b.js} +1 -1
- package/build/static/js/{runtime-main.b418ff16.js.map → runtime-main.f5553a9b.js.map} +1 -1
- package/package.json +7 -30
- package/src/App.css +64 -20
- package/src/App.test.tsx +49 -0
- package/src/App.tsx +242 -17
- package/src/AppMD.tsx +320 -0
- package/src/actions/nyrisAppActions.ts +76 -0
- package/src/actions/searchActions.ts +217 -0
- package/src/components/ExampleImages.tsx +17 -32
- package/src/components/Feedback.tsx +48 -87
- package/src/components/FiltersList.tsx +67 -0
- package/src/components/Header.tsx +17 -32
- package/src/components/Result.tsx +113 -186
- package/src/components/Sidebar.tsx +42 -0
- package/src/defaults.ts +3 -4
- package/src/epics/feedback.ts +59 -0
- package/src/epics/index.ts +154 -0
- package/src/epics/search.ts +164 -0
- package/src/epics/types.ts +12 -0
- package/src/{common/assets/fonts → fonts}/roboto-bold-webfont.woff +0 -0
- package/src/{common/assets/fonts → fonts}/roboto-bold-webfont.woff2 +0 -0
- package/src/{common/assets/fonts → fonts}/roboto-italic-webfont.woff +0 -0
- package/src/{common/assets/fonts → fonts}/roboto-italic-webfont.woff2 +0 -0
- package/src/{common/assets/fonts → fonts}/roboto-regular-webfont.woff +0 -0
- package/src/{common/assets/fonts → fonts}/roboto-regular-webfont.woff2 +0 -0
- package/src/{common/assets/fonts → fonts}/robotocondensed-bold-webfont.woff +0 -0
- package/src/{common/assets/fonts → fonts}/robotocondensed-bold-webfont.woff2 +0 -0
- package/src/{common/assets/fonts → fonts}/robotocondensed-bolditalic-webfont.woff +0 -0
- package/src/{common/assets/fonts → fonts}/robotocondensed-bolditalic-webfont.woff2 +0 -0
- package/src/{common/assets/images → images}/fav/android-icon-192x192.png +0 -0
- package/src/{common/assets/images → images}/fav/apple-icon-114x114.png +0 -0
- package/src/{common/assets/images → images}/fav/apple-icon-120x120.png +0 -0
- package/src/{common/assets/images → images}/fav/apple-icon-144x144.png +0 -0
- package/src/{common/assets/images → images}/fav/apple-icon-152x152.png +0 -0
- package/src/{common/assets/images → images}/fav/apple-icon-180x180.png +0 -0
- package/src/{common/assets/images → images}/fav/apple-icon-57x57.png +0 -0
- package/src/{common/assets/images → images}/fav/apple-icon-60x60.png +0 -0
- package/src/{common/assets/images → images}/fav/apple-icon-72x72.png +0 -0
- package/src/{common/assets/images → images}/fav/apple-icon-76x76.png +0 -0
- package/src/{common/assets/images → images}/fav/browserconfig.xml +0 -0
- package/src/{common/assets/images → images}/fav/favicon-16x16.png +0 -0
- package/src/{common/assets/images → images}/fav/favicon-32x32.png +0 -0
- package/src/{common/assets/images → images}/fav/favicon-96x96.png +0 -0
- package/src/{common/assets/images → images}/fav/manifest.json +0 -0
- package/src/{common/assets/images → images}/ic_cam.png +0 -0
- package/src/{common/assets/images → images}/ic_cam.svg +0 -0
- package/src/{common/assets/images → images}/ic_cam_large.png +0 -0
- package/src/{common/assets/images → images}/ic_cam_large.svg +0 -0
- package/src/{common/assets/images → images}/ic_cam_large_noimage.png +0 -0
- package/src/{common/assets/images → images}/ic_close_feedback.png +0 -0
- package/src/{common/assets/images → images}/ic_close_feedback.svg +0 -0
- package/src/{common/assets/images → images}/ic_shopNow.png +0 -0
- package/src/{common/assets/images → images}/ic_shopNow.svg +0 -0
- package/src/{common/assets/images → images}/ic_shopNowLight.png +0 -0
- package/src/{common/assets/images → images}/ic_shopNowLight.svg +0 -0
- package/src/{common/assets/images → images}/nyris_logo.png +0 -0
- package/src/{common/assets/images → images}/rewe.svg +0 -0
- package/src/{common/assets/images → images}/sectionTransBack.png +0 -0
- package/src/{common/assets/images → images}/sectionTransBack.svg +0 -0
- package/src/{common/assets/images → images}/sectionTransTop.png +0 -0
- package/src/{common/assets/images → images}/sectionTransTop.svg +0 -0
- package/src/index.css +415 -572
- package/src/index.tsx +191 -39
- package/src/types.ts +3 -42
- package/tsconfig.json +8 -3
- package/build/js/settings.example.js +0 -31
- package/build/js/test.js +0 -56
- package/build/static/css/2.8285176a.chunk.css +0 -2
- package/build/static/css/2.8285176a.chunk.css.map +0 -1
- package/build/static/css/main.6676fe1f.chunk.css +0 -2
- package/build/static/css/main.6676fe1f.chunk.css.map +0 -1
- package/build/static/js/2.29ddd567.chunk.js +0 -3
- package/build/static/js/2.29ddd567.chunk.js.LICENSE.txt +0 -124
- 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/build/static/media/Fill.37094b44.svg +0 -3
- package/build/static/media/Montserrat-Bold.5a052e98.otf +0 -0
- package/build/static/media/Montserrat-Light.21789e89.otf +0 -0
- package/build/static/media/Montserrat-Medium.a53e0373.otf +0 -0
- package/build/static/media/Montserrat-Regular.71cdc681.otf +0 -0
- package/build/static/media/Montserrat-SemiBold.f613d915.otf +0 -0
- package/build/static/media/Rectangle.4dd8b747.png +0 -0
- package/build/static/media/admin.9529c7f6.svg +0 -3
- package/build/static/media/bg-support-page.6ac55268.svg +0 -9
- package/build/static/media/book_mark.8e294c0b.svg +0 -3
- package/build/static/media/icon_dislike.94607ca6.svg +0 -3
- package/build/static/media/icon_like.a4fb1b18.svg +0 -3
- package/build/static/media/icon_modal_image.3068d0ea.svg +0 -21
- package/build/static/media/icon_search_image.c2c728c0.svg +0 -3
- package/build/static/media/nyris_logo.22d8f250.svg +0 -3
- package/build/static/media/reload_icon.4b579a74.svg +0 -3
- package/build/static/media/save_search.bebaeebf.svg +0 -3
- package/build/static/media/support.289c3a3c.svg +0 -3
- package/build/static/media/translate_icon.f0492297.svg +0 -3
- package/public/js/settings.example.js +0 -31
- package/public/js/test.js +0 -56
- package/src/Router.tsx +0 -97
- package/src/Store/Auth.ts +0 -44
- package/src/Store/Nyris.ts +0 -77
- package/src/Store/Search.ts +0 -270
- package/src/Store/Store.ts +0 -53
- package/src/Store/common.d.ts +0 -10
- package/src/common/assets/fonts/Montserrat_OTF/Montserrat-Bold.otf +0 -0
- package/src/common/assets/fonts/Montserrat_OTF/Montserrat-Light.otf +0 -0
- package/src/common/assets/fonts/Montserrat_OTF/Montserrat-Medium.otf +0 -0
- package/src/common/assets/fonts/Montserrat_OTF/Montserrat-Regular.otf +0 -0
- package/src/common/assets/fonts/Montserrat_OTF/Montserrat-SemiBold.otf +0 -0
- package/src/common/assets/icons/Fill.png +0 -0
- package/src/common/assets/icons/Fill.svg +0 -3
- package/src/common/assets/icons/Icon_wechat.png +0 -0
- package/src/common/assets/icons/Icon_whatsapp.png +0 -0
- package/src/common/assets/icons/admin.png +0 -0
- package/src/common/assets/icons/admin.svg +0 -3
- package/src/common/assets/icons/book_mark.png +0 -0
- package/src/common/assets/icons/book_mark.svg +0 -3
- package/src/common/assets/icons/icon_barcode.png +0 -0
- package/src/common/assets/icons/icon_camera.png +0 -0
- package/src/common/assets/icons/icon_dislike.svg +0 -3
- package/src/common/assets/icons/icon_disslike.png +0 -0
- package/src/common/assets/icons/icon_email.png +0 -0
- package/src/common/assets/icons/icon_like.png +0 -0
- package/src/common/assets/icons/icon_like.svg +0 -3
- package/src/common/assets/icons/icon_modal_image.png +0 -0
- package/src/common/assets/icons/icon_modal_image.svg +0 -21
- package/src/common/assets/icons/icon_picture.png +0 -0
- package/src/common/assets/icons/icon_search_image.png +0 -0
- package/src/common/assets/icons/icon_search_image.svg +0 -3
- package/src/common/assets/icons/nyris_logo.svg +0 -3
- package/src/common/assets/icons/reload_icon.png +0 -0
- package/src/common/assets/icons/reload_icon.svg +0 -3
- package/src/common/assets/icons/save_search.png +0 -0
- package/src/common/assets/icons/save_search.svg +0 -3
- package/src/common/assets/icons/setting_search_icon.png +0 -0
- package/src/common/assets/icons/support.png +0 -0
- package/src/common/assets/icons/support.svg +0 -3
- package/src/common/assets/icons/translate_icon.png +0 -0
- package/src/common/assets/icons/translate_icon.svg +0 -3
- package/src/common/assets/icons/view_off.png +0 -0
- package/src/common/assets/images/Rectangle.png +0 -0
- package/src/common/assets/images/bg-support-page.svg +0 -9
- package/src/common/assets/images/image_test.png +0 -0
- package/src/components/CustomHits/index.tsx +0 -57
- package/src/components/DetailItem.tsx +0 -175
- package/src/components/DragDropFile.tsx +0 -188
- package/src/components/FilterComponent.tsx +0 -33
- package/src/components/Footer.tsx +0 -29
- package/src/components/FooterMD.tsx +0 -54
- package/src/components/FooterNewVersion.tsx +0 -12
- package/src/components/FooterResult.tsx +0 -47
- package/src/components/HeaderMd.tsx +0 -38
- package/src/components/HeaderNewVersion.tsx +0 -92
- package/src/components/Layout.tsx +0 -46
- package/src/components/LoadingScreen/index.tsx +0 -29
- package/src/components/Navigation.tsx +0 -34
- package/src/components/Panigation/Pagination.tsx +0 -140
- package/src/components/Panigation/cx.js +0 -3
- package/src/components/Panigation/isModifierClick.js +0 -10
- package/src/components/Saved/AllItem.tsx +0 -32
- package/src/components/Saved/Category.tsx +0 -16
- package/src/components/carousel/DefaultCarousel.tsx +0 -48
- package/src/components/common.d.ts +0 -9
- package/src/components/common.scss +0 -54
- package/src/components/default-select.tsx +0 -44
- package/src/components/hitItem/hits.tsx +0 -50
- package/src/components/hitItem/infinitiHits.tsx +0 -33
- package/src/components/input/inputSearch.tsx +0 -77
- package/src/components/modal/DefaultModal.tsx +0 -28
- package/src/components/results/ItemResult.tsx +0 -155
- package/src/components/search/ListSearch.tsx +0 -209
- package/src/modules/LandingPage/App.tsx +0 -318
- package/src/modules/LandingPage/AppMD.tsx +0 -399
- package/src/modules/LandingPage/common.scss +0 -1304
- package/src/modules/LandingPage/index.tsx +0 -193
- package/src/modules/LandingPage/indexNewVersion.tsx +0 -110
- package/src/modules/LandingPage/propsType.ts +0 -43
- package/src/page/Auth/login.tsx +0 -7
- package/src/page/Exception/404.tsx +0 -11
- package/src/page/History/index.tsx +0 -76
- package/src/page/Profile/index.tsx +0 -87
- package/src/page/Saved/MockData.ts +0 -223
- package/src/page/Saved/index.tsx +0 -166
- package/src/page/Support/index.tsx +0 -160
- package/src/page/result/MockData.ts +0 -36
- package/src/page/result/index.tsx +0 -468
- package/src/services/Feedback.ts +0 -65
- package/src/services/findByImage.ts +0 -24
- package/src/services/findRegionsCustom.ts +0 -15
- package/src/services/image.ts +0 -107
- package/src/services/nyris.ts +0 -123
- package/src/services/session.ts +0 -20
- package/src/services/types.ts +0 -82
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {combineEpics, ofType} from "redux-observable";
|
|
2
|
+
import {debounceTime, ignoreElements, tap, withLatestFrom} from "rxjs/operators";
|
|
3
|
+
import {EpicConf} from "./types";
|
|
4
|
+
|
|
5
|
+
const feedbackSuccessEpic: EpicConf = (action$, state$, {api}) => action$.pipe(
|
|
6
|
+
ofType('FEEDBACK_SUBMIT_POSITIVE', "FEEDBACK_SUBMIT_NEGATIVE"),
|
|
7
|
+
withLatestFrom(state$),
|
|
8
|
+
tap(async ([{type}, state]) => {
|
|
9
|
+
const success = type === 'FEEDBACK_SUBMIT_POSITIVE';
|
|
10
|
+
const sessionId = state.search.sessionId || state.search.requestId;
|
|
11
|
+
if (sessionId && state.search.requestId) {
|
|
12
|
+
await api.sendFeedback(sessionId, state.search.requestId, {
|
|
13
|
+
event: 'feedback', data: {success}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}),
|
|
17
|
+
ignoreElements()
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const feedbackRegionEpic: EpicConf = (action$, state$, {api}) => action$.pipe(
|
|
21
|
+
ofType('REGION_CHANGED'),
|
|
22
|
+
debounceTime(1200),
|
|
23
|
+
withLatestFrom(state$),
|
|
24
|
+
tap(async ([action, state]) => {
|
|
25
|
+
if (action.type === 'REGION_CHANGED') {
|
|
26
|
+
let {normalizedRect: {x1, x2, y1, y2}} = action;
|
|
27
|
+
const sessionId = state.search.sessionId || state.search.requestId;
|
|
28
|
+
if (sessionId && state.search.requestId) {
|
|
29
|
+
await api.sendFeedback(sessionId, state.search.requestId, {
|
|
30
|
+
event: 'region', data: {rect: {x: x1, y: y1, w: x2 - x1, h: y2 - y1}}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}),
|
|
35
|
+
ignoreElements()
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const feedbackClickEpic: EpicConf = (action$, state$, {api}) => action$.pipe(
|
|
39
|
+
ofType('RESULT_LINK_CLICKED', 'RESULT_IMAGE_CLICKED'),
|
|
40
|
+
withLatestFrom(state$),
|
|
41
|
+
tap(async ([action, state]) => {
|
|
42
|
+
if (action.type === 'RESULT_LINK_CLICKED' || action.type === 'RESULT_IMAGE_CLICKED') {
|
|
43
|
+
let {position} = action;
|
|
44
|
+
const sessionId = state.search.sessionId || state.search.requestId;
|
|
45
|
+
if (sessionId && state.search.requestId) {
|
|
46
|
+
await api.sendFeedback(sessionId, state.search.requestId, {
|
|
47
|
+
event: 'click', data: {positions: [position]}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
ignoreElements()
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export default combineEpics(
|
|
56
|
+
feedbackSuccessEpic,
|
|
57
|
+
feedbackRegionEpic,
|
|
58
|
+
feedbackClickEpic
|
|
59
|
+
);
|
|
@@ -0,0 +1,154 @@
|
|
|
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";
|
|
5
|
+
import feedbackEpics from "./feedback";
|
|
6
|
+
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
|
+
withLatestFrom(state$),
|
|
16
|
+
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
|
+
}),
|
|
29
|
+
ignoreElements()
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const onSearchSuccessShowResults: EpicConf = (action$) => action$.pipe(
|
|
33
|
+
ofType('SEARCH_REQUEST_SUCCEED'),
|
|
34
|
+
map(showResults)
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const onSearchSuccessRedirectToSite: EpicConf = (action$, state$) => action$.pipe(
|
|
38
|
+
ofType('SEARCH_REQUEST_SUCCEED'),
|
|
39
|
+
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;
|
|
51
|
+
}),
|
|
52
|
+
ignoreElements()
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const onSearchSuccessShowFeedbackDelayed: EpicConf = (action$) => action$.pipe(
|
|
56
|
+
ofType('SEARCH_REQUEST_SUCCEED'),
|
|
57
|
+
delay(3000),
|
|
58
|
+
map(showFeedback)
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
const startSearchOnImageLoaded: EpicConf = (action$, state$) => action$.pipe(
|
|
63
|
+
ofType('IMAGE_LOADED'),
|
|
64
|
+
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
|
+
}
|
|
69
|
+
|
|
70
|
+
let { image } = action;
|
|
71
|
+
|
|
72
|
+
if (settings.regions) {
|
|
73
|
+
return searchRegions(image.canvas);
|
|
74
|
+
}
|
|
75
|
+
return searchOffersForImage(image.canvas);
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const startSearchOnCadLoaded: EpicConf = (action$, state$) => action$.pipe(
|
|
80
|
+
ofType('CAD_LOADED'),
|
|
81
|
+
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);
|
|
88
|
+
})
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const startSearchOnRegionsSuccessful: EpicConf = (action$, state$) => action$.pipe(
|
|
92
|
+
ofType('REGION_REQUEST_SUCCEED'),
|
|
93
|
+
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}`);
|
|
97
|
+
}
|
|
98
|
+
if (!requestImage) {
|
|
99
|
+
throw new Error(`No requestImage`);
|
|
100
|
+
}
|
|
101
|
+
let { regions } = action;
|
|
102
|
+
|
|
103
|
+
let selection = selectFirstCenteredRegion(regions, 0.3, {x1: 0, x2: 1, y1: 0, y2: 1});
|
|
104
|
+
return searchOffersForImage(requestImage.canvas, selection);
|
|
105
|
+
})
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const startSearchOnRegionsFailed: EpicConf = (action$, state$) => action$.pipe(
|
|
109
|
+
ofType('REGION_REQUEST_FAIL'),
|
|
110
|
+
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}`);
|
|
114
|
+
}
|
|
115
|
+
if (!requestImage) {
|
|
116
|
+
throw new Error(`No requestImage`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return searchOffersForImage(requestImage.canvas);
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const startSearchOnRegionChange: EpicConf = (action$, state$) => action$.pipe(
|
|
124
|
+
ofType('REGION_CHANGED'),
|
|
125
|
+
debounceTime(1200),
|
|
126
|
+
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}`);
|
|
130
|
+
}
|
|
131
|
+
if (!requestImage) {
|
|
132
|
+
throw new Error(`No requestImage`);
|
|
133
|
+
}
|
|
134
|
+
let { normalizedRect } = action;
|
|
135
|
+
return searchOffersForImage(requestImage.canvas, normalizedRect);
|
|
136
|
+
})
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
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
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
export default rootEpic;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import {EpicConf} from "./types";
|
|
2
|
+
import {combineEpics, ofType} from "redux-observable";
|
|
3
|
+
import {switchMap, withLatestFrom} from "rxjs/operators";
|
|
4
|
+
import {AppAction} from "../types";
|
|
5
|
+
import {ImageSearchOptions, urlOrBlobToCanvas, isCadFile, isImageFile, Filter } from "@nyris/nyris-api";
|
|
6
|
+
import {imageLoaded, cadFileLoaded} from "../actions/searchActions";
|
|
7
|
+
|
|
8
|
+
const imageSearch: EpicConf = (action$, state$, {api}) => action$.pipe(
|
|
9
|
+
ofType('SEARCH_REQUEST_START'),
|
|
10
|
+
withLatestFrom(state$),
|
|
11
|
+
switchMap(async ([action, state]) : Promise<AppAction> => {
|
|
12
|
+
if (action.type !== 'SEARCH_REQUEST_START') {
|
|
13
|
+
throw new Error(`Wrong action type ${action.type}`);
|
|
14
|
+
}
|
|
15
|
+
console.log("state search ");
|
|
16
|
+
console.log(state.search.selectedFilters);
|
|
17
|
+
|
|
18
|
+
if ('image' in action) {
|
|
19
|
+
let { image, normalizedRect} = action;
|
|
20
|
+
console.log("Selected Filters");
|
|
21
|
+
let selectedFilters = new Array<Filter>();
|
|
22
|
+
if(state.search.selectedFilters.size > 0 ){
|
|
23
|
+
state.search.selectedFilters.forEach((values, key) => {
|
|
24
|
+
let filterObj: Filter ={
|
|
25
|
+
key : key,
|
|
26
|
+
values : values
|
|
27
|
+
}
|
|
28
|
+
selectedFilters.push(filterObj);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let options : ImageSearchOptions = {
|
|
33
|
+
cropRect: normalizedRect
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
if(selectedFilters && selectedFilters.length> 0)
|
|
38
|
+
{
|
|
39
|
+
console.log("With Filters");
|
|
40
|
+
const {results, duration, requestId, categoryPredictions, codes} = await api.findByImageWithFilters(image, options, selectedFilters);
|
|
41
|
+
return ({ type: 'SEARCH_REQUEST_SUCCEED', results, requestId, duration, categoryPredictions, codes });
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
else{
|
|
45
|
+
console.log("Without Filters");
|
|
46
|
+
const {results, duration, requestId, categoryPredictions, codes} = await api.findByImage(image, options);
|
|
47
|
+
return ({ type: 'SEARCH_REQUEST_SUCCEED', results, requestId, duration, categoryPredictions, codes });
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.warn('search failed', e);
|
|
51
|
+
return ({ type: 'SEARCH_REQUEST_FAIL', reason: e.message, exception: e });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if ('file' in action) {
|
|
56
|
+
console.log('file');
|
|
57
|
+
let { file } = action;
|
|
58
|
+
|
|
59
|
+
let options : ImageSearchOptions = { };
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
const {results, duration, requestId, categoryPredictions, codes} = await api.findByCad(file, options);
|
|
63
|
+
return ({ type: 'SEARCH_REQUEST_SUCCEED', results, requestId, duration, categoryPredictions, codes });
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.warn('search failed', e);
|
|
66
|
+
return ({ type: 'SEARCH_REQUEST_FAIL', reason: e.message, exception: e });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
throw new Error(`Wrong action content ${action}`);
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const regionSearch: EpicConf = (action$, state$, {api}) => action$.pipe(
|
|
74
|
+
ofType('REGION_REQUEST_START'),
|
|
75
|
+
withLatestFrom(state$),
|
|
76
|
+
switchMap(async ([action, {settings}]) : Promise<AppAction> => {
|
|
77
|
+
if (action.type !== 'REGION_REQUEST_START') {
|
|
78
|
+
throw new Error(`Wrong action type ${action.type}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let { image } = action;
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
let regions = await api.findRegions(image);
|
|
85
|
+
return {type: 'REGION_REQUEST_SUCCEED', regions };
|
|
86
|
+
|
|
87
|
+
} catch (e) {
|
|
88
|
+
console.error(e);
|
|
89
|
+
return {type: 'REGION_REQUEST_FAIL', reason: e.message, exception: e};
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const loadFile: EpicConf = (action$) => action$.pipe(
|
|
95
|
+
ofType('LOAD_FILE'),
|
|
96
|
+
switchMap(async (action) : Promise<AppAction> => {
|
|
97
|
+
if (action.type !== 'LOAD_FILE') {
|
|
98
|
+
throw new Error(`Wrong action type ${action.type}`);
|
|
99
|
+
}
|
|
100
|
+
const randomId = Math.random().toString();
|
|
101
|
+
if ('file' in action) {
|
|
102
|
+
const file = action.file;
|
|
103
|
+
if (isImageFile(file)) {
|
|
104
|
+
return imageLoaded(await urlOrBlobToCanvas(file), randomId);
|
|
105
|
+
}
|
|
106
|
+
if (isCadFile(file)) {
|
|
107
|
+
return cadFileLoaded(file, randomId);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
throw new Error(`LOAD_FILE action wrong properties ${Object.keys(action).join(',')}`);
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const loadImage: EpicConf = (action$) => action$.pipe(
|
|
115
|
+
ofType('LOAD_IMAGE'),
|
|
116
|
+
switchMap(async (action) : Promise<AppAction> => {
|
|
117
|
+
if (action.type !== 'LOAD_IMAGE') {
|
|
118
|
+
throw new Error(`Wrong action type ${action.type}`);
|
|
119
|
+
}
|
|
120
|
+
const randomId = Math.random().toString();
|
|
121
|
+
if ('url' in action) {
|
|
122
|
+
return imageLoaded(await urlOrBlobToCanvas(action.url), randomId);
|
|
123
|
+
}
|
|
124
|
+
if ('file' in action) {
|
|
125
|
+
return imageLoaded(await urlOrBlobToCanvas(action.file), randomId);
|
|
126
|
+
}
|
|
127
|
+
if ('image' in action) {
|
|
128
|
+
return imageLoaded(action.image, randomId);
|
|
129
|
+
}
|
|
130
|
+
throw new Error(`LOAD_IMAGE action wrong properties ${Object.keys(action).join(',')}`);
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
const loadFilters: EpicConf = (action$, state$, {api}) => action$.pipe(
|
|
136
|
+
ofType('LOAD_FILTERS'),
|
|
137
|
+
withLatestFrom(state$),
|
|
138
|
+
switchMap(async ([action, state]) : Promise<AppAction> => {
|
|
139
|
+
if(action.type !== 'LOAD_FILTERS'){
|
|
140
|
+
throw new Error(`Wrong action type ${action.type}`);
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
// use find filters
|
|
144
|
+
|
|
145
|
+
let filters = await api.getFilters();
|
|
146
|
+
|
|
147
|
+
filters= filters.slice(0, 3);
|
|
148
|
+
console.log(filters);
|
|
149
|
+
return {type: 'LOAD_FILTERS_SUCCESS', filters };
|
|
150
|
+
|
|
151
|
+
} catch (e) {
|
|
152
|
+
console.error(e);
|
|
153
|
+
return {type: 'LOAD_FILTERS_FAIL', reason: e.message, exception: e};
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
export default combineEpics(
|
|
160
|
+
imageSearch,
|
|
161
|
+
regionSearch,
|
|
162
|
+
loadFile,
|
|
163
|
+
loadImage,
|
|
164
|
+
loadFilters);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import NyrisAPI from "@nyris/nyris-api";
|
|
2
|
+
import {Epic} from "redux-observable";
|
|
3
|
+
import {AppAction, AppState} from "../types";
|
|
4
|
+
import {History} from "history";
|
|
5
|
+
|
|
6
|
+
export interface EpicsDependencies {
|
|
7
|
+
api: NyrisAPI,
|
|
8
|
+
history: History
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type EpicConf = Epic<AppAction, AppAction, AppState, EpicsDependencies>;
|
|
12
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|