@wayke-se/components-react 3.0.0-beta.11 → 3.0.0-beta.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 (278) hide show
  1. package/dist/index.js +5529 -5460
  2. package/dist/index.js.map +4 -4
  3. package/dist/index.mjs +320 -257
  4. package/dist/index.mjs.map +2 -2
  5. package/package.json +4 -2
  6. package/.editorconfig +0 -10
  7. package/.eslintrc.js +0 -62
  8. package/.github/workflows/release-to-production.yaml +0 -40
  9. package/.github/workflows/release-to-test.yaml +0 -40
  10. package/.prettierrc +0 -12
  11. package/assets/ajax-loader.gif +0 -0
  12. package/assets/default.css +0 -1
  13. package/assets/fonts/slick.eot +0 -0
  14. package/assets/fonts/slick.svg +0 -14
  15. package/assets/fonts/slick.ttf +0 -0
  16. package/assets/fonts/slick.woff +0 -0
  17. package/codegen.yml +0 -19
  18. package/esbuild/build.js +0 -39
  19. package/esbuild/common.js +0 -15
  20. package/esbuild/start.js +0 -21
  21. package/esbuild/www/index.html +0 -32
  22. package/example/src/@types/global.d.ts +0 -7
  23. package/example/src/@types/react-panellum.d.ts +0 -1
  24. package/example/src/App.tsx +0 -77
  25. package/example/src/assets/style/ecom.css +0 -63
  26. package/example/src/assets/style/theme.css +0 -83
  27. package/example/src/index.html +0 -26
  28. package/example/src/index.tsx +0 -11
  29. package/example/src/routes/HashRoute/index.tsx +0 -30
  30. package/example/src/routes/Home/index.tsx +0 -33
  31. package/example/src/routes/NotFound/index.tsx +0 -5
  32. package/example/src/routes/PathRoute/index.tsx +0 -35
  33. package/example/src/routes/Search/index.tsx +0 -28
  34. package/example/src/routes/SearchItem/index.tsx +0 -28
  35. package/example/src/routes/index.tsx +0 -25
  36. package/src/@types/action.ts +0 -3
  37. package/src/@types/codegen/types.ts +0 -366
  38. package/src/@types/filter.ts +0 -18
  39. package/src/@types/queryFilter.ts +0 -5
  40. package/src/@types/react-panellum.d.ts +0 -1
  41. package/src/@types/search.ts +0 -118
  42. package/src/@types/theme.d.ts +0 -5
  43. package/src/@types/vehicle-properties.ts +0 -33
  44. package/src/State/CentralStorage/CentralStorageContext.ts +0 -10
  45. package/src/State/CentralStorage/CentralStorageProvider.tsx +0 -21
  46. package/src/State/CentralStorage/useCentralStorage.ts +0 -37
  47. package/src/State/Path/PathContext.ts +0 -11
  48. package/src/State/Path/PathProvider.tsx +0 -66
  49. package/src/State/Path/reducer.ts +0 -30
  50. package/src/State/Path/usePath.ts +0 -13
  51. package/src/State/RelatedSearch/RelatedSearchContext.ts +0 -18
  52. package/src/State/RelatedSearch/RelatedSearchProvider.tsx +0 -55
  53. package/src/State/RelatedSearch/useRelatedSearch.ts +0 -20
  54. package/src/State/Search/SearchContext.ts +0 -27
  55. package/src/State/Search/SearchProvider.tsx +0 -243
  56. package/src/State/Search/useSearch.ts +0 -6
  57. package/src/State/Settings/SettingsContext.ts +0 -15
  58. package/src/State/Settings/SettingsProvider.tsx +0 -23
  59. package/src/State/Settings/useSettings.ts +0 -7
  60. package/src/components/Accordion/index.tsx +0 -57
  61. package/src/components/Accordion/wrapper.tsx +0 -107
  62. package/src/components/ActionList/index.tsx +0 -48
  63. package/src/components/ActionList/toggle-item.tsx +0 -59
  64. package/src/components/Avatar/index.tsx +0 -12
  65. package/src/components/Avatar/wrapper.tsx +0 -21
  66. package/src/components/Badge/index.tsx +0 -12
  67. package/src/components/Badge/wrapper.tsx +0 -32
  68. package/src/components/Blockquote/index.tsx +0 -32
  69. package/src/components/Blockquote/wrapper.tsx +0 -52
  70. package/src/components/Button/index.tsx +0 -226
  71. package/src/components/CheckMarkList/index.tsx +0 -21
  72. package/src/components/CheckMarkList/wrapper.tsx +0 -31
  73. package/src/components/Checklist/index.tsx +0 -51
  74. package/src/components/Checklist/wrapper.tsx +0 -65
  75. package/src/components/ColorSelect/index.tsx +0 -63
  76. package/src/components/ColorSelect/wrapper.tsx +0 -82
  77. package/src/components/ColumnRow/index.tsx +0 -20
  78. package/src/components/Container/index.tsx +0 -11
  79. package/src/components/Container/wrapper.tsx +0 -14
  80. package/src/components/Content/index.tsx +0 -15
  81. package/src/components/Content/wrapper.tsx +0 -61
  82. package/src/components/ContentLogo/index.tsx +0 -27
  83. package/src/components/DataList/index.tsx +0 -25
  84. package/src/components/DataList/wrapper.tsx +0 -29
  85. package/src/components/DetailBox/index.tsx +0 -34
  86. package/src/components/DetailBox/wrapper.tsx +0 -34
  87. package/src/components/ExtendContent/index.tsx +0 -43
  88. package/src/components/ExtendContent/wrapper.tsx +0 -41
  89. package/src/components/ExtendInfo/index.tsx +0 -32
  90. package/src/components/ExtendInfo/wrapper.tsx +0 -63
  91. package/src/components/Filter/index.tsx +0 -108
  92. package/src/components/Filter/wrapper.tsx +0 -79
  93. package/src/components/FilterPanel/checkListFacet.tsx +0 -46
  94. package/src/components/FilterPanel/colorFacet.tsx +0 -47
  95. package/src/components/FilterPanel/faceSelector.tsx +0 -53
  96. package/src/components/FilterPanel/index.tsx +0 -79
  97. package/src/components/FilterPanel/rangeFacet.tsx +0 -128
  98. package/src/components/FinancialOptions/LoanModal.tsx +0 -223
  99. package/src/components/FinancialOptions/index.tsx +0 -29
  100. package/src/components/FinancialOptions/leasing.tsx +0 -77
  101. package/src/components/FinancialOptions/loan.tsx +0 -87
  102. package/src/components/Gallery/MediaButton.tsx +0 -19
  103. package/src/components/Gallery/index.tsx +0 -227
  104. package/src/components/Gallery/wrapper.tsx +0 -323
  105. package/src/components/Grid/index.tsx +0 -87
  106. package/src/components/Grid/wrapper.tsx +0 -30
  107. package/src/components/Heading/index.tsx +0 -72
  108. package/src/components/Icon/index.tsx +0 -87
  109. package/src/components/InputCheckbox/index.tsx +0 -30
  110. package/src/components/InputCheckbox/wrapper.tsx +0 -87
  111. package/src/components/InputGroup/index.tsx +0 -24
  112. package/src/components/InputLabel/index.tsx +0 -14
  113. package/src/components/InputLabel/wrapper.tsx +0 -10
  114. package/src/components/InputSearch/index.tsx +0 -51
  115. package/src/components/InputSearch/wrapper.tsx +0 -97
  116. package/src/components/InputSelect/index.tsx +0 -35
  117. package/src/components/InputSelect/wrapper.tsx +0 -59
  118. package/src/components/InputText/index.tsx +0 -27
  119. package/src/components/InputText/wrapper.tsx +0 -57
  120. package/src/components/InsuranceOptions/Insurance.tsx +0 -60
  121. package/src/components/InsuranceOptions/InsuranceFree.tsx +0 -59
  122. package/src/components/InsuranceOptions/InsuranceFreeModal.tsx +0 -49
  123. package/src/components/InsuranceOptions/InsuranceModal.tsx +0 -253
  124. package/src/components/InsuranceOptions/index.tsx +0 -27
  125. package/src/components/Lightbox/index.tsx +0 -51
  126. package/src/components/Lightbox/wrapper.tsx +0 -97
  127. package/src/components/Loader/index.tsx +0 -18
  128. package/src/components/Loader/wrapper.tsx +0 -50
  129. package/src/components/LogoBox/index.tsx +0 -22
  130. package/src/components/LogoBox/wrapper.tsx +0 -19
  131. package/src/components/Map/index.tsx +0 -62
  132. package/src/components/Map/wrapper.tsx +0 -29
  133. package/src/components/Modal/index.tsx +0 -51
  134. package/src/components/Modal/wrapper.tsx +0 -127
  135. package/src/components/OpeningHours/index.tsx +0 -145
  136. package/src/components/OptionBox/index.tsx +0 -23
  137. package/src/components/OptionBox/wrapper.tsx +0 -56
  138. package/src/components/OverflowBox/index.tsx +0 -11
  139. package/src/components/OverflowBox/wrapper.tsx +0 -7
  140. package/src/components/OverflowGrid/index.tsx +0 -70
  141. package/src/components/Page/index.tsx +0 -46
  142. package/src/components/Panel/index.tsx +0 -50
  143. package/src/components/Panel/wrapper.tsx +0 -155
  144. package/src/components/Pdf/index.tsx +0 -46
  145. package/src/components/Pdf/wrapper.tsx +0 -61
  146. package/src/components/PhoneNumber/index.tsx +0 -33
  147. package/src/components/Portal/index.ts +0 -5
  148. package/src/components/Portal/portal-element.tsx +0 -9
  149. package/src/components/Portal/portal-namespace.ts +0 -1
  150. package/src/components/Portal/portal.tsx +0 -36
  151. package/src/components/Price/index.tsx +0 -12
  152. package/src/components/PriceTable/index.tsx +0 -34
  153. package/src/components/PriceTable/wrapper.tsx +0 -27
  154. package/src/components/ProductCard/index.tsx +0 -133
  155. package/src/components/ProductCard/wrapper.tsx +0 -147
  156. package/src/components/ProductPage/index.tsx +0 -99
  157. package/src/components/ProgressBar/index.tsx +0 -31
  158. package/src/components/ProgressBar/wrapper.tsx +0 -29
  159. package/src/components/RangeSlider/RangeSliderSimple.tsx +0 -90
  160. package/src/components/RangeSlider/SliderWithLabel.tsx +0 -62
  161. package/src/components/RangeSlider/handle.tsx +0 -26
  162. package/src/components/RangeSlider/index.tsx +0 -132
  163. package/src/components/RangeSlider/track.tsx +0 -19
  164. package/src/components/RangeSlider/wrapper.tsx +0 -93
  165. package/src/components/RangeSliderLabel/index.tsx +0 -18
  166. package/src/components/RangeSliderLabel/wrapper.tsx +0 -33
  167. package/src/components/Repeat/index.tsx +0 -21
  168. package/src/components/Result/index.tsx +0 -91
  169. package/src/components/Result/wrapper.tsx +0 -39
  170. package/src/components/Root/index.tsx +0 -24
  171. package/src/components/SearchBar/index.tsx +0 -48
  172. package/src/components/SearchFilter/index.tsx +0 -31
  173. package/src/components/SearchTerm/index.tsx +0 -23
  174. package/src/components/SearchTerm/wrapper.tsx +0 -71
  175. package/src/components/SectionHeader/index.tsx +0 -25
  176. package/src/components/SectionHeader/wrapper.tsx +0 -17
  177. package/src/components/Snackbar/index.tsx +0 -35
  178. package/src/components/Snackbar/wrapper.tsx +0 -65
  179. package/src/components/SortSelect/index.tsx +0 -35
  180. package/src/components/SortSelect/wrapper.tsx +0 -54
  181. package/src/components/Sphere/Sphere.tsx +0 -49
  182. package/src/components/Sphere/SphereLightbox.tsx +0 -10
  183. package/src/components/Sphere/SphereViewer.tsx +0 -81
  184. package/src/components/Sphere/wrapper.tsx +0 -253
  185. package/src/components/SrOnly/index.tsx +0 -14
  186. package/src/components/SwitchBar/index.tsx +0 -55
  187. package/src/components/SwitchBar/wrapper.tsx +0 -80
  188. package/src/components/TableColumn/index.tsx +0 -18
  189. package/src/components/TableList/index.tsx +0 -39
  190. package/src/components/Tabs/index.tsx +0 -34
  191. package/src/components/Tabs/wrapper.tsx +0 -82
  192. package/src/components/ThreeSixty/Rotation.tsx +0 -136
  193. package/src/components/ThreeSixty/ThreeSixtLightbox.tsx +0 -34
  194. package/src/components/ThreeSixty/ThreeSixty.tsx +0 -53
  195. package/src/components/UspList/index.tsx +0 -47
  196. package/src/components/UspList/wrapper.tsx +0 -92
  197. package/src/components/Utility/index.tsx +0 -17
  198. package/src/components/Video/CustomPlayer.tsx +0 -28
  199. package/src/components/Video/EmbeddedVideoLightbox.tsx +0 -31
  200. package/src/components/Video/EmbededVideo.tsx +0 -72
  201. package/src/components/Video/QuickNavEmbeded.tsx +0 -35
  202. package/src/components/Video/QuickNavVideo.tsx +0 -14
  203. package/src/components/Video/Video.tsx +0 -18
  204. package/src/components/Video/VimeoPlayer.tsx +0 -21
  205. package/src/components/Video/YoutubePlayer.tsx +0 -21
  206. package/src/components/Video/useThumbnail.ts +0 -28
  207. package/src/components/Video/utils.ts +0 -47
  208. package/src/components/Video/wrapper.tsx +0 -29
  209. package/src/hooks/useFetch.ts +0 -88
  210. package/src/hooks/useHasBeenVisible.ts +0 -17
  211. package/src/hooks/useHashGuid.ts +0 -33
  212. package/src/hooks/useInsurance.ts +0 -22
  213. package/src/hooks/useLoan.ts +0 -21
  214. package/src/hooks/useOnScreen.ts +0 -20
  215. package/src/hooks/useOutsideClick.ts +0 -19
  216. package/src/hooks/usePrevious.ts +0 -11
  217. package/src/hooks/useSearchItem.ts +0 -11
  218. package/src/hooks/useSearchItemBranch.ts +0 -14
  219. package/src/hooks/useSessionStorage.ts +0 -32
  220. package/src/hooks/useVimeoThumbnail.ts +0 -31
  221. package/src/images/map/marker.png +0 -0
  222. package/src/images/placeholders/staticmap.jpg +0 -0
  223. package/src/index-dev.tsx +0 -42
  224. package/src/index-esbuild.ts +0 -74
  225. package/src/index.ts +0 -72
  226. package/src/layout/helpers.tsx +0 -6
  227. package/src/layout/keyframes.tsx +0 -23
  228. package/src/layout/theme.ts +0 -60
  229. package/src/layouts/WaykeComposite.tsx +0 -64
  230. package/src/layouts/WaykeCompositeWithProvider.tsx +0 -17
  231. package/src/layouts/search/index.tsx +0 -124
  232. package/src/layouts/searchItem/Branch.tsx +0 -97
  233. package/src/layouts/searchItem/BranchModal.tsx +0 -67
  234. package/src/layouts/searchItem/CheckList.tsx +0 -146
  235. package/src/layouts/searchItem/ManufacturerPackagesOption.tsx +0 -54
  236. package/src/layouts/searchItem/MetadataItem.tsx +0 -74
  237. package/src/layouts/searchItem/PackageOptionModal.tsx +0 -54
  238. package/src/layouts/searchItem/PackageOptions.tsx +0 -58
  239. package/src/layouts/searchItem/Page404.tsx +0 -17
  240. package/src/layouts/searchItem/PageLoading.tsx +0 -17
  241. package/src/layouts/searchItem/Property.tsx +0 -134
  242. package/src/layouts/searchItem/Related.tsx +0 -120
  243. package/src/layouts/searchItem/index.tsx +0 -342
  244. package/src/providers/WaykeItemProvidet.tsx +0 -63
  245. package/src/providers/WaykeProvider.tsx +0 -75
  246. package/src/providers/graphqlProvider.tsx +0 -9
  247. package/src/providers/themeProvider.tsx +0 -15
  248. package/src/queries/INSURANCE_CALCULATION.ts +0 -43
  249. package/src/queries/LOAN_CALCULATION.ts +0 -39
  250. package/src/queries/SEARCH_ITEM_BRANCH_QUERY.ts +0 -120
  251. package/src/queries/SEARCH_ITEM_QUERY.ts +0 -237
  252. package/src/utils/constants.ts +0 -34
  253. package/src/utils/converters.ts +0 -45
  254. package/src/utils/deep-copy.ts +0 -6
  255. package/src/utils/formats.ts +0 -83
  256. package/src/utils/metadata.min.ts +0 -87
  257. package/src/utils/phonenumbers.ts +0 -17
  258. package/src/utils/pubsub/Actions.ts +0 -20
  259. package/src/utils/pubsub/Events.ts +0 -79
  260. package/src/utils/pubsub/pubsub.ts +0 -151
  261. package/src/utils/regex.ts +0 -13
  262. package/src/utils/sortOptions.ts +0 -36
  263. package/src/utils/specification.ts +0 -581
  264. package/src/utils/ssn.ts +0 -1
  265. package/src/utils/url.ts +0 -1
  266. package/src/utils/vehicle-properties/compare-basic-properties.ts +0 -63
  267. package/src/utils/vehicle-properties/compare-categories.ts +0 -45
  268. package/src/utils/vehicle-properties/compare-properties.ts +0 -5
  269. package/src/utils/vehicle-properties/custom-property-adder.ts +0 -163
  270. package/src/utils/vehicle-properties/property-hint-enricher.ts +0 -230
  271. package/src/utils/vehicle-properties/property-remover.ts +0 -28
  272. package/src/utils/vehicle-properties/property-tree-creator.ts +0 -171
  273. package/src/utils/vehicle-properties/property-tree-sorter.ts +0 -20
  274. package/tsconfig.build.json +0 -10
  275. package/tsconfig.eslint.json +0 -11
  276. package/tsconfig.json +0 -18
  277. package/webpack.analyze.js +0 -10
  278. package/webpack.config.js +0 -95
@@ -1,33 +0,0 @@
1
- export interface Property {
2
- value: string | number | boolean | string[];
3
- name: string;
4
- type: string;
5
- unit: string | null | undefined;
6
- hint: string | null | undefined;
7
- }
8
-
9
- export interface Category {
10
- id: number;
11
- name: string;
12
- properties: Property[];
13
- subCategories: Category[];
14
- }
15
-
16
- export interface Tree {
17
- categories: Category[];
18
- }
19
-
20
- export interface EnhancedProperty {
21
- value: number | string | boolean | string[];
22
- name: string;
23
- type: string;
24
- unit: string | undefined | null;
25
- category: ItemCategory | undefined | null;
26
- hint: string | undefined | null;
27
- }
28
-
29
- export interface ItemCategory {
30
- name: string;
31
- id: number;
32
- subCategory: ItemCategory | undefined | null;
33
- }
@@ -1,10 +0,0 @@
1
- import { createContext } from 'react';
2
-
3
- export interface CentralStorageContextProps {
4
- centralStorageId?: string | null;
5
- setCentralStorageId: (id?: string) => void;
6
- }
7
-
8
- export const CentralStorageContext = createContext<CentralStorageContextProps>({
9
- setCentralStorageId: (_) => {},
10
- });
@@ -1,21 +0,0 @@
1
- import React, { useCallback } from 'react';
2
- import { CentralStorageContext } from './CentralStorageContext';
3
- import useSessionStorage from '../../hooks/useSessionStorage';
4
-
5
- interface CentralStorageProviderProps {
6
- children: React.ReactNode;
7
- }
8
-
9
- const CentralStorageProvider = ({ children }: CentralStorageProviderProps) => {
10
- const { value, set, remove } = useSessionStorage('centralStorage');
11
-
12
- const setCentralStorageId = useCallback((id?: string) => (id ? set(id) : remove()), []);
13
-
14
- return (
15
- <CentralStorageContext.Provider value={{ centralStorageId: value, setCentralStorageId }}>
16
- {children}
17
- </CentralStorageContext.Provider>
18
- );
19
- };
20
-
21
- export default CentralStorageProvider;
@@ -1,37 +0,0 @@
1
- import { useContext, useEffect } from 'react';
2
- import { CentralStorageContext } from './CentralStorageContext';
3
- import { Vehicle } from '../../@types/codegen/types';
4
- import useSearchItemBranch from '../../hooks/useSearchItemBranch';
5
-
6
- const useCentralStorage = (vehicle?: Vehicle | null) => {
7
- const { centralStorageId, setCentralStorageId } = useContext(CentralStorageContext);
8
-
9
- const connections = vehicle?.branch?.connections;
10
- const branchId = centralStorageId
11
- ? connections?.find((x) => x.id === centralStorageId)?.id
12
- : undefined;
13
-
14
- const { data, loading } = useSearchItemBranch(vehicle?.id, branchId);
15
-
16
- useEffect(() => {
17
- if ((connections?.length || 0) > 0) {
18
- const match = centralStorageId
19
- ? connections?.find((x) => x.id === centralStorageId)
20
- : undefined;
21
-
22
- if (!match) {
23
- const first = connections?.[0];
24
- if (first) {
25
- setCentralStorageId(first.id);
26
- }
27
- }
28
- }
29
- }, [connections]);
30
-
31
- return {
32
- vehicle: (connections?.length || 0) > 0 ? data?.vehicle : vehicle,
33
- loading,
34
- };
35
- };
36
-
37
- export default useCentralStorage;
@@ -1,11 +0,0 @@
1
- import { createContext } from 'react';
2
-
3
- export interface PathContextProps {
4
- path: string;
5
- previousPath?: string;
6
- id?: string;
7
- pushState: (id: string) => void;
8
- replaceState: (id: string) => void;
9
- }
10
-
11
- export const PathContext = createContext<PathContextProps | undefined>(undefined);
@@ -1,66 +0,0 @@
1
- import React, { useCallback, useEffect, useMemo, useReducer } from 'react';
2
- import usePrevious from '../../hooks/usePrevious';
3
-
4
- import { PathContext, PathContextProps } from './PathContext';
5
- import reducer, { initialState, SET_PATH } from './reducer';
6
-
7
- const regexGuidAnyWhere =
8
- /(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}/g;
9
- const POP_STATE = 'popstate';
10
-
11
- interface PathProviderProps {
12
- children: React.ReactNode;
13
- }
14
-
15
- const PathProvider = ({ children }: PathProviderProps) => {
16
- const [state, dispatch] = useReducer(reducer, initialState);
17
- const previousPath = usePrevious(state.path);
18
-
19
- useEffect(() => {
20
- const onPopState = () => {
21
- dispatch({ type: SET_PATH, path: window.location.pathname });
22
- };
23
-
24
- window.addEventListener(POP_STATE, onPopState);
25
- return () => {
26
- window.removeEventListener(POP_STATE, onPopState);
27
- };
28
- }, []);
29
-
30
- const pushState = useCallback((path: string) => {
31
- const h1 = window.location.hash;
32
- history.pushState(null, '', `${path}`);
33
- const h2 = window.location.hash;
34
- if (h1.localeCompare(h2) !== 0) {
35
- window.dispatchEvent(new HashChangeEvent('hashchange'));
36
- }
37
- dispatch({ type: SET_PATH, path });
38
- }, []);
39
-
40
- const replaceState = useCallback((path: string) => {
41
- const h1 = window.location.hash;
42
- history.replaceState(null, '', path);
43
- const h2 = window.location.hash;
44
- if (h1.localeCompare(h2) !== 0) {
45
- window.dispatchEvent(new HashChangeEvent('hashchange'));
46
- }
47
- dispatch({ type: SET_PATH, path });
48
- }, []);
49
-
50
- const id = useMemo(() => state.path.match(regexGuidAnyWhere)?.pop(), [state.path]);
51
-
52
- const value: PathContextProps = useMemo(
53
- () => ({
54
- ...state,
55
- previousPath,
56
- id,
57
- pushState,
58
- replaceState,
59
- }),
60
- [state]
61
- );
62
-
63
- return <PathContext.Provider value={value}>{children}</PathContext.Provider>;
64
- };
65
-
66
- export default PathProvider;
@@ -1,30 +0,0 @@
1
- import { BaseAction } from '../../@types/action';
2
-
3
- export const SET_PATH = 'SET_PATH';
4
- type SET_PATH_TYPE = BaseAction<typeof SET_PATH> & {
5
- path: string;
6
- };
7
-
8
- type PathAction = SET_PATH_TYPE;
9
-
10
- interface PathState {
11
- path: string;
12
- }
13
-
14
- export const initialState: PathState = {
15
- path: window.location.pathname,
16
- };
17
-
18
- const pathReducer = (state: PathState, action: PathAction) => {
19
- const next = { ...state };
20
- switch (action.type) {
21
- case SET_PATH:
22
- next.path = action.path;
23
- return next;
24
-
25
- default:
26
- throw new Error(`Unsupported action type`);
27
- }
28
- };
29
-
30
- export default pathReducer;
@@ -1,13 +0,0 @@
1
- import { useContext } from 'react';
2
- import { PathContext, PathContextProps } from './PathContext';
3
-
4
- const usePath = (): PathContextProps => {
5
- const context = useContext(PathContext);
6
-
7
- if (!context) {
8
- throw new Error('usePath must be used within a PathProvider');
9
- }
10
-
11
- return context;
12
- };
13
- export default usePath;
@@ -1,18 +0,0 @@
1
- import { createContext } from 'react';
2
- import { Search } from '../../@types/search';
3
-
4
- export interface RelatedSearchContextProps {
5
- moreLikeThisUrl: boolean;
6
- loading: boolean;
7
- response?: Search;
8
- error: boolean;
9
- fetchRelated: (searchParmas: URLSearchParams) => void;
10
- }
11
-
12
- export const RelatedSearchContext = createContext<RelatedSearchContextProps>({
13
- moreLikeThisUrl: false,
14
- loading: false,
15
- error: false,
16
- response: undefined,
17
- fetchRelated: (_) => {},
18
- });
@@ -1,55 +0,0 @@
1
- import React, { useState, useCallback } from 'react';
2
-
3
- import { Search } from '../../@types/search';
4
- import { QueryFilter } from '../../@types/queryFilter';
5
- import useFetch from '../../hooks/useFetch';
6
- import { RelatedSearchContext } from './RelatedSearchContext';
7
-
8
- interface RelatedSearchProviderProps {
9
- url: string;
10
- urlMlt?: string;
11
- apiKey?: string;
12
- children: React.ReactNode;
13
- }
14
-
15
- const RelatedSearchProvider = ({ url, urlMlt, apiKey, children }: RelatedSearchProviderProps) => {
16
- const [queryFilter, setQueryFilter] = useState<QueryFilter>();
17
-
18
- const query = queryFilter?.searchParams.toString();
19
- const {
20
- loading,
21
- data: response,
22
- error,
23
- } = useFetch<Search>(
24
- `${urlMlt || url}${query ? `?${query}` : ''}`,
25
- {
26
- headers: apiKey
27
- ? {
28
- 'x-api-key': apiKey,
29
- }
30
- : {},
31
- },
32
- !queryFilter
33
- );
34
-
35
- const fetchRelated = useCallback(
36
- (searchParams: URLSearchParams) =>
37
- setQueryFilter({
38
- searchParams,
39
- }),
40
- []
41
- );
42
-
43
- const value = {
44
- moreLikeThisUrl: !!urlMlt,
45
- loading,
46
- error,
47
- response,
48
- queryFilter,
49
- fetchRelated,
50
- };
51
-
52
- return <RelatedSearchContext.Provider value={value}>{children}</RelatedSearchContext.Provider>;
53
- };
54
-
55
- export default RelatedSearchProvider;
@@ -1,20 +0,0 @@
1
- import { useContext, useEffect } from 'react';
2
-
3
- import { RelatedSearchContext } from './RelatedSearchContext';
4
-
5
- const useRelatedSearch = (id: string) => {
6
- const data = useContext(RelatedSearchContext);
7
-
8
- useEffect(() => {
9
- const searchParams = new URLSearchParams();
10
- searchParams.set('hits', '3');
11
- if (data.moreLikeThisUrl && id) {
12
- searchParams.set('id', id);
13
- }
14
- data.fetchRelated(searchParams);
15
- }, [id]);
16
-
17
- return data;
18
- };
19
-
20
- export default useRelatedSearch;
@@ -1,27 +0,0 @@
1
- import { createContext } from 'react';
2
- import { Facet, Document, Search } from '../../@types/search';
3
- import { QueryFilter } from '../../@types/queryFilter';
4
-
5
- export interface SearchContextProps {
6
- loading: boolean;
7
- response?: Search;
8
- error: boolean;
9
- documents?: Document[];
10
- initialFacets?: Facet[];
11
- queryFilter: QueryFilter;
12
- onFilterUpdate: (nextQuery: string) => void;
13
- onLoadMore: () => void;
14
- onInitialize: (initialQueryParams?: URLSearchParams) => void;
15
- }
16
-
17
- export const SearchContext = createContext<SearchContextProps>({
18
- loading: false,
19
- error: false,
20
- response: undefined,
21
- documents: undefined,
22
- initialFacets: undefined,
23
- queryFilter: { searchParams: new URLSearchParams() },
24
- onFilterUpdate: (_) => {},
25
- onLoadMore: () => {},
26
- onInitialize: (_) => {},
27
- });
@@ -1,243 +0,0 @@
1
- import React, { useState, useEffect, useCallback } from 'react';
2
-
3
- import { Facet, Document, Search } from '../../@types/search';
4
- import { QueryFilter } from '../../@types/queryFilter';
5
- import useFetch from '../../hooks/useFetch';
6
- import { SearchContext } from './SearchContext';
7
- import { getUrlSearchParamsFromUrl } from '../../utils/url';
8
- import { WaykePubSub } from '../../index';
9
- import { ActionOnFilterUpdate } from '../../utils/pubsub/Actions';
10
- import usePath from '../Path/usePath';
11
-
12
- interface SearchProviderProps {
13
- url: string;
14
- apiKey?: string;
15
- useQueryParamsFromUrl?: boolean;
16
- pathRoute?: string;
17
- children: React.ReactNode;
18
- }
19
-
20
- const initialSearchParams = new URLSearchParams();
21
- initialSearchParams.set('hits', '30');
22
- initialSearchParams.set('sort', 'published-desc');
23
-
24
- const SearchProvider = ({
25
- url,
26
- apiKey,
27
- useQueryParamsFromUrl,
28
- pathRoute,
29
- children,
30
- }: SearchProviderProps) => {
31
- const { replaceState, pushState } = usePath();
32
- const [queryFilter, setQueryFilter] = useState<QueryFilter>({
33
- searchParams: initialSearchParams,
34
- });
35
-
36
- const [initialFacets, setInitialFacets] = useState<Facet[]>();
37
- const [documents, setDocuments] = useState<Document[]>();
38
- const [initialize, setInitialize] = useState(false);
39
-
40
- const { data: initialDataRepsonse } = useFetch<Search>(
41
- `${url}?hits=0`,
42
- {
43
- headers: apiKey
44
- ? {
45
- 'x-api-key': apiKey,
46
- }
47
- : {},
48
- },
49
- !!initialFacets
50
- );
51
-
52
- const query = queryFilter.searchParams.toString();
53
- const {
54
- loading,
55
- data: response,
56
- error,
57
- } = useFetch<Search>(
58
- `${url}${query ? `?${query}` : ''}`,
59
- {
60
- headers: apiKey
61
- ? {
62
- 'x-api-key': apiKey,
63
- }
64
- : {},
65
- },
66
- !initialize || !!queryFilter?.block
67
- );
68
-
69
- const popStateEvent = (event: PopStateEvent) => {
70
- const { currentTarget } = event;
71
- if (currentTarget) {
72
- const nextSearchParams = new URLSearchParams((currentTarget as Window).location.search);
73
-
74
- if (!nextSearchParams.has('sort')) {
75
- nextSearchParams.set('sort', 'published-desc');
76
- }
77
-
78
- setQueryFilter({
79
- searchParams: nextSearchParams,
80
- });
81
- }
82
- };
83
-
84
- useEffect(() => {
85
- if (useQueryParamsFromUrl) {
86
- window.addEventListener('popstate', popStateEvent);
87
- }
88
-
89
- const onFilterUpdateEvent: ActionOnFilterUpdate = {
90
- actionName: 'onFilterUpdate',
91
- callback: onFilterUpdate,
92
- };
93
-
94
- WaykePubSub.subscribeAction(onFilterUpdateEvent);
95
- return () => {
96
- window.removeEventListener('popstate', popStateEvent);
97
- WaykePubSub.unsubscribeAction(onFilterUpdateEvent);
98
- };
99
- }, []);
100
-
101
- useEffect(() => {
102
- if (initialDataRepsonse) {
103
- setInitialFacets(initialDataRepsonse.facets);
104
- }
105
- }, [initialDataRepsonse]);
106
-
107
- useEffect(() => {
108
- if (useQueryParamsFromUrl) {
109
- const nextSearchParams = new URLSearchParams(queryFilter.searchParams);
110
- nextSearchParams.delete('hits');
111
- nextSearchParams.delete('offset');
112
- if (nextSearchParams.get('sort') === 'published-desc') {
113
- nextSearchParams.delete('sort');
114
- }
115
-
116
- const nextSearch = nextSearchParams.toString() ? `?${nextSearchParams}` : '';
117
- if (initialize) {
118
- if (window.location.search.localeCompare(nextSearch) !== 0) {
119
- const _path = pathRoute?.replace(/^\/|\/$/g, '');
120
- const prefix = _path ? `/${_path}/` : '/';
121
-
122
- const index = _path ? window.location.pathname.indexOf(prefix) : -1;
123
- let pathname = window.location.pathname;
124
- if (index > -1) {
125
- pathname = pathname.substr(0, index);
126
- }
127
-
128
- pushState(`${pathname}${nextSearch}`);
129
- }
130
- }
131
- }
132
- }, [queryFilter, initialize, useQueryParamsFromUrl]);
133
-
134
- useEffect(() => {
135
- if (response) {
136
- if (!initialFacets && !useQueryParamsFromUrl) {
137
- setInitialFacets(response.facets);
138
- }
139
-
140
- if (useQueryParamsFromUrl && response.query?.parameters) {
141
- const nextSearchParams = new URLSearchParams(response.query.parameters);
142
- nextSearchParams.delete('hits');
143
- nextSearchParams.delete('offset');
144
- const nextSearch = nextSearchParams.toString() ? `?${nextSearchParams}` : '';
145
- if (window.location.search.localeCompare(nextSearch) !== 0) {
146
- replaceState(`${window.location.pathname}${nextSearch}`);
147
- setQueryFilter({
148
- searchParams: new URLSearchParams(nextSearch),
149
- block: true,
150
- });
151
- }
152
- }
153
-
154
- if (queryFilter?.concatResult) {
155
- setDocuments([...(documents || []), ...(response.documentList.documents || [])]);
156
- } else {
157
- setDocuments(response.documentList.documents || []);
158
- }
159
- }
160
- }, [response, useQueryParamsFromUrl]);
161
-
162
- const onFilterUpdate = useCallback(
163
- (nextQuery: string) => {
164
- {
165
- if (!initialize) {
166
- setInitialize(true);
167
- }
168
-
169
- setQueryFilter({
170
- searchParams: new URLSearchParams(nextQuery),
171
- });
172
- }
173
- },
174
- [initialize]
175
- );
176
-
177
- const onLoadMore = useCallback(() => {
178
- if (response) {
179
- setQueryFilter({
180
- searchParams: new URLSearchParams(response?.documentList.pagination.nextPage?.query),
181
- concatResult: true,
182
- });
183
- }
184
- }, [response]);
185
-
186
- const onInitialize = useCallback(
187
- (_initialQueryParams?: URLSearchParams) => {
188
- if (!initialize) {
189
- const searchParamsFromUrl = getUrlSearchParamsFromUrl();
190
-
191
- const initialQueryParams = useQueryParamsFromUrl
192
- ? searchParamsFromUrl
193
- : _initialQueryParams;
194
-
195
- if (useQueryParamsFromUrl && _initialQueryParams) {
196
- _initialQueryParams.forEach((value, key) => {
197
- if (!initialQueryParams?.getAll(key)?.some((v) => v === value)) {
198
- initialQueryParams?.append(key, value);
199
- }
200
- });
201
- }
202
-
203
- if (initialQueryParams) {
204
- const nextSearchParams = new URLSearchParams(initialQueryParams);
205
- nextSearchParams.delete('hits');
206
- nextSearchParams.delete('offset');
207
-
208
- if (!initialQueryParams.has('hits')) {
209
- initialQueryParams.set('hits', '30');
210
- }
211
- if (!initialQueryParams.has('sort')) {
212
- initialQueryParams.set('sort', 'published-desc');
213
- }
214
-
215
- const nextSearch = nextSearchParams.toString() ? `?${nextSearchParams}` : '';
216
-
217
- setQueryFilter({
218
- searchParams: initialQueryParams,
219
- });
220
- replaceState(`${window.location.pathname}${nextSearch}`);
221
- }
222
- setInitialize(true);
223
- }
224
- },
225
- [initialize]
226
- );
227
-
228
- const value = {
229
- loading,
230
- error,
231
- response,
232
- documents,
233
- initialFacets,
234
- queryFilter,
235
- onFilterUpdate,
236
- onLoadMore,
237
- onInitialize,
238
- };
239
-
240
- return <SearchContext.Provider value={value}>{children}</SearchContext.Provider>;
241
- };
242
-
243
- export default SearchProvider;
@@ -1,6 +0,0 @@
1
- import { useContext } from 'react';
2
- import { SearchContext } from './SearchContext';
3
-
4
- const useSearch = () => useContext(SearchContext);
5
-
6
- export default useSearch;
@@ -1,15 +0,0 @@
1
- import { createContext } from 'react';
2
-
3
- export interface SettingsContextProps {
4
- googleMapsApiKey?: string;
5
- googleMapsMarker?: string;
6
- ecomSettings?: {
7
- url: string;
8
- useBankId?: boolean;
9
- displayBankIdAlert?: boolean;
10
- serviceLogotypeUrl?: string;
11
- bankIdThumbprint?: string;
12
- };
13
- }
14
-
15
- export const SettingsContext = createContext<SettingsContextProps>({});
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import { SettingsContext } from './SettingsContext';
3
- import { EcomSettings } from '../../providers/WaykeProvider';
4
-
5
- interface SettingsProps {
6
- ecomSettings?: EcomSettings;
7
- googleMapsApiKey?: string;
8
- googleMapsMarker?: string;
9
- children: React.ReactNode;
10
- }
11
-
12
- const SettingsProvider = ({
13
- googleMapsApiKey,
14
- googleMapsMarker,
15
- ecomSettings,
16
- children,
17
- }: SettingsProps) => (
18
- <SettingsContext.Provider value={{ ecomSettings, googleMapsApiKey, googleMapsMarker }}>
19
- {children}
20
- </SettingsContext.Provider>
21
- );
22
-
23
- export default SettingsProvider;
@@ -1,7 +0,0 @@
1
- import { useContext } from 'react';
2
-
3
- import { SettingsContext } from './SettingsContext';
4
-
5
- const useSettings = () => useContext(SettingsContext);
6
-
7
- export default useSettings;