ublo-lib 1.17.8 → 1.18.0

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/es/esf/components/{instructors-book-v2 → instructors-book}/api.js +12 -8
  2. package/es/esf/components/{instructors-book-v2 → instructors-book}/book.js +1 -1
  3. package/es/esf/components/{instructors-book-v2 → instructors-book}/filters.js +2 -2
  4. package/es/esf/components/instructors-book/index.js +6 -3
  5. package/es/esf/components/{instructors-book-v2 → instructors-book}/instructor.js +6 -6
  6. package/es/esf/components/instructors-book/list.js +39 -170
  7. package/es/esf/components/instructors-book/messages.js +36 -37
  8. package/es/esf/components/{instructors-book-v2 → instructors-book}/sheet.js +17 -17
  9. package/es/esf/components/instructors-book/utils.js +48 -2
  10. package/package.json +1 -1
  11. package/es/esf/components/instructor-suggestions/fetcher.js +0 -16
  12. package/es/esf/components/instructor-suggestions/icons.js +0 -266
  13. package/es/esf/components/instructor-suggestions/index.js +0 -2
  14. package/es/esf/components/instructor-suggestions/instructor-suggestions.js +0 -180
  15. package/es/esf/components/instructor-suggestions/loader.js +0 -8
  16. package/es/esf/components/instructor-suggestions/messages.js +0 -16
  17. package/es/esf/components/instructors-book/container.js +0 -18
  18. package/es/esf/components/instructors-book/details.js +0 -117
  19. package/es/esf/components/instructors-book/icons.js +0 -266
  20. package/es/esf/components/instructors-book/inner.js +0 -15
  21. package/es/esf/components/instructors-book/instructors-book.js +0 -111
  22. package/es/esf/components/instructors-book/link.js +0 -17
  23. package/es/esf/components/instructors-book/list-utils.js +0 -18
  24. package/es/esf/components/instructors-book/loader.js +0 -8
  25. package/es/esf/components/instructors-book-v2/index.js +0 -6
  26. package/es/esf/components/instructors-book-v2/list.js +0 -47
  27. package/es/esf/components/instructors-book-v2/messages.js +0 -41
  28. package/es/esf/components/instructors-book-v2/utils.js +0 -51
  29. /package/es/esf/components/{instructors-book-v2 → instructors-book}/book.module.css +0 -0
  30. /package/es/esf/components/{instructors-book-v2 → instructors-book}/filters.module.css +0 -0
  31. /package/es/esf/components/{instructors-book-v2 → instructors-book}/flags.js +0 -0
  32. /package/es/esf/components/{instructors-book-v2 → instructors-book}/instructor.module.css +0 -0
  33. /package/es/esf/components/{instructors-book-v2 → instructors-book}/list.module.css +0 -0
  34. /package/es/esf/components/{instructors-book-v2 → instructors-book}/prefixes.js +0 -0
  35. /package/es/esf/components/{instructors-book-v2 → instructors-book}/sheet.module.css +0 -0
  36. /package/es/esf/components/{instructors-book-v2 → instructors-book}/suggestions.js +0 -0
  37. /package/es/esf/components/{instructors-book-v2 → instructors-book}/suggestions.module.css +0 -0
@@ -1,266 +0,0 @@
1
- import * as React from "react";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { jsxs as _jsxs } from "react/jsx-runtime";
4
- const SvgIcon = ({
5
- title,
6
- ...props
7
- }) => _jsxs("svg", {
8
- viewBox: "0 0 24 24",
9
- ...props,
10
- children: [title && _jsx("title", {
11
- children: title
12
- }), props.children]
13
- });
14
- export const PersonIcon = props => _jsx(SvgIcon, {
15
- ...props,
16
- children: _jsx("path", {
17
- d: "M12 4c2.7614 0 5 2.23858 5 5 0 2.7614-2.2386 5-5 5-2.76142 0-5-2.2386-5-5 0-2.76142 2.23858-5 5-5m0 12.5c5.525 0 10 2.2375 10 5V24H2v-2.5c0-2.7625 4.475-5 10-5z"
18
- })
19
- });
20
- export const OverlayIcon = props => _jsx(SvgIcon, {
21
- ...props,
22
- children: _jsx("path", {
23
- d: "M15.5 14h-.8l-.3-.3c1-1.1 1.6-2.6 1.6-4.2a6.5 6.5 0 10-2.3 5l.3.2v.8l5 5 1.5-1.5-5-5zm-6 0a4.5 4.5 0 110-9 4.5 4.5 0 010 9z"
24
- })
25
- });
26
- export const BackIcon = props => _jsx(SvgIcon, {
27
- ...props,
28
- children: _jsx("path", {
29
- d: "M15.41 16.59L10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41z"
30
- })
31
- });
32
- const ArFlag = props => _jsxs(SvgIcon, {
33
- ...props,
34
- children: [_jsx("path", {
35
- d: "M0 3h24v6H0V3z",
36
- fill: "#000"
37
- }), _jsx("path", {
38
- d: "M0 9h24v6H0V9z",
39
- fill: "#fff"
40
- }), _jsx("path", {
41
- d: "M0 15h24v6H0v-6z",
42
- fill: "#00732F"
43
- })]
44
- });
45
- const CnFlag = props => _jsxs(SvgIcon, {
46
- ...props,
47
- children: [_jsx("path", {
48
- d: "M0 3h24v18H0V3z",
49
- fill: "#DE2910"
50
- }), _jsx("path", {
51
- d: "M2.91 9.69L4.5 4.8l1.59 4.89-4.16-3.03h5.14L2.91 9.7zM9.9 4.88l-1.66.38 1.12-1.29-.15 1.7-.88-1.46 1.58.67zM11.6 7.01l-1.7-.3 1.55-.74-.8 1.51-.25-1.7 1.2 1.23zM11.35 10.01l-1.42-.96L11.64 9l-1.35 1.06.48-1.65.58 1.61zM9.24 11.97l-.95-1.43 1.6.6-1.65.46 1.08-1.34-.08 1.71z",
52
- fill: "#FFDE00"
53
- })]
54
- });
55
- const DeFlag = props => _jsxs(SvgIcon, {
56
- ...props,
57
- children: [_jsx("path", {
58
- d: "M0 15h24v6H0v-6z",
59
- fill: "#FFCE00"
60
- }), _jsx("path", {
61
- d: "M0 3h24v6H0V3z",
62
- fill: "#000"
63
- }), _jsx("path", {
64
- d: "M0 9h24v6H0V9z",
65
- fill: "#D00"
66
- })]
67
- });
68
- const DkFlag = props => _jsxs(SvgIcon, {
69
- ...props,
70
- children: [_jsx("path", {
71
- d: "M0 3h24v18H0V3z",
72
- fill: "#C60C30"
73
- }), _jsx("path", {
74
- d: "M7.7 3h2.6v18H7.7V3z",
75
- fill: "#fff"
76
- }), _jsx("path", {
77
- d: "M0 10.7h24v2.6H0v-2.6z",
78
- fill: "#fff"
79
- })]
80
- });
81
- const EsFlag = props => _jsxs(SvgIcon, {
82
- ...props,
83
- children: [_jsx("path", {
84
- d: "M0 3h24v18H0V3z",
85
- fill: "#C60B1E"
86
- }), _jsx("path", {
87
- d: "M0 7.5h24v9H0v-9z",
88
- fill: "#FFC400"
89
- })]
90
- });
91
- const FrFlag = props => _jsxs(SvgIcon, {
92
- ...props,
93
- children: [_jsx("path", {
94
- fillRule: "evenodd",
95
- clipRule: "evenodd",
96
- d: "M0 3h24v18H0V3z",
97
- fill: "#fff"
98
- }), _jsx("path", {
99
- fillRule: "evenodd",
100
- clipRule: "evenodd",
101
- d: "M0 3h8v18H0V3z",
102
- fill: "#00267F"
103
- }), _jsx("path", {
104
- fillRule: "evenodd",
105
- clipRule: "evenodd",
106
- d: "M16 3h8v18h-8V3z",
107
- fill: "#F31830"
108
- })]
109
- });
110
- const EnFlag = props => _jsxs(SvgIcon, {
111
- ...props,
112
- children: [_jsx("path", {
113
- d: "M-6 3h36v18H-6V3z",
114
- fill: "#006"
115
- }), _jsx("path", {
116
- d: "M-6 3v2l32 16h4v-2L-2 3h-4zm36 0v2L-2 21h-4v-2L26 3h4z",
117
- fill: "#fff"
118
- }), _jsx("path", {
119
- d: "M9 3v18h6V3H9zM-6 9v6h36V9H-6z",
120
- fill: "#fff"
121
- }), _jsx("path", {
122
- d: "M-6 10.2v3.6h36v-3.6H-6zM10.2 3v18h3.6V3h-3.6zM-7 21l11-6h3l-11 6h-3zm1-18.5L7 9H4.5L-6 4V2.5zM16.5 9l12-6H31L19 9h-2.5zM30 21.5L17 15h3l10 5v1.5z",
123
- fill: "#C00"
124
- })]
125
- });
126
- const IlFlag = props => _jsxs(SvgIcon, {
127
- ...props,
128
- children: [_jsx("path", {
129
- d: "M25 21H-1V3H25v18z",
130
- fill: "#fff"
131
- }), _jsx("path", {
132
- d: "M25 7H-1V4.8H25V7zm0 12.4H-1V17H25v2.4zM7.8 9.7l3.9 6.8 4-6.7h-8z",
133
- fill: "#00C"
134
- }), _jsx("path", {
135
- d: "M11 14.2l.8 1.3.7-1.3H11z",
136
- fill: "#fff"
137
- }), _jsx("path", {
138
- d: "M7.9 14.3l3.9-6.8 4 6.8h-8z",
139
- fill: "#00C"
140
- }), _jsx("path", {
141
- d: "M11 9.8l.8-1.3.7 1.2H11zm-1.5 2.8l-.8 1.2h1.5l-.7-1.2zm-.8-2.4h1.5l-.7 1.3-.8-1.3zm5.4 2.4l.7 1.2h-1.5l.8-1.2zm.7-2.4h-1.5l.7 1.3.8-1.3zm-4 0l-1 1.8 1 1.8h1.8l1.2-1.8-1-1.8h-2z",
142
- fill: "#fff"
143
- })]
144
- });
145
- const ItFlag = props => _jsxs(SvgIcon, {
146
- ...props,
147
- children: [_jsx("path", {
148
- fillRule: "evenodd",
149
- clipRule: "evenodd",
150
- d: "M0 3h24v18H0V3z",
151
- fill: "#fff"
152
- }), _jsx("path", {
153
- fillRule: "evenodd",
154
- clipRule: "evenodd",
155
- d: "M0 3h8v18H0V3z",
156
- fill: "#009246"
157
- }), _jsx("path", {
158
- fillRule: "evenodd",
159
- clipRule: "evenodd",
160
- d: "M16 3h8v18h-8V3z",
161
- fill: "#CE2B37"
162
- })]
163
- });
164
- const JpFlag = props => _jsxs(SvgIcon, {
165
- ...props,
166
- children: [_jsx("path", {
167
- fillRule: "evenodd",
168
- clipRule: "evenodd",
169
- d: "M-1.5 3h27v18h-27V3z",
170
- fill: "#fff"
171
- }), _jsx("path", {
172
- d: "M12 17.6a5.6 5.6 0 100-11.2 5.6 5.6 0 000 11.2z",
173
- fill: "#D30000"
174
- })]
175
- });
176
- const NlFlag = props => _jsxs(SvgIcon, {
177
- ...props,
178
- children: [_jsx("path", {
179
- d: "M24 3H0v18h24V3z",
180
- fill: "#fff"
181
- }), _jsx("path", {
182
- d: "M24 15H0v6h24v-6z",
183
- fill: "#21468B"
184
- }), _jsx("path", {
185
- fillRule: "evenodd",
186
- clipRule: "evenodd",
187
- d: "M0 3h24v6H0V3z",
188
- fill: "#AE1C28"
189
- })]
190
- });
191
- const PlFlag = props => _jsxs(SvgIcon, {
192
- ...props,
193
- children: [_jsx("path", {
194
- fillRule: "evenodd",
195
- clipRule: "evenodd",
196
- d: "M24 21H0V3h24v18z",
197
- fill: "#fff"
198
- }), _jsx("path", {
199
- fillRule: "evenodd",
200
- clipRule: "evenodd",
201
- d: "M24 21H0v-9h24v9z",
202
- fill: "#DC143C"
203
- })]
204
- });
205
- const PtFlag = props => _jsxs(SvgIcon, {
206
- ...props,
207
- children: [_jsx("path", {
208
- d: "M9.6 3H24v18H9.6V3z",
209
- fill: "red"
210
- }), _jsx("path", {
211
- d: "M0 3h9.6v18H0V3z",
212
- fill: "#060"
213
- })]
214
- });
215
- const RuFlag = props => _jsxs(SvgIcon, {
216
- ...props,
217
- children: [_jsx("path", {
218
- fillRule: "evenodd",
219
- clipRule: "evenodd",
220
- d: "M0 3h24v18H0V3z",
221
- fill: "#fff"
222
- }), _jsx("path", {
223
- fillRule: "evenodd",
224
- clipRule: "evenodd",
225
- d: "M0 9h24v12H0V9z",
226
- fill: "#0039A6"
227
- }), _jsx("path", {
228
- fillRule: "evenodd",
229
- clipRule: "evenodd",
230
- d: "M0 15h24v6H0v-6z",
231
- fill: "#D52B1E"
232
- })]
233
- });
234
- const SeFlag = props => _jsxs(SvgIcon, {
235
- ...props,
236
- children: [_jsx("path", {
237
- d: "M-2.4 3h9v7.2h-9V3zm0 10.8h9V21h-9v-7.2z",
238
- fill: "#006AA7"
239
- }), _jsx("path", {
240
- d: "M-2.4 10.2h9v3.6h-9v-3.6zM6.6 3h3.6v18H6.6V3z",
241
- fill: "#FECC00"
242
- }), _jsx("path", {
243
- d: "M10 10.2h16.3v3.6H10v-3.6z",
244
- fill: "#FECC00"
245
- }), _jsx("path", {
246
- d: "M10.2 13.8h16.2V21H10.2v-7.2zm0-10.8h16.2v7.2H10.2V3z",
247
- fill: "#006AA7"
248
- })]
249
- });
250
- export const flags = {
251
- ar: ArFlag,
252
- cn: CnFlag,
253
- de: DeFlag,
254
- dk: DkFlag,
255
- en: EnFlag,
256
- es: EsFlag,
257
- fr: FrFlag,
258
- il: IlFlag,
259
- it: ItFlag,
260
- jp: JpFlag,
261
- nl: NlFlag,
262
- pl: PlFlag,
263
- pt: PtFlag,
264
- ru: RuFlag,
265
- se: SeFlag
266
- };
@@ -1,15 +0,0 @@
1
- import * as React from "react";
2
- import List from "./list";
3
- import Details from "./details";
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- const Inner = props => {
6
- return _jsx("div", {
7
- className: "instructors-book",
8
- children: props.instructor ? _jsx(Details, {
9
- ...props
10
- }) : props.instructors ? _jsx(List, {
11
- ...props
12
- }) : "No data"
13
- });
14
- };
15
- export default Inner;
@@ -1,111 +0,0 @@
1
- import * as React from "react";
2
- import { memo, useEffect, useState } from "react";
3
- import { useUbloContext } from "ublo/with-ublo";
4
- import Inner from "./inner";
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- const host = "https://instructors-book-server.carnet-rouge-esf.com";
7
- const fetcher = async (url, school, body) => {
8
- const res = await fetch(url, {
9
- method: "POST",
10
- headers: {
11
- "content-type": "application/json;charset=utf-8",
12
- Authorization: "00q2qa545018261l252gg3414t3qa2",
13
- schoolcode: school
14
- },
15
- body: body ? JSON.stringify(body) : undefined
16
- });
17
- return res.json();
18
- };
19
- export const fetchInstructorsContext = (school, lang, body = {}) => fetcher(`${host}/api/instructors-book/${school}/${lang}`, school, {
20
- ...body,
21
- project: true
22
- });
23
- export const fetchInstructor = (school, lang, uri) => fetcher(`${host}/api/instructors-book/${school}/${lang}/${uri}`, school);
24
- const propsFromQueryString = () => {
25
- if (typeof window === "undefined") return {};
26
- const params = new URLSearchParams(document.location.search);
27
- const activity = params.get("activity") || undefined;
28
- const language = params.get("language") || undefined;
29
- return {
30
- activity,
31
- language
32
- };
33
- };
34
- const hasTrailingSlash = path => path.length > 1 && path.endsWith("/");
35
- const InstructorsBook = ({
36
- instructorsContext,
37
- instructor,
38
- trombi
39
- }) => {
40
- const {
41
- lang,
42
- path,
43
- config
44
- } = useUbloContext();
45
- const {
46
- resort
47
- } = config;
48
- const [instructorsCtx, setInstructorsCtx] = useState(instructorsContext);
49
- const [activity, setActivity] = useState();
50
- const [language, setLanguage] = useState();
51
- const fetchNewContext = React.useCallback(async (activity, language) => {
52
- const newContext = await fetchInstructorsContext(resort, lang, {
53
- activity,
54
- language
55
- });
56
- setInstructorsCtx(newContext);
57
- }, [lang, resort]);
58
- useEffect(() => {
59
- const {
60
- activity,
61
- language
62
- } = propsFromQueryString();
63
- if (activity) {
64
- window.sessionStorage.activity = activity;
65
- }
66
- if (language) {
67
- window.sessionStorage.language = language;
68
- }
69
- setActivity(window.sessionStorage.activity);
70
- setLanguage(window.sessionStorage.language);
71
- if ((window.sessionStorage.activity || window.sessionStorage.language) && !instructor) {
72
- fetchNewContext(window.sessionStorage.activity, window.sessionStorage.language);
73
- }
74
- }, [fetchNewContext, instructor]);
75
- const selectInstructor = uri => {
76
- return {
77
- href: path.concat(hasTrailingSlash(path) ? "" : "/").concat(uri)
78
- };
79
- };
80
- const backToList = uri => {
81
- return {
82
- href: path.replace(`/${uri}`, "")
83
- };
84
- };
85
- const selectFilter = async (filter, value) => {
86
- window.sessionStorage[filter] = value;
87
- if (filter === "activity") {
88
- setActivity(value);
89
- await fetchNewContext(value, language);
90
- } else {
91
- setLanguage(value);
92
- await fetchNewContext(activity, value);
93
- }
94
- };
95
- const dataProps = instructorsCtx !== undefined ? {
96
- ...instructorsCtx
97
- } : {
98
- instructor
99
- };
100
- return _jsx(Inner, {
101
- ...dataProps,
102
- lang: lang,
103
- selectInstructor: selectInstructor,
104
- selectFilter: selectFilter,
105
- backToList: backToList,
106
- activity: activity,
107
- language: language,
108
- trombi: trombi
109
- });
110
- };
111
- export default memo(InstructorsBook);
@@ -1,17 +0,0 @@
1
- import * as React from "react";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- const Link = ({
4
- Link,
5
- linkProps,
6
- children,
7
- ...props
8
- }) => {
9
- return Link !== undefined ? _jsx(Link, {
10
- ...linkProps,
11
- children: children
12
- }) : _jsx("a", {
13
- ...props,
14
- children: children
15
- });
16
- };
17
- export default Link;
@@ -1,18 +0,0 @@
1
- const strStartWith = (str1, str2) => str1.toLowerCase().trim().startsWith(str2.toLowerCase().trim());
2
- const strEquals = (str1, str2) => str1.toLowerCase().trim() === str2.toLowerCase().trim();
3
- const match = (searchingArray, entries) => {
4
- return searchingArray.reduce((acc, str, index) => {
5
- const matched = index === searchingArray.length - 1 ? strStartWith : strEquals;
6
- return acc && entries.some(entry => matched(entry, str));
7
- }, true);
8
- };
9
- export const filter = (project, search = "") => {
10
- const searchingArray = search.split(" ");
11
- const filtered = project.all.filter(uri => {
12
- const instructor = project.byUri[uri];
13
- const firstnameWords = instructor.firstname.split(" ");
14
- const lastnameWords = instructor.lastname.split(" ");
15
- return match(searchingArray, [...firstnameWords, ...lastnameWords]);
16
- });
17
- return filtered.reduce((acc, uri) => [...acc, project.byUri[uri]], []);
18
- };
@@ -1,8 +0,0 @@
1
- import * as React from "react";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- const Loader = () => {
4
- return _jsx("div", {
5
- className: "instructors-book-loader"
6
- });
7
- };
8
- export default Loader;
@@ -1,6 +0,0 @@
1
- import * as API from "./api";
2
- import Book from "./book";
3
- import Sheet from "./sheet";
4
- import Suggestions from "./suggestions";
5
- import prefixes from "./prefixes";
6
- export { Book, Sheet, Suggestions, API, prefixes };
@@ -1,47 +0,0 @@
1
- import * as React from "react";
2
- import classNames from "classnames";
3
- import { useUbloContext } from "ublo/with-ublo";
4
- import * as Utils from "./utils";
5
- import Instructor from "./instructor";
6
- import { message } from "./messages";
7
- import css from "./list.module.css";
8
- import { jsx as _jsx } from "react/jsx-runtime";
9
- import { jsxs as _jsxs } from "react/jsx-runtime";
10
- export default function List({
11
- search = "",
12
- instructors,
13
- fromSuggestions,
14
- formSendFunction,
15
- formFields,
16
- trombi,
17
- popup
18
- }) {
19
- const {
20
- lang
21
- } = useUbloContext();
22
- const displayedInstructors = fromSuggestions ? instructors : Utils.filter(instructors, search);
23
- const listCountMessageCode = displayedInstructors?.length > 1 ? "instructors" : "instructor";
24
- const classes = classNames(css.container, {
25
- [css.containerSuggestions]: fromSuggestions
26
- });
27
- return _jsxs("div", {
28
- className: classes,
29
- children: [!fromSuggestions && _jsxs("div", {
30
- className: css.listCount,
31
- children: [_jsx("b", {
32
- children: displayedInstructors.length
33
- }), " ", message(lang, listCountMessageCode)]
34
- }), _jsx("div", {
35
- className: css.inner,
36
- children: displayedInstructors?.map(instructor => {
37
- return _jsx(Instructor, {
38
- instructor: instructor,
39
- trombi: trombi,
40
- formFields: formFields,
41
- formSendFunction: formSendFunction,
42
- popup: popup
43
- }, instructor.uri);
44
- })
45
- })]
46
- });
47
- }
@@ -1,41 +0,0 @@
1
- const locales = {
2
- fr: {
3
- "search-label": "Chercher un moniteur",
4
- "search-placeholder": "Nom, prénom...",
5
- "activity-label": "Quelle pratique ?",
6
- "language-label": "Quelle langue ?",
7
- instructors: "moniteurs trouvés",
8
- instructor: "moniteur trouvé",
9
- activities: "Activités pratiquées",
10
- and: "et",
11
- languages: "Langues parlées",
12
- about: "À propos",
13
- contact: "Quand souhaitez-vous skier avec moi ?",
14
- "suggestions-title": "Les moniteurs qui vous proposent ce cours",
15
- "suggestions-button": "Voir tous les moniteurs",
16
- "see-more": "Voir plus",
17
- "go-back": "Retour"
18
- },
19
- en: {
20
- "search-label": "Search an instructor",
21
- "search-placeholder": "Lastname, firstname...",
22
- "activity-label": "Which activity?",
23
- "language-label": "Which language?",
24
- instructors: "instructors found",
25
- instructor: "instructor found",
26
- activities: "Activities",
27
- and: "and",
28
- languages: "Spoken languages",
29
- about: "About",
30
- contact: "When would you like to ski with me?",
31
- "suggestions-title": "The instructors who offer you this course",
32
- "suggestions-button": "See all instructors",
33
- "see-more": "See more",
34
- "go-back": "Go back"
35
- }
36
- };
37
- export const message = (lang, id) => {
38
- const locale = lang === "fr" ? "fr" : "en";
39
- const messages = locales[locale];
40
- return messages[id] || `??${id}??`;
41
- };
@@ -1,51 +0,0 @@
1
- const SLASH = "/";
2
- export function truncate(input, lenght = 140) {
3
- return input.length > lenght ? `${input.substring(0, lenght)}...` : input;
4
- }
5
- export function sanitizeHTML(text) {
6
- const element = document.createElement("div");
7
- element.innerHTML = text;
8
- return element.textContent;
9
- }
10
- export function propsFromQueryString() {
11
- if (typeof window === "undefined") return {};
12
- const params = new URLSearchParams(document.location.search);
13
- const activity = params.get("activity") || undefined;
14
- const language = params.get("language") || undefined;
15
- return {
16
- activity,
17
- language
18
- };
19
- }
20
- export function hasTrailingSlash(path) {
21
- return path.length > 1 && path.endsWith(SLASH);
22
- }
23
- export const formatNames = name => {
24
- const lowercasedName = name && name.toLowerCase();
25
- return lowercasedName ? lowercasedName.charAt(0).toUpperCase() + lowercasedName.slice(1) : "";
26
- };
27
- export function includesString(source, included) {
28
- source.toLowerCase().includes(included.toLowerCase());
29
- }
30
- function strStartWith(str1, str2) {
31
- return str1.toLowerCase().trim().startsWith(str2.toLowerCase().trim());
32
- }
33
- function strEquals(str1, str2) {
34
- return str1.toLowerCase().trim() === str2.toLowerCase().trim();
35
- }
36
- function match(searchingArray, entries) {
37
- return searchingArray.reduce((acc, str, index) => {
38
- const matched = index === searchingArray.length - 1 ? strStartWith : strEquals;
39
- return acc && entries.some(entry => matched(entry, str));
40
- }, true);
41
- }
42
- export function filter(array, search = "") {
43
- const searchingArray = search.split(" ");
44
- const filtered = array.all.filter(uri => {
45
- const instructor = array.byUri[uri];
46
- const firstnameWords = instructor.firstname.split(" ");
47
- const lastnameWords = instructor.lastname.split(" ");
48
- return match(searchingArray, [...firstnameWords, ...lastnameWords]);
49
- });
50
- return filtered.reduce((acc, uri) => [...acc, array.byUri[uri]], []);
51
- }