@streamlayer/react 0.2.1 → 0.2.5
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/main.js +2865 -0
- package/package.json +17 -11
- package/README.md +0 -6
- package/src/app/app.d.ts +0 -2
- package/src/app/app.js +0 -18
- package/src/app/app.js.map +0 -1
- package/src/app/provider.d.ts +0 -19
- package/src/app/provider.js +0 -26
- package/src/app/provider.js.map +0 -1
- package/src/app/useStreamLayer.d.ts +0 -7
- package/src/app/useStreamLayer.js +0 -39
- package/src/app/useStreamLayer.js.map +0 -1
- package/src/environments/environment.d.ts +0 -3
- package/src/environments/environment.js +0 -6
- package/src/environments/environment.js.map +0 -1
- package/src/environments/environment.prod.d.ts +0 -3
- package/src/environments/environment.prod.js +0 -4
- package/src/environments/environment.prod.js.map +0 -1
- package/src/main.d.ts +0 -3
- package/src/main.js +0 -4
- package/src/main.js.map +0 -1
package/main.js
ADDED
|
@@ -0,0 +1,2865 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// packages/react-ui/src/lib/gamification/inapp/index.tsx
|
|
8
|
+
import { useCallback } from "react";
|
|
9
|
+
|
|
10
|
+
// packages/react-ui/src/assets/icons/icon-exit.svg
|
|
11
|
+
import * as React from "react";
|
|
12
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
13
|
+
var SvgIconExit = (props) => /* @__PURE__ */ jsxs("svg", { width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: [
|
|
14
|
+
/* @__PURE__ */ jsx("rect", { width: 24, height: 24, rx: 12, fill: "white", fillOpacity: 0.1 }),
|
|
15
|
+
/* @__PURE__ */ jsx("rect", { x: 8.25, y: 7, width: 12.3744, height: 1.76777, rx: 0.883884, transform: "rotate(45 8.25 7)", fill: "white" }),
|
|
16
|
+
/* @__PURE__ */ jsx("rect", { x: 7, y: 15.75, width: 12.3744, height: 1.76777, rx: 0.883884, transform: "rotate(-45 7 15.75)", fill: "white" })
|
|
17
|
+
] });
|
|
18
|
+
var icon_exit_default = SvgIconExit;
|
|
19
|
+
|
|
20
|
+
// packages/react-ui/src/lib/gamification/inapp/styles.tsx
|
|
21
|
+
import styled from "@emotion/styled";
|
|
22
|
+
var Container = styled.div`
|
|
23
|
+
box-sizing: border-box;
|
|
24
|
+
border: ${(props) => `1px solid ${props.theme.COLORS.BLUE_PRIMARY}`};
|
|
25
|
+
border-radius: 13px;
|
|
26
|
+
background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT};
|
|
27
|
+
color: ${(props) => props.theme.COLORS.WHITE};
|
|
28
|
+
display: flex;
|
|
29
|
+
user-select: none;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
overflow: hidden;
|
|
32
|
+
animation: slidein 0.3s ease-in;
|
|
33
|
+
|
|
34
|
+
@keyframes slidein {
|
|
35
|
+
from {
|
|
36
|
+
transform: translateX(-100%);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
to {
|
|
40
|
+
transform: translateX(0);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
var IconWrap = styled.div`
|
|
45
|
+
display: flex;
|
|
46
|
+
justify-content: center;
|
|
47
|
+
align-items: center;
|
|
48
|
+
padding: 14px;
|
|
49
|
+
background-color: ${(props) => props.theme.COLORS.BLUE_PRIMARY};
|
|
50
|
+
`;
|
|
51
|
+
var Icon = styled.img`
|
|
52
|
+
max-width: 40px;
|
|
53
|
+
max-height: 40px;
|
|
54
|
+
width: 100%;
|
|
55
|
+
height: 100%;
|
|
56
|
+
border-radius: 50%;
|
|
57
|
+
`;
|
|
58
|
+
var Content = styled.div`
|
|
59
|
+
display: flex;
|
|
60
|
+
justify-content: space-between;
|
|
61
|
+
width: 100%;
|
|
62
|
+
align-items: center;
|
|
63
|
+
`;
|
|
64
|
+
var TitleWrap = styled.div`
|
|
65
|
+
padding-left: 20px;
|
|
66
|
+
padding-right: 5px;
|
|
67
|
+
font-weight: 700;
|
|
68
|
+
font-size: 14px;
|
|
69
|
+
flex: 1;
|
|
70
|
+
`;
|
|
71
|
+
var Title = styled.div`
|
|
72
|
+
display: -webkit-box;
|
|
73
|
+
-webkit-box-orient: vertical;
|
|
74
|
+
-webkit-line-clamp: 2;
|
|
75
|
+
overflow: hidden;
|
|
76
|
+
text-overflow: ellipsis;
|
|
77
|
+
`;
|
|
78
|
+
var CloseBtnWrap = styled.div`
|
|
79
|
+
padding: 20px;
|
|
80
|
+
`;
|
|
81
|
+
var CloseBtn = styled.button`
|
|
82
|
+
border: none;
|
|
83
|
+
outline: none;
|
|
84
|
+
background-color: transparent;
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
display: flex;
|
|
87
|
+
justify-content: center;
|
|
88
|
+
align-items: center;
|
|
89
|
+
`;
|
|
90
|
+
var CloseIcon = styled.img`
|
|
91
|
+
width: 24px;
|
|
92
|
+
height: 24px;
|
|
93
|
+
`;
|
|
94
|
+
|
|
95
|
+
// packages/react-ui/src/lib/gamification/inapp/index.tsx
|
|
96
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "@emotion/react/jsx-runtime";
|
|
97
|
+
var InApp = ({ title = "", icon, color, openVoiting, closeInApp }) => {
|
|
98
|
+
const _closeInApp = useCallback(
|
|
99
|
+
(e) => {
|
|
100
|
+
e.stopPropagation();
|
|
101
|
+
closeInApp();
|
|
102
|
+
},
|
|
103
|
+
[closeInApp]
|
|
104
|
+
);
|
|
105
|
+
return /* @__PURE__ */ jsxs2(Container, { onClick: openVoiting, children: [
|
|
106
|
+
/* @__PURE__ */ jsx2(IconWrap, { style: color ? { backgroundColor: color } : {}, children: !!icon && /* @__PURE__ */ jsx2(Icon, { alt: "in-app-icon", src: icon }) }),
|
|
107
|
+
/* @__PURE__ */ jsxs2(Content, { children: [
|
|
108
|
+
/* @__PURE__ */ jsx2(TitleWrap, { children: /* @__PURE__ */ jsx2(Title, { id: "in-app-title", children: title }) }),
|
|
109
|
+
/* @__PURE__ */ jsx2(CloseBtnWrap, { children: /* @__PURE__ */ jsx2(CloseBtn, { onClick: _closeInApp, children: /* @__PURE__ */ jsx2(CloseIcon, { alt: "close-in-app-icon", src: icon_exit_default }) }) })
|
|
110
|
+
] })
|
|
111
|
+
] });
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// packages/react-ui/src/lib/gamification/login/index.tsx
|
|
115
|
+
import { useState } from "react";
|
|
116
|
+
import PhoneInput, { isValidPhoneNumber, formatPhoneNumberIntl } from "react-phone-number-input";
|
|
117
|
+
import "react-phone-number-input/style.css";
|
|
118
|
+
import useDigitInput from "react-digit-input";
|
|
119
|
+
|
|
120
|
+
// packages/react-ui/src/utils/login.ts
|
|
121
|
+
import { createGrpcWebTransport } from "@bufbuild/connect-web";
|
|
122
|
+
import { createPromiseClient } from "@connectrpc/connect";
|
|
123
|
+
import { Users } from "@streamlayer/sl-eslib/users/users_connect";
|
|
124
|
+
var requestLoginCode = async (phone) => {
|
|
125
|
+
const transport2 = createGrpcWebTransport({
|
|
126
|
+
baseUrl: process.env.NX_GRPC_HOST || "https://grpc-web.next.streamlayer.io:443"
|
|
127
|
+
});
|
|
128
|
+
const userClient = createPromiseClient(Users, transport2);
|
|
129
|
+
await userClient.requestPassword({ id: phone });
|
|
130
|
+
return true;
|
|
131
|
+
};
|
|
132
|
+
var login = async (phone, code) => {
|
|
133
|
+
const transport2 = createGrpcWebTransport({
|
|
134
|
+
baseUrl: process.env.NX_GRPC_HOST || "https://grpc-web.next.streamlayer.io:443"
|
|
135
|
+
});
|
|
136
|
+
const userClient = createPromiseClient(Users, transport2);
|
|
137
|
+
const res = await userClient.login({ id: phone, password: code });
|
|
138
|
+
return res?.meta?.jwt;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// packages/react-ui/src/lib/gamification/vote/components/voting-header/components/timer/index.tsx
|
|
142
|
+
import { useEffect } from "react";
|
|
143
|
+
import { CountdownCircleTimer } from "react-countdown-circle-timer";
|
|
144
|
+
|
|
145
|
+
// packages/react-ui/src/lib/theme/theme.ts
|
|
146
|
+
var theme = {
|
|
147
|
+
COLORS: {
|
|
148
|
+
BG_TRANSPARENT: "rgba(0,0,0, .8)",
|
|
149
|
+
BG_TRANSPARENT_VOTE_CONTAINER: "rgba(10, 14, 19, 0.8)",
|
|
150
|
+
BG_TRANSPARENT_ITEM: "rgba(0, 0, 0, 0.7)",
|
|
151
|
+
BG_TRANSPARENT_ITEM_VOTE: "rgba(255, 255, 255, 0.1)",
|
|
152
|
+
BG_TRANSPARENT_ITEM_SUCCESS: "rgba(0, 139, 251, 0.2)",
|
|
153
|
+
BG_TRANSPARENT_ITEM_ERROR: "rgba(205, 37, 37, 0.2)",
|
|
154
|
+
BG_TRANSPARENT_VOTE_PROGRESS: "rgba(255, 255, 255, 0.2)",
|
|
155
|
+
BG_TRANSPARENT_VOTE_PROGRESS_SUCCESS: "rgba(60, 139, 251, 0.5)",
|
|
156
|
+
BG_TRANSPARENT_VOTE_PROGRESS_ERROR: "rgba(205, 37, 37, 0.5)",
|
|
157
|
+
BG_TRANSPARENT_USER_CONTAINER: "rgba(255, 255, 255, 0.05)",
|
|
158
|
+
BLUE_PRIMARY: "#1589EE",
|
|
159
|
+
RED_PRIMARY: "#CD2525",
|
|
160
|
+
BLUE_QUESTION_ACTION_BTN: "#1589ee",
|
|
161
|
+
WHITE: "#FFFFFF",
|
|
162
|
+
GREY_1: "#909395",
|
|
163
|
+
GREY_2: "#22262b",
|
|
164
|
+
GREY_3: "#2d3135",
|
|
165
|
+
GREY_4: "#53565a",
|
|
166
|
+
BLACK_1: "#161a1f",
|
|
167
|
+
GREEN_1: "#F7B801",
|
|
168
|
+
RED_1: "#A30000",
|
|
169
|
+
RED_2: "#FF4170",
|
|
170
|
+
GREY_PRIMARY: "#909395",
|
|
171
|
+
DIVIDER_COLOR_PRIMARY: "#2d3135",
|
|
172
|
+
DIVIDER_COLOR_SECONDARY: "#53565a",
|
|
173
|
+
GREEN_PRIMARY_BTN: "#009B77"
|
|
174
|
+
},
|
|
175
|
+
FONT: {
|
|
176
|
+
FAMILY: "Roboto, sans-serif",
|
|
177
|
+
COLOR: "#fff"
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// packages/react-ui/src/lib/gamification/vote/components/voting-header/components/timer/styles.tsx
|
|
182
|
+
import styled2 from "@emotion/styled";
|
|
183
|
+
var RemainingTime = styled2.div`
|
|
184
|
+
color: ${(props) => props.remainingTime ? "inherit" : props.theme.COLORS.RED_2};
|
|
185
|
+
font-size: 12px;
|
|
186
|
+
`;
|
|
187
|
+
|
|
188
|
+
// packages/react-ui/src/lib/gamification/vote/components/voting-header/components/timer/index.tsx
|
|
189
|
+
import { jsx as jsx3 } from "@emotion/react/jsx-runtime";
|
|
190
|
+
var TIMER_COLORS = [theme.COLORS.BLUE_PRIMARY, theme.COLORS.GREEN_1, theme.COLORS.RED_1];
|
|
191
|
+
var TIMER_COLORS_TIME = [10, 6, 0];
|
|
192
|
+
var DEFAULT_DURATION = 30;
|
|
193
|
+
var TIMER_SIZE = 32;
|
|
194
|
+
var STROKE_WIDTH = 4;
|
|
195
|
+
var TRAIL_STROKE_WIDTH = 0;
|
|
196
|
+
var Timer = ({ isPlaying = true, duration = DEFAULT_DURATION, setTimeToExpire }) => {
|
|
197
|
+
const renderTime = ({ remainingTime }) => /* @__PURE__ */ jsx3(RemainingTime, { remainingTime, children: remainingTime });
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
setTimeToExpire(false);
|
|
200
|
+
}, [setTimeToExpire]);
|
|
201
|
+
return /* @__PURE__ */ jsx3(
|
|
202
|
+
CountdownCircleTimer,
|
|
203
|
+
{
|
|
204
|
+
isPlaying,
|
|
205
|
+
duration,
|
|
206
|
+
colors: TIMER_COLORS,
|
|
207
|
+
colorsTime: TIMER_COLORS_TIME,
|
|
208
|
+
size: TIMER_SIZE,
|
|
209
|
+
strokeWidth: STROKE_WIDTH,
|
|
210
|
+
trailStrokeWidth: TRAIL_STROKE_WIDTH,
|
|
211
|
+
onComplete: () => setTimeToExpire(true),
|
|
212
|
+
children: renderTime
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// packages/react-ui/src/lib/gamification/login/styles.tsx
|
|
218
|
+
import styled3 from "@emotion/styled";
|
|
219
|
+
var Panel = styled3.div`
|
|
220
|
+
border-radius: 8px;
|
|
221
|
+
padding: 0 12px;
|
|
222
|
+
background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_ITEM};
|
|
223
|
+
display: flex;
|
|
224
|
+
align-items: center;
|
|
225
|
+
height: 100%;
|
|
226
|
+
`;
|
|
227
|
+
var Form = styled3.form`
|
|
228
|
+
display: flex;
|
|
229
|
+
margin: auto;
|
|
230
|
+
flex-direction: column;
|
|
231
|
+
align-items: center;
|
|
232
|
+
text-align: center;
|
|
233
|
+
`;
|
|
234
|
+
var FormTitle = styled3.div`
|
|
235
|
+
margin-bottom: 20px;
|
|
236
|
+
font-size: 18px;
|
|
237
|
+
`;
|
|
238
|
+
var FormDescription = styled3.div`
|
|
239
|
+
margin-bottom: 10px;
|
|
240
|
+
font-size: 14px;
|
|
241
|
+
|
|
242
|
+
display: flex;
|
|
243
|
+
align-items: center;
|
|
244
|
+
flex-direction: column;
|
|
245
|
+
`;
|
|
246
|
+
var FormSubmit = styled3.button`
|
|
247
|
+
background-color: ${(props) => props.theme.COLORS.BLUE_QUESTION_ACTION_BTN};
|
|
248
|
+
border: none;
|
|
249
|
+
border-radius: 2px;
|
|
250
|
+
padding: 6px;
|
|
251
|
+
text-transform: uppercase;
|
|
252
|
+
color: #fff;
|
|
253
|
+
cursor: pointer;
|
|
254
|
+
|
|
255
|
+
&:disabled {
|
|
256
|
+
opacity: 0.5;
|
|
257
|
+
cursor: default;
|
|
258
|
+
}
|
|
259
|
+
margin-bottom: 20px;
|
|
260
|
+
`;
|
|
261
|
+
var FormInputContainer = styled3.div`
|
|
262
|
+
input {
|
|
263
|
+
font-size: 20px;
|
|
264
|
+
background: transparent;
|
|
265
|
+
color: #fff;
|
|
266
|
+
border: none;
|
|
267
|
+
outline: none;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
margin-bottom: 40px;
|
|
271
|
+
border-bottom: 1px solid white;
|
|
272
|
+
`;
|
|
273
|
+
var Digits = styled3.div`
|
|
274
|
+
display: flex;
|
|
275
|
+
gap: 10px;
|
|
276
|
+
margin-bottom: 20px;
|
|
277
|
+
|
|
278
|
+
input {
|
|
279
|
+
width: 20px;
|
|
280
|
+
height: 40px;
|
|
281
|
+
font-size: 40px;
|
|
282
|
+
}
|
|
283
|
+
`;
|
|
284
|
+
|
|
285
|
+
// packages/react-ui/src/lib/gamification/login/index.tsx
|
|
286
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "@emotion/react/jsx-runtime";
|
|
287
|
+
var Login = ({ login: login2, anonymousLogin }) => {
|
|
288
|
+
const [phoneInput, setPhoneInput] = useState("");
|
|
289
|
+
const [phone, setPhone] = useState("");
|
|
290
|
+
const [code, setCode] = useState("");
|
|
291
|
+
const digits = useDigitInput({
|
|
292
|
+
acceptedCharacters: /^[0-9]$/,
|
|
293
|
+
length: 4,
|
|
294
|
+
value: code,
|
|
295
|
+
onChange: setCode
|
|
296
|
+
});
|
|
297
|
+
const requestCode = async (e) => {
|
|
298
|
+
e.preventDefault();
|
|
299
|
+
try {
|
|
300
|
+
const parsed = phoneInput.replaceAll("+", "");
|
|
301
|
+
await requestLoginCode(parsed);
|
|
302
|
+
setPhone(parsed);
|
|
303
|
+
} catch (err) {
|
|
304
|
+
window.alert(err);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
const loginByCode = async (e) => {
|
|
308
|
+
e.preventDefault();
|
|
309
|
+
if (phone && code) {
|
|
310
|
+
try {
|
|
311
|
+
const token = await login(phone, code);
|
|
312
|
+
if (token && login2) {
|
|
313
|
+
await login2(token);
|
|
314
|
+
} else {
|
|
315
|
+
console.log("token", token);
|
|
316
|
+
}
|
|
317
|
+
} catch (err) {
|
|
318
|
+
window.alert(err);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
return /* @__PURE__ */ jsxs3(Panel, { children: [
|
|
323
|
+
!phone && /* @__PURE__ */ jsxs3("div", { children: [
|
|
324
|
+
/* @__PURE__ */ jsxs3(Form, { onSubmit: requestCode, children: [
|
|
325
|
+
/* @__PURE__ */ jsx4(FormTitle, { children: "Enter your phone number" }),
|
|
326
|
+
/* @__PURE__ */ jsx4(FormDescription, { children: "Enter your phone up for number to log in or sign an account." }),
|
|
327
|
+
/* @__PURE__ */ jsx4(FormInputContainer, { children: /* @__PURE__ */ jsx4(PhoneInput, { value: phoneInput, onChange: (val) => setPhoneInput(`${val}`) }) }),
|
|
328
|
+
/* @__PURE__ */ jsx4(FormSubmit, { disabled: !isValidPhoneNumber(phoneInput), type: "submit", children: "request code" })
|
|
329
|
+
] }),
|
|
330
|
+
anonymousLogin && /* @__PURE__ */ jsx4(FormSubmit, { style: { display: "block", margin: "auto" }, disabled: true, onClick: anonymousLogin, children: "anonymous login" })
|
|
331
|
+
] }),
|
|
332
|
+
phone && /* @__PURE__ */ jsxs3(Form, { onSubmit: loginByCode, children: [
|
|
333
|
+
/* @__PURE__ */ jsx4(FormTitle, { children: "Enter Verification Code" }),
|
|
334
|
+
/* @__PURE__ */ jsxs3(FormDescription, { children: [
|
|
335
|
+
"Please enter the verification code ",
|
|
336
|
+
/* @__PURE__ */ jsx4("br", {}),
|
|
337
|
+
"sent to ",
|
|
338
|
+
/* @__PURE__ */ jsx4("b", { children: formatPhoneNumberIntl(phoneInput) })
|
|
339
|
+
] }),
|
|
340
|
+
/* @__PURE__ */ jsxs3(Digits, { children: [
|
|
341
|
+
/* @__PURE__ */ jsx4("input", { autoFocus: true, inputMode: "decimal", ...digits[0] }),
|
|
342
|
+
/* @__PURE__ */ jsx4("input", { inputMode: "decimal", ...digits[1] }),
|
|
343
|
+
/* @__PURE__ */ jsx4("input", { inputMode: "decimal", ...digits[2] }),
|
|
344
|
+
/* @__PURE__ */ jsx4("input", { inputMode: "decimal", ...digits[3] })
|
|
345
|
+
] }),
|
|
346
|
+
/* @__PURE__ */ jsx4(FormSubmit, { disabled: code.length !== 4, type: "submit", children: "login" }),
|
|
347
|
+
/* @__PURE__ */ jsxs3(FormDescription, { children: [
|
|
348
|
+
"Didn't get 59 the code? ",
|
|
349
|
+
/* @__PURE__ */ jsx4("br", {}),
|
|
350
|
+
"Resend Code in",
|
|
351
|
+
/* @__PURE__ */ jsx4(Timer, { duration: 30, setTimeToExpire: () => {
|
|
352
|
+
}, isPlaying: true })
|
|
353
|
+
] })
|
|
354
|
+
] })
|
|
355
|
+
] });
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
// packages/react-ui/src/lib/gamification/onboarding/styles.tsx
|
|
359
|
+
import styled4 from "@emotion/styled";
|
|
360
|
+
var Container2 = styled4.div`
|
|
361
|
+
box-sizing: border-box;
|
|
362
|
+
display: flex;
|
|
363
|
+
color: ${(props) => props.theme.COLORS.WHITE};
|
|
364
|
+
flex-direction: column;
|
|
365
|
+
height: 100%;
|
|
366
|
+
width: 100%;
|
|
367
|
+
`;
|
|
368
|
+
var Content2 = styled4.div`
|
|
369
|
+
flex: 1;
|
|
370
|
+
display: flex;
|
|
371
|
+
justify-content: center;
|
|
372
|
+
flex-direction: column;
|
|
373
|
+
align-items: center;
|
|
374
|
+
`;
|
|
375
|
+
var Description = styled4.div`
|
|
376
|
+
font-size: 22px;
|
|
377
|
+
font-weight: 300;
|
|
378
|
+
margin-bottom: 4px;
|
|
379
|
+
`;
|
|
380
|
+
var Title2 = styled4.div`
|
|
381
|
+
font-size: 26px;
|
|
382
|
+
font-weight: 700;
|
|
383
|
+
`;
|
|
384
|
+
var OnboardingActionBtn = styled4.button`
|
|
385
|
+
color: ${(props) => props.theme.COLORS.WHITE};
|
|
386
|
+
width: 100%;
|
|
387
|
+
border: none;
|
|
388
|
+
outline: none;
|
|
389
|
+
background-color: ${(props) => props.theme.COLORS.GREEN_PRIMARY_BTN};
|
|
390
|
+
cursor: pointer;
|
|
391
|
+
padding: 12px 16px;
|
|
392
|
+
display: flex;
|
|
393
|
+
justify-content: center;
|
|
394
|
+
align-items: center;
|
|
395
|
+
font-size: 16px;
|
|
396
|
+
font-weight: 600;
|
|
397
|
+
border-radius: 6px;
|
|
398
|
+
`;
|
|
399
|
+
|
|
400
|
+
// packages/react-ui/src/lib/gamification/onboarding/index.tsx
|
|
401
|
+
import { jsx as jsx5, jsxs as jsxs4 } from "@emotion/react/jsx-runtime";
|
|
402
|
+
var Onboarding = ({ action }) => /* @__PURE__ */ jsxs4(Container2, { children: [
|
|
403
|
+
/* @__PURE__ */ jsxs4(Content2, { children: [
|
|
404
|
+
/* @__PURE__ */ jsx5(Description, { children: "Welcome to the" }),
|
|
405
|
+
/* @__PURE__ */ jsx5(Title2, { children: "Inplay Game" })
|
|
406
|
+
] }),
|
|
407
|
+
/* @__PURE__ */ jsx5(OnboardingActionBtn, { onClick: action, children: "Let\u2019s play" })
|
|
408
|
+
] });
|
|
409
|
+
|
|
410
|
+
// packages/sdk-web-types/src/sl-types.ts
|
|
411
|
+
import { QuestionType, QuestionStatus } from "@streamlayer/sl-eslib/interactive/interactive.common_pb";
|
|
412
|
+
import { PickHistoryStatus } from "@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb";
|
|
413
|
+
import { SdkOverlayType } from "@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb";
|
|
414
|
+
|
|
415
|
+
// packages/react-ui/src/assets/icons/icon-poll.svg
|
|
416
|
+
import * as React3 from "react";
|
|
417
|
+
import { jsx as jsx6 } from "@emotion/react/jsx-runtime";
|
|
418
|
+
var SvgIconPoll = (props) => /* @__PURE__ */ jsx6("svg", { width: 16, height: 16, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsx6("g", { id: "Poll", children: /* @__PURE__ */ jsx6("path", { id: "Notification/Icon/Poll", fillRule: "evenodd", clipRule: "evenodd", d: "M9.7778 1.68421V5.05263H13.3333C13.8243 5.05263 14.2222 4.67561 14.2222 4.21053V2.52632C14.2222 2.06123 13.8243 1.68421 13.3333 1.68421H9.7778ZM2.66667 0C1.19391 0 0 1.13107 0 2.52632V4.21053C0 5.60577 1.19391 6.73684 2.66667 6.73684H13.3333C14.8061 6.73684 16 5.60577 16 4.21053V2.52632C16 1.13107 14.8061 0 13.3333 0H2.66667ZM4.44446 10.9473H13.3333C13.8243 10.9473 14.2222 11.3243 14.2222 11.7894V13.4736C14.2222 13.9387 13.8243 14.3157 13.3333 14.3157H4.44446V10.9473ZM0 11.7894C0 10.3942 1.19391 9.2631 2.66667 9.2631H13.3333C14.8061 9.2631 16 10.3942 16 11.7894V13.4736C16 14.8689 14.8061 15.9999 13.3333 15.9999H2.66667C1.19391 15.9999 0 14.8689 0 13.4736V11.7894Z", fill: "white", fillOpacity: 0.5 }) }) });
|
|
419
|
+
var icon_poll_default = SvgIconPoll;
|
|
420
|
+
|
|
421
|
+
// packages/react-ui/src/assets/icons/icon-prediction.svg
|
|
422
|
+
import * as React4 from "react";
|
|
423
|
+
import { jsx as jsx7 } from "@emotion/react/jsx-runtime";
|
|
424
|
+
var SvgIconPrediction = (props) => /* @__PURE__ */ jsx7("svg", { width: 16, height: 16, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsx7("g", { id: "Icon/Notification/Prediciton", children: /* @__PURE__ */ jsx7("path", { id: "Icon/Prediction", fillRule: "evenodd", clipRule: "evenodd", d: "M16 7.00522C16 7.00522 9.20048 6.81607 9.20048 0C9.20048 6.36168 3.27729 6.95056 2.48756 7.00078L2.40094 7.00522C2.40094 7.00522 9.20048 7.19435 9.20048 14.0104C9.20048 7.64877 15.1234 7.05989 15.9131 7.00964L16 7.00522ZM6.97382 12.5652C6.97382 12.5652 3.48691 12.4724 3.48691 9.13033C3.48691 12.2496 0.449402 12.5384 0.0444186 12.563L0 12.5652C0 12.5652 3.48691 12.6579 3.48691 16C3.48691 12.8807 6.52429 12.592 6.92927 12.5673L6.97382 12.5652Z", fill: "white", fillOpacity: 0.5 }) }) });
|
|
425
|
+
var icon_prediction_default = SvgIconPrediction;
|
|
426
|
+
|
|
427
|
+
// packages/react-ui/src/assets/icons/icon-trivia.svg
|
|
428
|
+
import * as React5 from "react";
|
|
429
|
+
import { jsx as jsx8 } from "@emotion/react/jsx-runtime";
|
|
430
|
+
var SvgIconTrivia = (props) => /* @__PURE__ */ jsx8("svg", { width: 16, height: 16, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsx8("g", { id: "Icon/Notification/Trivia", children: /* @__PURE__ */ jsx8("path", { id: "Notification/Icon/Trivia", fillRule: "evenodd", clipRule: "evenodd", d: "M2.01663 1.3808C0.739913 1.55586 -0.153153 2.73276 0.021912 4.00948L1.3808 13.9196C1.55586 15.1963 2.73276 16.0894 4.00948 15.9143L13.9196 14.5554C15.1963 14.3803 16.0894 13.2034 15.9143 11.9267L14.5554 2.01663C14.3803 0.739913 13.2034 -0.153153 11.9267 0.021912L2.01663 1.3808ZM9.59613 3.788C9.11431 3.46991 8.47813 3.30151 7.7566 3.30151C7.54377 3.30151 7.32625 3.31671 7.10872 3.34478C6.38836 3.44067 5.68901 3.79034 5.18965 4.30138C4.68445 4.82062 4.4377 5.45563 4.51722 6.04151C4.57452 6.4742 4.90078 6.7537 5.34635 6.7537C5.39429 6.7537 5.44341 6.7502 5.49136 6.74435C6.08778 6.66483 6.21642 6.25436 6.34036 5.85675L6.34045 5.85648C6.48192 5.40401 6.61534 4.97731 7.38585 4.87444C7.46537 4.86391 7.54138 4.85806 7.61506 4.85806C8.16939 4.85806 8.51436 5.15042 8.58454 5.68252C8.65353 6.20293 8.24307 6.61807 7.80684 7.0566L7.80393 7.05954C7.31582 7.55231 6.7639 8.1095 6.86895 8.90083C6.89585 9.10548 6.9859 9.29493 7.12272 9.43644C7.27826 9.599 7.4829 9.68436 7.71331 9.68436C7.75541 9.68436 7.79868 9.68203 7.84311 9.67618C8.46691 9.59324 8.55162 9.23139 8.63338 8.8821L8.63365 8.88097L8.63661 8.86859C8.66723 8.7403 8.69877 8.60813 8.75995 8.48804C8.84649 8.31613 9.06283 8.11265 9.31428 7.87875C9.9142 7.31858 10.734 6.55143 10.582 5.41589C10.4872 4.70603 10.1551 4.15757 9.59611 3.78802L9.59613 3.788ZM8.11605 10.28C8.06927 10.28 8.02132 10.2836 7.97454 10.2894C7.38396 10.3689 6.96765 10.9127 7.04599 11.5033C7.11733 12.0377 7.57808 12.4412 8.1172 12.4412C8.16397 12.4412 8.21192 12.4377 8.25987 12.4318C8.85045 12.3523 9.2656 11.8085 9.18842 11.2179C9.11591 10.6823 8.65517 10.28 8.11605 10.28Z", fill: "white", fillOpacity: 0.5 }) }) });
|
|
431
|
+
var icon_trivia_default = SvgIconTrivia;
|
|
432
|
+
|
|
433
|
+
// packages/react-ui/src/assets/icons/icon-check-green.svg
|
|
434
|
+
import * as React6 from "react";
|
|
435
|
+
import { jsx as jsx9 } from "@emotion/react/jsx-runtime";
|
|
436
|
+
var SvgIconCheckGreen = (props) => /* @__PURE__ */ jsx9("svg", { width: 16, height: 17, viewBox: "0 0 16 17", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsx9("g", { id: "Check", children: /* @__PURE__ */ jsx9("path", { id: "Vector", d: "M13.4315 3.18246L5.53321 11.0808L1.99771 7.54527C1.54056 7.08811 0.799913 7.08811 0.342864 7.54527C-0.114288 8.00242 -0.114288 8.74307 0.342864 9.20011L4.70567 13.5629C4.93331 13.7906 5.23415 13.9063 5.53307 13.9063C5.83202 13.9063 6.13096 13.7924 6.36048 13.5629L15.0861 4.83731C15.5432 4.38016 15.5432 3.63951 15.0861 3.18246C14.629 2.72531 13.8884 2.72531 13.4312 3.18246H13.4315Z", fill: "#00BD60" }) }) });
|
|
437
|
+
var icon_check_green_default = SvgIconCheckGreen;
|
|
438
|
+
|
|
439
|
+
// packages/react-ui/src/assets/icons/icon-cross.svg
|
|
440
|
+
import * as React7 from "react";
|
|
441
|
+
import { jsx as jsx10, jsxs as jsxs5 } from "@emotion/react/jsx-runtime";
|
|
442
|
+
var SvgIconCross = (props) => /* @__PURE__ */ jsx10("svg", { width: 14, height: 14, viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsxs5("g", { id: "Group 465", children: [
|
|
443
|
+
/* @__PURE__ */ jsx10("rect", { id: "Rectangle 368", x: 2, y: 0.506104, width: 16.4992, height: 2.35702, rx: 1.17851, transform: "rotate(45 2 0.506104)", fill: "#9e0a1f" }),
|
|
444
|
+
/* @__PURE__ */ jsx10("rect", { id: "Rectangle 369", x: 0.333008, y: 12.1729, width: 16.4992, height: 2.35702, rx: 1.17851, transform: "rotate(-45 0.333008 12.1729)", fill: "#9e0a1f" })
|
|
445
|
+
] }) });
|
|
446
|
+
var icon_cross_default = SvgIconCross;
|
|
447
|
+
|
|
448
|
+
// packages/react-ui/src/assets/icons/icon-chevron.svg
|
|
449
|
+
import * as React8 from "react";
|
|
450
|
+
import { jsx as jsx11 } from "@emotion/react/jsx-runtime";
|
|
451
|
+
var SvgIconChevron = (props) => /* @__PURE__ */ jsx11("svg", { width: 16, height: 17, viewBox: "0 0 16 17", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsx11("g", { id: "Chevron", children: /* @__PURE__ */ jsx11("path", { id: "Chevron_2", d: "M12 8.17222C12 8.28783 11.9781 8.39553 11.9342 8.49533C11.8903 8.59513 11.822 8.68992 11.7292 8.7797L6.36949 13.9439C6.21462 14.0965 6.02742 14.1729 5.80787 14.1729C5.65752 14.1729 5.52191 14.1379 5.40104 14.0679C5.28016 13.998 5.1831 13.9039 5.10986 13.7856C5.03662 13.6673 5 13.5345 5 13.3873C5 13.1721 5.08288 12.9818 5.24863 12.8164L10.0807 8.17095L5.24863 3.52799C5.08288 3.36425 5 3.17439 5 2.95841C5 2.81118 5.03662 2.67842 5.10986 2.56013C5.1831 2.44183 5.28016 2.34771 5.40104 2.27777C5.52191 2.20782 5.65752 2.17285 5.80787 2.17285C6.02742 2.17285 6.21462 2.24731 6.36949 2.39624L11.7292 7.56473C11.8211 7.65451 11.889 7.74909 11.9329 7.84846C11.9768 7.94784 11.9991 8.05576 12 8.17222Z", fill: "#FFFFFF" }) }) });
|
|
452
|
+
var icon_chevron_default = SvgIconChevron;
|
|
453
|
+
|
|
454
|
+
// packages/react-ui/src/lib/gamification/question/styles.tsx
|
|
455
|
+
import styled5 from "@emotion/styled";
|
|
456
|
+
var Panel2 = styled5.div`
|
|
457
|
+
border-radius: 8px;
|
|
458
|
+
padding: 12px;
|
|
459
|
+
background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_ITEM};
|
|
460
|
+
display: flex;
|
|
461
|
+
align-items: center;
|
|
462
|
+
cursor: pointer;
|
|
463
|
+
|
|
464
|
+
&:hover {
|
|
465
|
+
background: #000;
|
|
466
|
+
}
|
|
467
|
+
`;
|
|
468
|
+
var QuestionTypeIconWrap = styled5.div`
|
|
469
|
+
padding-right: 12px;
|
|
470
|
+
display: flex;
|
|
471
|
+
align-items: center;
|
|
472
|
+
justify-content: center;
|
|
473
|
+
`;
|
|
474
|
+
var QuestionTypeIcon = styled5.img`
|
|
475
|
+
width: 16px;
|
|
476
|
+
height: 16px;
|
|
477
|
+
`;
|
|
478
|
+
var QuestionContent = styled5.div`
|
|
479
|
+
font-weight: 700;
|
|
480
|
+
flex: 1;
|
|
481
|
+
display: flex;
|
|
482
|
+
flex-direction: column;
|
|
483
|
+
overflow: hidden;
|
|
484
|
+
`;
|
|
485
|
+
var QuestionTypeLabel = styled5.div`
|
|
486
|
+
color: ${(props) => props.theme.COLORS.GREY_PRIMARY};
|
|
487
|
+
font-size: 10px;
|
|
488
|
+
overflow: hidden;
|
|
489
|
+
text-overflow: ellipsis;
|
|
490
|
+
white-space: nowrap;
|
|
491
|
+
padding-bottom: 5px;
|
|
492
|
+
text-transform: uppercase;
|
|
493
|
+
`;
|
|
494
|
+
var QuestionSubject = styled5.div`
|
|
495
|
+
color: ${(props) => props.theme.COLORS.WHITE};
|
|
496
|
+
font-size: 12px;
|
|
497
|
+
overflow: hidden;
|
|
498
|
+
text-overflow: ellipsis;
|
|
499
|
+
white-space: nowrap;
|
|
500
|
+
`;
|
|
501
|
+
var QuestionActionTitle = styled5.button`
|
|
502
|
+
background-color: ${(props) => props.theme.COLORS.BLUE_QUESTION_ACTION_BTN};
|
|
503
|
+
border: none;
|
|
504
|
+
border-radius: 2px;
|
|
505
|
+
font-size: 8px;
|
|
506
|
+
padding: 6px;
|
|
507
|
+
height: 20px;
|
|
508
|
+
text-transform: uppercase;
|
|
509
|
+
color: #fff;
|
|
510
|
+
cursor: pointer;
|
|
511
|
+
`;
|
|
512
|
+
var QuestionActionIcon = styled5.button`
|
|
513
|
+
border: none;
|
|
514
|
+
font-size: 8px;
|
|
515
|
+
padding: 6px;
|
|
516
|
+
display: flex;
|
|
517
|
+
align-items: center;
|
|
518
|
+
background-color: transparent;
|
|
519
|
+
cursor: pointer;
|
|
520
|
+
`;
|
|
521
|
+
var QuestionStatusIcon = styled5.img`
|
|
522
|
+
width: 16px;
|
|
523
|
+
height: 16px;
|
|
524
|
+
`;
|
|
525
|
+
var QuestionTypeTitle = styled5.span`
|
|
526
|
+
text-transform: uppercase;
|
|
527
|
+
`;
|
|
528
|
+
var ExpiredQuestion = styled5.span`
|
|
529
|
+
text-transform: uppercase;
|
|
530
|
+
border-left: ${(props) => `1px solid ${props.theme.COLORS.GREY_PRIMARY}`};
|
|
531
|
+
padding-left: 5px;
|
|
532
|
+
margin-left: 5px;
|
|
533
|
+
`;
|
|
534
|
+
|
|
535
|
+
// packages/react-ui/src/lib/gamification/question/index.tsx
|
|
536
|
+
import { jsx as jsx12, jsxs as jsxs6 } from "@emotion/react/jsx-runtime";
|
|
537
|
+
var QuestionTypeData = {
|
|
538
|
+
[QuestionType.POLL]: { label: "Poll", icon: icon_poll_default },
|
|
539
|
+
[QuestionType.TRIVIA]: { label: "Trivia", icon: icon_trivia_default },
|
|
540
|
+
[QuestionType.PREDICTION]: { label: "Prediction", icon: icon_prediction_default }
|
|
541
|
+
};
|
|
542
|
+
var QuestionStatusTypeData = {
|
|
543
|
+
[PickHistoryStatus.LOST]: icon_cross_default,
|
|
544
|
+
[PickHistoryStatus.WON]: icon_check_green_default,
|
|
545
|
+
[PickHistoryStatus.UNSET]: icon_chevron_default,
|
|
546
|
+
[PickHistoryStatus.DNP]: icon_chevron_default
|
|
547
|
+
};
|
|
548
|
+
var Question = ({
|
|
549
|
+
questionId,
|
|
550
|
+
questionType,
|
|
551
|
+
questionStatus,
|
|
552
|
+
subject,
|
|
553
|
+
openForVoting,
|
|
554
|
+
openQuestion,
|
|
555
|
+
status
|
|
556
|
+
}) => {
|
|
557
|
+
const questionTypeData = QuestionTypeData[questionType];
|
|
558
|
+
if (questionTypeData === void 0) {
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
561
|
+
return /* @__PURE__ */ jsxs6(Panel2, { onClick: () => openQuestion?.(questionId), children: [
|
|
562
|
+
/* @__PURE__ */ jsx12(QuestionTypeIconWrap, { children: /* @__PURE__ */ jsx12(QuestionTypeIcon, { alt: "question-type-icon", src: questionTypeData.icon }) }),
|
|
563
|
+
/* @__PURE__ */ jsxs6(QuestionContent, { children: [
|
|
564
|
+
/* @__PURE__ */ jsxs6(QuestionTypeLabel, { children: [
|
|
565
|
+
/* @__PURE__ */ jsx12(QuestionTypeTitle, { children: questionTypeData.label }),
|
|
566
|
+
questionType === QuestionType.TRIVIA && questionStatus === QuestionStatus.RESOLVED && /* @__PURE__ */ jsx12(ExpiredQuestion, { children: "Expired" })
|
|
567
|
+
] }),
|
|
568
|
+
/* @__PURE__ */ jsx12(QuestionSubject, { children: subject || "" })
|
|
569
|
+
] }),
|
|
570
|
+
openForVoting ? /* @__PURE__ */ jsx12(QuestionActionTitle, { children: "play" }) : /* @__PURE__ */ jsx12(QuestionActionIcon, { children: /* @__PURE__ */ jsx12(QuestionStatusIcon, { alt: "question-status-icon", src: QuestionStatusTypeData[status] }) })
|
|
571
|
+
] });
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
// packages/react-ui/src/lib/gamification/question-list/styles.tsx
|
|
575
|
+
import styled6 from "@emotion/styled";
|
|
576
|
+
var Container3 = styled6.div`
|
|
577
|
+
display: flex;
|
|
578
|
+
flex-direction: column;
|
|
579
|
+
height: calc(100% - 160px);
|
|
580
|
+
border-radius: 13px;
|
|
581
|
+
`;
|
|
582
|
+
var Title3 = styled6.div`
|
|
583
|
+
color: ${(props) => props.theme.COLORS.GREY_PRIMARY};
|
|
584
|
+
text-transform: uppercase;
|
|
585
|
+
font-size: 12px;
|
|
586
|
+
font-weight: 500;
|
|
587
|
+
margin-bottom: 8px;
|
|
588
|
+
`;
|
|
589
|
+
var ItemsContainer = styled6.div`
|
|
590
|
+
display: flex;
|
|
591
|
+
flex-direction: column;
|
|
592
|
+
overflow-y: auto;
|
|
593
|
+
max-height: 100%;
|
|
594
|
+
|
|
595
|
+
& > div {
|
|
596
|
+
margin-bottom: 8px;
|
|
597
|
+
}
|
|
598
|
+
`;
|
|
599
|
+
|
|
600
|
+
// packages/react-ui/src/lib/gamification/question-list/index.tsx
|
|
601
|
+
import { jsx as jsx13, jsxs as jsxs7 } from "@emotion/react/jsx-runtime";
|
|
602
|
+
var QuestionList = ({ questions, openQuestion }) => {
|
|
603
|
+
return /* @__PURE__ */ jsxs7(Container3, { children: [
|
|
604
|
+
/* @__PURE__ */ jsx13(Title3, { children: "PICK HISTORY" }),
|
|
605
|
+
/* @__PURE__ */ jsx13(ItemsContainer, { children: questions?.map((props) => /* @__PURE__ */ jsx13(Question, { openQuestion, ...props }, props.questionId)) })
|
|
606
|
+
] });
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
// packages/react-ui/src/assets/icons/icon-trophy.svg
|
|
610
|
+
import * as React9 from "react";
|
|
611
|
+
import { jsx as jsx14 } from "@emotion/react/jsx-runtime";
|
|
612
|
+
var SvgIconTrophy = (props) => /* @__PURE__ */ jsx14("svg", { width: 12, height: 12, viewBox: "0 0 12 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsx14("g", { id: "Trophy", children: /* @__PURE__ */ jsx14("path", { id: "Combined Shape", fillRule: "evenodd", clipRule: "evenodd", d: "M2.76916 3.50002C2.76916 4.49786 2.94705 5.38348 3.30282 6.15692C2.62493 6.01847 2.05883 5.74872 1.6045 5.34768C1.15017 4.94663 0.923008 4.55992 0.923008 4.18752V3.50002H2.76916ZM11.0768 3.50002V4.18752C11.0768 4.55992 10.8497 4.94663 10.3953 5.34768C9.941 5.74872 9.3749 6.01847 8.69701 6.15692C9.05278 5.38348 9.23066 4.49786 9.23066 3.50002H11.0768ZM12 4.1875V3.27083C12 3.07986 11.9327 2.91754 11.7981 2.78385C11.6635 2.65017 11.5 2.58333 11.3077 2.58333H9.23077V1.89583C9.23077 1.58073 9.11779 1.31098 8.89183 1.08659C8.66586 0.862195 8.39423 0.75 8.07692 0.75H3.92308C3.60577 0.75 3.33414 0.862195 3.10817 1.08659C2.88221 1.31098 2.76923 1.58073 2.76923 1.89583V2.58333H0.692308C0.499999 2.58333 0.336539 2.65017 0.201923 2.78385C0.067307 2.91754 0 3.07986 0 3.27083V4.1875C0 4.52648 0.0997586 4.86784 0.299279 5.21159C0.498799 5.55534 0.768027 5.86567 1.10697 6.14258C1.44592 6.41949 1.86178 6.65223 2.35457 6.84082C2.84736 7.02941 3.36538 7.13563 3.90865 7.15951C4.11058 7.41732 4.33894 7.6441 4.59375 7.83984C4.77644 8.00217 4.90264 8.17524 4.97236 8.35905C5.04207 8.54286 5.07692 8.75651 5.07692 9C5.07692 9.25781 5.00361 9.47504 4.85697 9.65169C4.71034 9.82834 4.47596 9.91667 4.15385 9.91667C3.79327 9.91667 3.47236 10.0253 3.19111 10.2425C2.90985 10.4597 2.76923 10.7331 2.76923 11.0625V11.5208C2.76923 11.5877 2.79087 11.6426 2.83413 11.6855C2.8774 11.7285 2.93269 11.75 3 11.75H9C9.06731 11.75 9.1226 11.7285 9.16586 11.6855C9.20913 11.6426 9.23077 11.5877 9.23077 11.5208V11.0625C9.23077 10.7331 9.09015 10.4597 8.80889 10.2425C8.52764 10.0253 8.20673 9.91667 7.84615 9.91667C7.52404 9.91667 7.28966 9.82834 7.14303 9.65169C6.99639 9.47504 6.92308 9.25781 6.92308 9C6.92308 8.75651 6.95793 8.54286 7.02764 8.35905C7.09736 8.17524 7.22356 8.00217 7.40625 7.83984C7.66106 7.6441 7.88942 7.41732 8.09135 7.15951C8.63462 7.13563 9.15264 7.02941 9.64543 6.84082C10.1382 6.65223 10.5541 6.41949 10.893 6.14258C11.232 5.86567 11.5012 5.55534 11.7007 5.21159C11.9002 4.86784 12 4.52648 12 4.1875ZM5.07033 5.38491L6.0383 4.87503L7.00627 5.38491L6.8214 4.30497L7.60451 3.54016L6.52228 3.3826L6.0383 2.40003L5.55431 3.3826L4.47209 3.54016L5.25519 4.30497L5.07033 5.38491Z", fill: "#F2C94C" }) }) });
|
|
613
|
+
var icon_trophy_default = SvgIconTrophy;
|
|
614
|
+
|
|
615
|
+
// packages/react-ui/src/lib/gamification/user-statistics/components/statistics/styles.tsx
|
|
616
|
+
import styled7 from "@emotion/styled";
|
|
617
|
+
var Container4 = styled7.div`
|
|
618
|
+
font-weight: 700;
|
|
619
|
+
display: flex;
|
|
620
|
+
flex-direction: column;
|
|
621
|
+
row-gap: 4px;
|
|
622
|
+
align-items: center;
|
|
623
|
+
text-align: center;
|
|
624
|
+
`;
|
|
625
|
+
var Indicator = styled7.div`
|
|
626
|
+
font-size: 18px;
|
|
627
|
+
color: #fff;
|
|
628
|
+
`;
|
|
629
|
+
|
|
630
|
+
// packages/react-ui/src/lib/gamification/user-statistics/components/statistics/index.tsx
|
|
631
|
+
import { jsx as jsx15, jsxs as jsxs8 } from "@emotion/react/jsx-runtime";
|
|
632
|
+
var Statistics = ({ indicator, title }) => /* @__PURE__ */ jsxs8(Container4, { children: [
|
|
633
|
+
/* @__PURE__ */ jsx15(Indicator, { children: indicator }),
|
|
634
|
+
/* @__PURE__ */ jsx15("p", { children: title })
|
|
635
|
+
] });
|
|
636
|
+
|
|
637
|
+
// packages/react-ui/src/lib/gamification/user-statistics/components/rank/styles.tsx
|
|
638
|
+
import styled8 from "@emotion/styled";
|
|
639
|
+
var Container5 = styled8.div`
|
|
640
|
+
display: flex;
|
|
641
|
+
justify-content: flex-end;
|
|
642
|
+
align-items: center;
|
|
643
|
+
column-gap: 2px;
|
|
644
|
+
overflow: hidden;
|
|
645
|
+
`;
|
|
646
|
+
var Title4 = styled8.div`
|
|
647
|
+
width: 75px;
|
|
648
|
+
`;
|
|
649
|
+
var Indicator2 = styled8.div`
|
|
650
|
+
font-size: 14px;
|
|
651
|
+
color: #fff;
|
|
652
|
+
overflow: hidden;
|
|
653
|
+
text-overflow: ellipsis;
|
|
654
|
+
white-space: nowrap;
|
|
655
|
+
width: 25px;
|
|
656
|
+
`;
|
|
657
|
+
|
|
658
|
+
// packages/react-ui/src/lib/gamification/user-statistics/components/rank/index.tsx
|
|
659
|
+
import { jsx as jsx16, jsxs as jsxs9 } from "@emotion/react/jsx-runtime";
|
|
660
|
+
var Rank = ({ indicator, title }) => /* @__PURE__ */ jsxs9(Container5, { children: [
|
|
661
|
+
/* @__PURE__ */ jsx16(Title4, { children: title }),
|
|
662
|
+
/* @__PURE__ */ jsx16(Indicator2, { children: indicator })
|
|
663
|
+
] });
|
|
664
|
+
|
|
665
|
+
// packages/react-ui/src/lib/gamification/user-statistics/styles.tsx
|
|
666
|
+
import styled9 from "@emotion/styled";
|
|
667
|
+
var Container6 = styled9.div`
|
|
668
|
+
background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_USER_CONTAINER};
|
|
669
|
+
border-radius: 12px;
|
|
670
|
+
color: ${(props) => props.theme.COLORS.GREY_PRIMARY};
|
|
671
|
+
font-size: 10px;
|
|
672
|
+
font-weight: 600;
|
|
673
|
+
`;
|
|
674
|
+
var TopInfo = styled9.div`
|
|
675
|
+
padding: 12px;
|
|
676
|
+
border-bottom: ${(props) => `1px solid ${props.theme.COLORS.DIVIDER_COLOR_PRIMARY}`};
|
|
677
|
+
display: flex;
|
|
678
|
+
justify-content: space-between;
|
|
679
|
+
align-items: center;
|
|
680
|
+
column-gap: 5px;
|
|
681
|
+
`;
|
|
682
|
+
var BottomInfo = styled9.div`
|
|
683
|
+
padding: 12px 16px;
|
|
684
|
+
text-transform: uppercase;
|
|
685
|
+
display: flex;
|
|
686
|
+
justify-content: space-between;
|
|
687
|
+
column-gap: 16px;
|
|
688
|
+
`;
|
|
689
|
+
var User = styled9.div`
|
|
690
|
+
display: flex;
|
|
691
|
+
column-gap: 8px;
|
|
692
|
+
flex: 1;
|
|
693
|
+
overflow: hidden;
|
|
694
|
+
`;
|
|
695
|
+
var Avatar = styled9.img`
|
|
696
|
+
width: 100%;
|
|
697
|
+
height: 100%;
|
|
698
|
+
max-width: 48px;
|
|
699
|
+
max-height: 48px;
|
|
700
|
+
border-radius: 50%;
|
|
701
|
+
object-fit: cover;
|
|
702
|
+
object-position: center;
|
|
703
|
+
flex-shrink: 0;
|
|
704
|
+
`;
|
|
705
|
+
var UserInfo = styled9.div`
|
|
706
|
+
padding-top: 4px;
|
|
707
|
+
display: flex;
|
|
708
|
+
flex-direction: column;
|
|
709
|
+
row-gap: 4px;
|
|
710
|
+
overflow: hidden;
|
|
711
|
+
`;
|
|
712
|
+
var UserName = styled9.div`
|
|
713
|
+
font-size: 18px;
|
|
714
|
+
color: ${(props) => props.theme.COLORS.WHITE};
|
|
715
|
+
overflow: hidden;
|
|
716
|
+
text-overflow: ellipsis;
|
|
717
|
+
white-space: nowrap;
|
|
718
|
+
`;
|
|
719
|
+
var UserRating = styled9.div`
|
|
720
|
+
text-transform: uppercase;
|
|
721
|
+
display: flex;
|
|
722
|
+
align-items: center;
|
|
723
|
+
`;
|
|
724
|
+
var TrophyIcon = styled9.img`
|
|
725
|
+
width: 12px;
|
|
726
|
+
height: 12px;
|
|
727
|
+
margin-right: 4px;
|
|
728
|
+
`;
|
|
729
|
+
var Rts = styled9.div`
|
|
730
|
+
display: flex;
|
|
731
|
+
align-items: center;
|
|
732
|
+
column-gap: 4px;
|
|
733
|
+
border-right: ${(props) => `1px solid ${props.theme.COLORS.DIVIDER_COLOR_SECONDARY}`};
|
|
734
|
+
padding-right: 5px;
|
|
735
|
+
`;
|
|
736
|
+
var RtsIndicator = styled9.div`
|
|
737
|
+
font-size: 14px;
|
|
738
|
+
color: ${(props) => props.theme.COLORS.WHITE};
|
|
739
|
+
`;
|
|
740
|
+
var Top = styled9.div`
|
|
741
|
+
padding-left: 5px;
|
|
742
|
+
`;
|
|
743
|
+
var Ranks = styled9.div`
|
|
744
|
+
text-transform: uppercase;
|
|
745
|
+
display: flex;
|
|
746
|
+
flex-direction: column;
|
|
747
|
+
row-gap: 4px;
|
|
748
|
+
`;
|
|
749
|
+
var AvatarPlaceholder = styled9.div`
|
|
750
|
+
background: #2d6ffd;
|
|
751
|
+
border-radius: 50%;
|
|
752
|
+
width: 48px;
|
|
753
|
+
height: 48px;
|
|
754
|
+
text-align: center;
|
|
755
|
+
text-transform: uppercase;
|
|
756
|
+
display: flex;
|
|
757
|
+
align-items: center;
|
|
758
|
+
justify-content: center;
|
|
759
|
+
color: #fff;
|
|
760
|
+
font-size: 18px;
|
|
761
|
+
flex-shrink: 0;
|
|
762
|
+
`;
|
|
763
|
+
|
|
764
|
+
// packages/react-ui/src/lib/gamification/user-statistics/index.tsx
|
|
765
|
+
import { jsx as jsx17, jsxs as jsxs10 } from "@emotion/react/jsx-runtime";
|
|
766
|
+
var abbreviate = (name) => name.split(/\s+/).map((p) => p[0]).join("").toUpperCase();
|
|
767
|
+
var UserStatistics = ({
|
|
768
|
+
avatar,
|
|
769
|
+
name,
|
|
770
|
+
points,
|
|
771
|
+
grade,
|
|
772
|
+
friendsRank,
|
|
773
|
+
globalRank,
|
|
774
|
+
winStreak,
|
|
775
|
+
correct,
|
|
776
|
+
incorrect,
|
|
777
|
+
successRate
|
|
778
|
+
}) => {
|
|
779
|
+
return /* @__PURE__ */ jsxs10(Container6, { children: [
|
|
780
|
+
/* @__PURE__ */ jsxs10(TopInfo, { children: [
|
|
781
|
+
/* @__PURE__ */ jsxs10(User, { children: [
|
|
782
|
+
avatar && /* @__PURE__ */ jsx17(Avatar, { alt: "avatar", src: avatar }),
|
|
783
|
+
!avatar && /* @__PURE__ */ jsx17(AvatarPlaceholder, { children: abbreviate(name) }),
|
|
784
|
+
/* @__PURE__ */ jsxs10(UserInfo, { children: [
|
|
785
|
+
/* @__PURE__ */ jsx17(UserName, { children: name }),
|
|
786
|
+
/* @__PURE__ */ jsxs10(UserRating, { children: [
|
|
787
|
+
/* @__PURE__ */ jsx17(TrophyIcon, { alt: "rank-icon", src: icon_trophy_default }),
|
|
788
|
+
/* @__PURE__ */ jsxs10(Rts, { children: [
|
|
789
|
+
/* @__PURE__ */ jsx17(RtsIndicator, { children: points || "-" }),
|
|
790
|
+
"RTS"
|
|
791
|
+
] }),
|
|
792
|
+
/* @__PURE__ */ jsxs10(Top, { children: [
|
|
793
|
+
"TOP ",
|
|
794
|
+
grade,
|
|
795
|
+
"%"
|
|
796
|
+
] })
|
|
797
|
+
] })
|
|
798
|
+
] })
|
|
799
|
+
] }),
|
|
800
|
+
/* @__PURE__ */ jsxs10(Ranks, { children: [
|
|
801
|
+
/* @__PURE__ */ jsx17(Rank, { title: "Friens rank", indicator: friendsRank || "-" }),
|
|
802
|
+
/* @__PURE__ */ jsx17(Rank, { title: "Global rank", indicator: globalRank || "-" })
|
|
803
|
+
] })
|
|
804
|
+
] }),
|
|
805
|
+
/* @__PURE__ */ jsxs10(BottomInfo, { children: [
|
|
806
|
+
/* @__PURE__ */ jsx17(Statistics, { indicator: winStreak || "-", title: "Win streak" }),
|
|
807
|
+
/* @__PURE__ */ jsx17(Statistics, { indicator: correct || "-", title: "Correct" }),
|
|
808
|
+
/* @__PURE__ */ jsx17(Statistics, { indicator: incorrect || "-", title: "Incorrect" }),
|
|
809
|
+
/* @__PURE__ */ jsx17(Statistics, { indicator: `${successRate || "-"}%`, title: "Success rate" })
|
|
810
|
+
] })
|
|
811
|
+
] });
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
// packages/react-ui/src/assets/icons/icon-check.svg
|
|
815
|
+
import * as React10 from "react";
|
|
816
|
+
import { jsx as jsx18 } from "@emotion/react/jsx-runtime";
|
|
817
|
+
var SvgIconCheck = (props) => /* @__PURE__ */ jsx18("svg", { width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsx18("g", { id: "Checkmark", children: /* @__PURE__ */ jsx18("path", { id: "Selected", fillRule: "evenodd", clipRule: "evenodd", d: "M24 12.002C24 18.6294 18.6274 24.002 12 24.002C5.37258 24.002 0 18.6294 0 12.002C0 5.37454 5.37258 0.00195312 12 0.00195312C18.6274 0.00195312 24 5.37454 24 12.002ZM17.4086 8.15357C16.94 7.68494 16.1802 7.68494 15.7116 8.15357L10.4072 14.9579L7.62573 13.1036C7.07429 12.736 6.32925 12.885 5.96163 13.4365C5.59401 13.9879 5.74301 14.7329 6.29445 15.1006L9.89445 17.5006C10.3704 17.8179 11.0041 17.7551 11.4086 17.3506L17.4086 9.85063C17.8772 9.382 17.8772 8.6222 17.4086 8.15357Z", fill: "#00BD60" }) }) });
|
|
818
|
+
var icon_check_default = SvgIconCheck;
|
|
819
|
+
|
|
820
|
+
// packages/react-ui/src/assets/icons/icon-close.svg
|
|
821
|
+
import * as React11 from "react";
|
|
822
|
+
import { jsx as jsx19, jsxs as jsxs11 } from "@emotion/react/jsx-runtime";
|
|
823
|
+
var SvgIconClose = (props) => /* @__PURE__ */ jsxs11("svg", { width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: [
|
|
824
|
+
/* @__PURE__ */ jsx19("rect", { y: 195312e-8, width: 24, height: 24, rx: 12, fill: "#F80022" }),
|
|
825
|
+
/* @__PURE__ */ jsx19("rect", { x: 8.25, y: 7.00195, width: 12.3744, height: 1.76777, rx: 0.883884, transform: "rotate(45 8.25 7.00195)", fill: "white" }),
|
|
826
|
+
/* @__PURE__ */ jsx19("rect", { x: 7, y: 15.752, width: 12.3744, height: 1.76777, rx: 0.883884, transform: "rotate(-45 7 15.752)", fill: "white" })
|
|
827
|
+
] });
|
|
828
|
+
var icon_close_default = SvgIconClose;
|
|
829
|
+
|
|
830
|
+
// packages/react-ui/src/assets/icons/icon-check-white.svg
|
|
831
|
+
import * as React12 from "react";
|
|
832
|
+
import { jsx as jsx20 } from "@emotion/react/jsx-runtime";
|
|
833
|
+
var SvgIconCheckWhite = (props) => /* @__PURE__ */ jsx20("svg", { width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsx20("g", { id: "Checkmark", children: /* @__PURE__ */ jsx20("path", { id: "Selected", fillRule: "evenodd", clipRule: "evenodd", d: "M24 12.002C24 18.6294 18.6274 24.002 12 24.002C5.37258 24.002 0 18.6294 0 12.002C0 5.37454 5.37258 0.00195312 12 0.00195312C18.6274 0.00195312 24 5.37454 24 12.002ZM17.4086 8.15357C16.94 7.68494 16.1802 7.68494 15.7116 8.15357L10.4072 14.9579L7.62573 13.1036C7.07429 12.736 6.32925 12.885 5.96163 13.4365C5.59401 13.9879 5.74301 14.7329 6.29445 15.1006L9.89445 17.5006C10.3704 17.8179 11.0041 17.7551 11.4086 17.3506L17.4086 9.85063C17.8772 9.382 17.8772 8.6222 17.4086 8.15357Z", fill: "#FFFFFF" }) }) });
|
|
834
|
+
var icon_check_white_default = SvgIconCheckWhite;
|
|
835
|
+
|
|
836
|
+
// packages/react-ui/src/lib/gamification/vote/components/voting-option/styles.tsx
|
|
837
|
+
import styled10 from "@emotion/styled";
|
|
838
|
+
var Container7 = styled10.div`
|
|
839
|
+
box-sizing: border-box;
|
|
840
|
+
border-radius: 4px;
|
|
841
|
+
height: 44px;
|
|
842
|
+
background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_ITEM_VOTE};
|
|
843
|
+
border: 2px solid transparent;
|
|
844
|
+
position: relative;
|
|
845
|
+
|
|
846
|
+
${(props) => !props.questionAnswered && `
|
|
847
|
+
&:hover {
|
|
848
|
+
border-color: inherit;
|
|
849
|
+
}
|
|
850
|
+
`}
|
|
851
|
+
`;
|
|
852
|
+
var AnsweredContainer = styled10(Container7)`
|
|
853
|
+
background-color: ${({ answeredCorrect, theme: theme2 }) => answeredCorrect ? theme2.COLORS.BG_TRANSPARENT_ITEM_SUCCESS : theme2.COLORS.BG_TRANSPARENT_ITEM_ERROR};
|
|
854
|
+
border: 2px solid;
|
|
855
|
+
border-color: ${({ answeredCorrect, theme: theme2 }) => answeredCorrect ? theme2.COLORS.BLUE_PRIMARY : theme2.COLORS.RED_PRIMARY};
|
|
856
|
+
|
|
857
|
+
&:hover {
|
|
858
|
+
border-color: ${({ answeredCorrect, theme: theme2 }) => answeredCorrect ? theme2.COLORS.BLUE_PRIMARY : theme2.COLORS.RED_PRIMARY};
|
|
859
|
+
}
|
|
860
|
+
`;
|
|
861
|
+
var ButtonPct = styled10.div`
|
|
862
|
+
position: absolute;
|
|
863
|
+
left: 0;
|
|
864
|
+
border-radius: 2px;
|
|
865
|
+
z-index: 0;
|
|
866
|
+
height: 100%;
|
|
867
|
+
background-color: inherit;
|
|
868
|
+
transition: all 1s ease-in;
|
|
869
|
+
`;
|
|
870
|
+
var Button = styled10.button`
|
|
871
|
+
border-radius: 20px;
|
|
872
|
+
position: relative;
|
|
873
|
+
background-color: transparent;
|
|
874
|
+
padding: 0px 16px;
|
|
875
|
+
display: flex;
|
|
876
|
+
align-items: center;
|
|
877
|
+
border: none;
|
|
878
|
+
outline: none;
|
|
879
|
+
width: 100%;
|
|
880
|
+
color: ${(props) => props.theme.COLORS.WHITE};
|
|
881
|
+
font-weight: 700;
|
|
882
|
+
font-size: 14px;
|
|
883
|
+
height: 100%;
|
|
884
|
+
border-radius: 2px;
|
|
885
|
+
cursor: pointer;
|
|
886
|
+
|
|
887
|
+
&:disabled {
|
|
888
|
+
cursor: default;
|
|
889
|
+
}
|
|
890
|
+
`;
|
|
891
|
+
var Icon2 = styled10.img`
|
|
892
|
+
width: 32px;
|
|
893
|
+
height: 32px;
|
|
894
|
+
border-radius: 50%;
|
|
895
|
+
margin-right: 8px;
|
|
896
|
+
`;
|
|
897
|
+
var Title5 = styled10.span`
|
|
898
|
+
overflow: hidden;
|
|
899
|
+
text-overflow: ellipsis;
|
|
900
|
+
white-space: nowrap;
|
|
901
|
+
padding: 8px 0px;
|
|
902
|
+
flex: 1;
|
|
903
|
+
text-align: left;
|
|
904
|
+
`;
|
|
905
|
+
var Indicators = styled10.span`
|
|
906
|
+
display: flex;
|
|
907
|
+
`;
|
|
908
|
+
var CheckIconWrap = styled10.div`
|
|
909
|
+
width: 16px;
|
|
910
|
+
height: 16px;
|
|
911
|
+
margin-left: 8px;
|
|
912
|
+
`;
|
|
913
|
+
var Percentage = styled10.div`
|
|
914
|
+
margin-left: 12px;
|
|
915
|
+
`;
|
|
916
|
+
var CheckIcon = styled10.img`
|
|
917
|
+
width: 16px;
|
|
918
|
+
height: 16px;
|
|
919
|
+
`;
|
|
920
|
+
|
|
921
|
+
// packages/react-ui/src/lib/gamification/vote/components/voting-option/index.tsx
|
|
922
|
+
import { jsx as jsx21, jsxs as jsxs12 } from "@emotion/react/jsx-runtime";
|
|
923
|
+
var VotingOption = ({
|
|
924
|
+
icon,
|
|
925
|
+
id,
|
|
926
|
+
title,
|
|
927
|
+
questionId,
|
|
928
|
+
disabled,
|
|
929
|
+
percentage,
|
|
930
|
+
onVote,
|
|
931
|
+
correct,
|
|
932
|
+
questionAnswered,
|
|
933
|
+
hasCorrectAnswer,
|
|
934
|
+
answered
|
|
935
|
+
}) => {
|
|
936
|
+
if (questionAnswered && answered) {
|
|
937
|
+
return /* @__PURE__ */ jsxs12(AnsweredContainer, { answeredCorrect: !hasCorrectAnswer || correct, questionAnswered: false, children: [
|
|
938
|
+
/* @__PURE__ */ jsx21(ButtonPct, { style: { width: `${percentage}%` } }),
|
|
939
|
+
/* @__PURE__ */ jsxs12(Button, { disabled, onClick: () => onVote(questionId, id), children: [
|
|
940
|
+
icon && /* @__PURE__ */ jsx21(Icon2, { alt: "option-icon", src: icon }),
|
|
941
|
+
/* @__PURE__ */ jsx21(Title5, { children: title }),
|
|
942
|
+
/* @__PURE__ */ jsxs12(Indicators, { children: [
|
|
943
|
+
hasCorrectAnswer && correct && /* @__PURE__ */ jsx21(CheckIconWrap, { children: /* @__PURE__ */ jsx21(CheckIcon, { alt: "icon-correct", src: answered ? icon_check_white_default : icon_check_default }) }),
|
|
944
|
+
/* @__PURE__ */ jsxs12(Percentage, { children: [
|
|
945
|
+
percentage,
|
|
946
|
+
"%"
|
|
947
|
+
] })
|
|
948
|
+
] })
|
|
949
|
+
] })
|
|
950
|
+
] });
|
|
951
|
+
}
|
|
952
|
+
return /* @__PURE__ */ jsxs12(Container7, { questionAnswered, children: [
|
|
953
|
+
questionAnswered && /* @__PURE__ */ jsx21(ButtonPct, { style: { width: `${percentage}%` } }),
|
|
954
|
+
/* @__PURE__ */ jsxs12(Button, { disabled, onClick: () => onVote(questionId, id), children: [
|
|
955
|
+
icon && /* @__PURE__ */ jsx21(Icon2, { alt: "option-icon", src: icon }),
|
|
956
|
+
/* @__PURE__ */ jsx21(Title5, { children: title }),
|
|
957
|
+
questionAnswered && /* @__PURE__ */ jsxs12(Indicators, { children: [
|
|
958
|
+
hasCorrectAnswer && correct && /* @__PURE__ */ jsx21(CheckIconWrap, { children: /* @__PURE__ */ jsx21(CheckIcon, { alt: "icon-correct", src: answered ? icon_check_white_default : icon_check_default }) }),
|
|
959
|
+
/* @__PURE__ */ jsxs12(Percentage, { children: [
|
|
960
|
+
percentage,
|
|
961
|
+
"%"
|
|
962
|
+
] })
|
|
963
|
+
] })
|
|
964
|
+
] })
|
|
965
|
+
] });
|
|
966
|
+
};
|
|
967
|
+
|
|
968
|
+
// packages/react-ui/src/lib/gamification/vote/styles.tsx
|
|
969
|
+
import styled11 from "@emotion/styled";
|
|
970
|
+
var Container8 = styled11.div`
|
|
971
|
+
padding: 16px;
|
|
972
|
+
color: ${(props) => props.theme.COLORS.WHITE};
|
|
973
|
+
font-weight: 700;
|
|
974
|
+
font-size: 14px;
|
|
975
|
+
|
|
976
|
+
& > div:not(:last-child) {
|
|
977
|
+
margin-bottom: 16px;
|
|
978
|
+
}
|
|
979
|
+
`;
|
|
980
|
+
var Title6 = styled11.div`
|
|
981
|
+
font-size: 16px;
|
|
982
|
+
`;
|
|
983
|
+
var Options = styled11.div`
|
|
984
|
+
overflow-y: auto;
|
|
985
|
+
max-height: 220px;
|
|
986
|
+
|
|
987
|
+
& > div:not(:last-child) {
|
|
988
|
+
margin-bottom: 12px;
|
|
989
|
+
}
|
|
990
|
+
`;
|
|
991
|
+
var Feedback = styled11.div`
|
|
992
|
+
padding: 14px 12px 14px 16px;
|
|
993
|
+
display: flex;
|
|
994
|
+
align-items: center;
|
|
995
|
+
`;
|
|
996
|
+
var FeedbackIcon = styled11.img`
|
|
997
|
+
width: 24px;
|
|
998
|
+
height: 24px;
|
|
999
|
+
margin-right: 12px;
|
|
1000
|
+
`;
|
|
1001
|
+
var FeedbackTitle = styled11.div`
|
|
1002
|
+
overflow: hidden;
|
|
1003
|
+
text-overflow: ellipsis;
|
|
1004
|
+
white-space: nowrap;
|
|
1005
|
+
font-size: 16;
|
|
1006
|
+
font-weight: 700;
|
|
1007
|
+
margin-bottom: 10px;
|
|
1008
|
+
`;
|
|
1009
|
+
var FeedbackDescription = styled11.div`
|
|
1010
|
+
display: -webkit-box;
|
|
1011
|
+
-webkit-box-orient: vertical;
|
|
1012
|
+
-webkit-line-clamp: 4;
|
|
1013
|
+
overflow: hidden;
|
|
1014
|
+
text-overflow: ellipsis;
|
|
1015
|
+
font-size: 14;
|
|
1016
|
+
font-weight: 500;
|
|
1017
|
+
`;
|
|
1018
|
+
|
|
1019
|
+
// packages/react-ui/src/lib/gamification/vote/index.tsx
|
|
1020
|
+
import { jsx as jsx22, jsxs as jsxs13 } from "@emotion/react/jsx-runtime";
|
|
1021
|
+
var Vote = ({
|
|
1022
|
+
title,
|
|
1023
|
+
questionId,
|
|
1024
|
+
options,
|
|
1025
|
+
questionAnswered,
|
|
1026
|
+
feedbackMessages,
|
|
1027
|
+
questionAnsweredCorrectly,
|
|
1028
|
+
questionType
|
|
1029
|
+
}) => {
|
|
1030
|
+
return /* @__PURE__ */ jsxs13(Container8, { children: [
|
|
1031
|
+
/* @__PURE__ */ jsx22(Title6, { children: title }),
|
|
1032
|
+
/* @__PURE__ */ jsx22(Options, { children: options.map((props) => /* @__PURE__ */ jsx22(VotingOption, { questionId, ...props }, props.id)) }),
|
|
1033
|
+
questionAnswered && questionType === QuestionType.TRIVIA && /* @__PURE__ */ jsxs13(Feedback, { children: [
|
|
1034
|
+
/* @__PURE__ */ jsx22(FeedbackIcon, { alt: "reaction-to-answer", src: questionAnsweredCorrectly ? icon_check_default : icon_close_default }),
|
|
1035
|
+
/* @__PURE__ */ jsxs13("div", { children: [
|
|
1036
|
+
/* @__PURE__ */ jsx22(FeedbackTitle, { children: questionAnsweredCorrectly ? feedbackMessages.correctFeedback.title : feedbackMessages.incorrectFeedback.title }),
|
|
1037
|
+
/* @__PURE__ */ jsx22(FeedbackDescription, { children: questionAnsweredCorrectly ? feedbackMessages.correctFeedback.description : feedbackMessages.incorrectFeedback.description })
|
|
1038
|
+
] })
|
|
1039
|
+
] })
|
|
1040
|
+
] });
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
// packages/react-ui/src/lib/demo/index.tsx
|
|
1044
|
+
import { useStore as useStore6 } from "@nanostores/react";
|
|
1045
|
+
|
|
1046
|
+
// packages/react-ui/src/lib/demo/Gamification.tsx
|
|
1047
|
+
import { useStore as useStore5 } from "@nanostores/react";
|
|
1048
|
+
|
|
1049
|
+
// packages/react-ui/src/lib/demo/components/UserSummary.tsx
|
|
1050
|
+
import { useStore } from "@nanostores/react";
|
|
1051
|
+
import { jsx as jsx23 } from "@emotion/react/jsx-runtime";
|
|
1052
|
+
var UserSummary = ({ store: store2 }) => {
|
|
1053
|
+
const { data: user } = useStore(store2);
|
|
1054
|
+
if (!user?.summary) {
|
|
1055
|
+
return /* @__PURE__ */ jsx23("div", { children: "wait user..." });
|
|
1056
|
+
}
|
|
1057
|
+
return /* @__PURE__ */ jsx23(
|
|
1058
|
+
UserStatistics,
|
|
1059
|
+
{
|
|
1060
|
+
avatar: user.summary.avatar,
|
|
1061
|
+
name: user.summary.name,
|
|
1062
|
+
points: user.summary.points,
|
|
1063
|
+
grade: "0",
|
|
1064
|
+
friendsRank: user.summary.friendsRank,
|
|
1065
|
+
globalRank: user.summary.rank,
|
|
1066
|
+
winStreak: user.summary.streak,
|
|
1067
|
+
correct: user.summary.correct,
|
|
1068
|
+
incorrect: user.summary.incorrect,
|
|
1069
|
+
successRate: user.percentage?.average
|
|
1070
|
+
}
|
|
1071
|
+
);
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
// packages/react-ui/src/lib/demo/components/QuestionsList.tsx
|
|
1075
|
+
import { useStore as useStore2 } from "@nanostores/react";
|
|
1076
|
+
import { jsx as jsx24 } from "@emotion/react/jsx-runtime";
|
|
1077
|
+
var QuestionsList = ({ store: store2, openQuestion }) => {
|
|
1078
|
+
const { data: questions } = useStore2(store2);
|
|
1079
|
+
if (!questions) {
|
|
1080
|
+
return /* @__PURE__ */ jsx24("div", { children: "wait questions..." });
|
|
1081
|
+
}
|
|
1082
|
+
return /* @__PURE__ */ jsx24(QuestionList, { openQuestion, questions });
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
// packages/react-ui/src/lib/demo/components/Question.tsx
|
|
1086
|
+
import styled14 from "@emotion/styled";
|
|
1087
|
+
import { useStore as useStore3 } from "@nanostores/react";
|
|
1088
|
+
import { useState as useState2, useCallback as useCallback2, useMemo } from "react";
|
|
1089
|
+
|
|
1090
|
+
// packages/react-ui/src/assets/icons/icon-trophy-green.svg
|
|
1091
|
+
import * as React13 from "react";
|
|
1092
|
+
import { jsx as jsx25 } from "@emotion/react/jsx-runtime";
|
|
1093
|
+
var SvgIconTrophyGreen = (props) => /* @__PURE__ */ jsx25("svg", { width: 12, height: 12, viewBox: "0 0 12 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsx25("g", { id: "Trophy", children: /* @__PURE__ */ jsx25("path", { id: "Combined Shape", fillRule: "evenodd", clipRule: "evenodd", d: "M2.76916 3.50002C2.76916 4.49786 2.94705 5.38348 3.30282 6.15692C2.62493 6.01847 2.05883 5.74872 1.6045 5.34768C1.15017 4.94663 0.923008 4.55992 0.923008 4.18752V3.50002H2.76916ZM11.0768 3.50002V4.18752C11.0768 4.55992 10.8497 4.94663 10.3953 5.34768C9.941 5.74872 9.3749 6.01847 8.69701 6.15692C9.05278 5.38348 9.23066 4.49786 9.23066 3.50002H11.0768ZM12 4.1875V3.27083C12 3.07986 11.9327 2.91754 11.7981 2.78385C11.6635 2.65017 11.5 2.58333 11.3077 2.58333H9.23077V1.89583C9.23077 1.58073 9.11779 1.31098 8.89183 1.08659C8.66586 0.862195 8.39423 0.75 8.07692 0.75H3.92308C3.60577 0.75 3.33414 0.862195 3.10817 1.08659C2.88221 1.31098 2.76923 1.58073 2.76923 1.89583V2.58333H0.692308C0.499999 2.58333 0.336539 2.65017 0.201923 2.78385C0.067307 2.91754 0 3.07986 0 3.27083V4.1875C0 4.52648 0.0997586 4.86784 0.299279 5.21159C0.498799 5.55534 0.768027 5.86567 1.10697 6.14258C1.44592 6.41949 1.86178 6.65223 2.35457 6.84082C2.84736 7.02941 3.36538 7.13563 3.90865 7.15951C4.11058 7.41732 4.33894 7.6441 4.59375 7.83984C4.77644 8.00217 4.90264 8.17524 4.97236 8.35905C5.04207 8.54286 5.07692 8.75651 5.07692 9C5.07692 9.25781 5.00361 9.47504 4.85697 9.65169C4.71034 9.82834 4.47596 9.91667 4.15385 9.91667C3.79327 9.91667 3.47236 10.0253 3.19111 10.2425C2.90985 10.4597 2.76923 10.7331 2.76923 11.0625V11.5208C2.76923 11.5877 2.79087 11.6426 2.83413 11.6855C2.8774 11.7285 2.93269 11.75 3 11.75H9C9.06731 11.75 9.1226 11.7285 9.16586 11.6855C9.20913 11.6426 9.23077 11.5877 9.23077 11.5208V11.0625C9.23077 10.7331 9.09015 10.4597 8.80889 10.2425C8.52764 10.0253 8.20673 9.91667 7.84615 9.91667C7.52404 9.91667 7.28966 9.82834 7.14303 9.65169C6.99639 9.47504 6.92308 9.25781 6.92308 9C6.92308 8.75651 6.95793 8.54286 7.02764 8.35905C7.09736 8.17524 7.22356 8.00217 7.40625 7.83984C7.66106 7.6441 7.88942 7.41732 8.09135 7.15951C8.63462 7.13563 9.15264 7.02941 9.64543 6.84082C10.1382 6.65223 10.5541 6.41949 10.893 6.14258C11.232 5.86567 11.5012 5.55534 11.7007 5.21159C11.9002 4.86784 12 4.52648 12 4.1875ZM5.07033 5.38491L6.0383 4.87503L7.00627 5.38491L6.8214 4.30497L7.60451 3.54016L6.52228 3.3826L6.0383 2.40003L5.55431 3.3826L4.47209 3.54016L5.25519 4.30497L5.07033 5.38491Z", fill: "white" }) }) });
|
|
1094
|
+
var icon_trophy_green_default = SvgIconTrophyGreen;
|
|
1095
|
+
|
|
1096
|
+
// packages/react-ui/src/assets/icons/icon-thumb-down.svg
|
|
1097
|
+
import * as React14 from "react";
|
|
1098
|
+
import { jsx as jsx26 } from "@emotion/react/jsx-runtime";
|
|
1099
|
+
var SvgIconThumbDown = (props) => /* @__PURE__ */ jsx26("svg", { xmlns: "http://www.w3.org/2000/svg", width: 22, height: 22, viewBox: "0 0 22 22", fill: "none", ...props, children: /* @__PURE__ */ jsx26("path", { d: "M5.5 2.78867V12.4137C5.5 13.1729 4.88426 13.75 4.125 13.75H1.375C0.615742 13.75 0 13.1343 0 12.4137V2.82734C0 2.06808 0.615742 1.49102 1.375 1.49102H4.125C4.88555 1.41367 5.5 1.99375 5.5 2.78867ZM22 12.3707C22 13.5094 21.077 14.4323 19.9375 14.4323H13.6426C14.621 16.0613 15.1259 17.9077 15.1259 18.5582C15.125 19.5714 14.3301 20.625 12.998 20.625C10.2854 20.625 11.8654 17.3529 8.34883 14.5406L7.64844 13.982C7.14141 13.5738 6.88359 12.9766 6.8793 12.375C6.87829 12.374 6.8793 12.375 6.8793 12.375L6.875 5.5C6.875 4.85117 7.18064 4.23973 7.7 3.85043L9.16695 2.75086C10.3555 1.85625 11.8035 1.375 13.2902 1.375H15.8125C16.952 1.375 17.875 2.29754 17.875 3.43664C17.875 3.59283 17.8544 3.74357 17.8215 3.88996C18.6484 4.15937 19.25 4.92422 19.25 5.84375C19.25 6.23683 19.1341 6.60043 18.9432 6.91281C19.8988 7.08984 20.625 7.92773 20.625 8.9332C20.625 9.47031 20.4148 9.955 20.0784 10.322C21.1492 10.3941 22 11.2793 22 12.3707Z", fill: "white" }) });
|
|
1100
|
+
var icon_thumb_down_default = SvgIconThumbDown;
|
|
1101
|
+
|
|
1102
|
+
// packages/react-ui/src/lib/gamification/vote/components/voting-header/styles.tsx
|
|
1103
|
+
import styled12 from "@emotion/styled";
|
|
1104
|
+
var Container9 = styled12.div`
|
|
1105
|
+
box-sizing: border-box;
|
|
1106
|
+
background-color: transparent;
|
|
1107
|
+
color: ${(props) => props.theme.COLORS.WHITE};
|
|
1108
|
+
display: flex;
|
|
1109
|
+
flex-direction: row-reverse;
|
|
1110
|
+
justify-content: space-between;
|
|
1111
|
+
padding: 0px 16px;
|
|
1112
|
+
align-items: center;
|
|
1113
|
+
`;
|
|
1114
|
+
var Logo = styled12.img`
|
|
1115
|
+
width: 60px;
|
|
1116
|
+
height: 80%;
|
|
1117
|
+
`;
|
|
1118
|
+
var RightBlock = styled12.div`
|
|
1119
|
+
display: flex;
|
|
1120
|
+
align-items: center;
|
|
1121
|
+
`;
|
|
1122
|
+
var ExitBtn = styled12.button`
|
|
1123
|
+
border: none;
|
|
1124
|
+
outline: none;
|
|
1125
|
+
background-color: transparent;
|
|
1126
|
+
border-radius: 50%;
|
|
1127
|
+
padding: 0px;
|
|
1128
|
+
width: 24px;
|
|
1129
|
+
height: 24px;
|
|
1130
|
+
margin-left: 25px;
|
|
1131
|
+
cursor: pointer;
|
|
1132
|
+
`;
|
|
1133
|
+
var ExitIcon = styled12.img`
|
|
1134
|
+
width: 24px;
|
|
1135
|
+
height: 24px;
|
|
1136
|
+
`;
|
|
1137
|
+
var Interactive = styled12.div`
|
|
1138
|
+
display: flex;
|
|
1139
|
+
align-items: center;
|
|
1140
|
+
padding: 4px 0px;
|
|
1141
|
+
margin-left: 10px;
|
|
1142
|
+
`;
|
|
1143
|
+
var ReactionIconWrap = styled12.div`
|
|
1144
|
+
background-color: ${(props) => props.isSuccess ? "#f1be1c" : "#da3732"};
|
|
1145
|
+
width: 32px;
|
|
1146
|
+
height: 32px;
|
|
1147
|
+
border-radius: 50%;
|
|
1148
|
+
display: flex;
|
|
1149
|
+
justify-content: center;
|
|
1150
|
+
align-items: center;
|
|
1151
|
+
`;
|
|
1152
|
+
var ReactionIcon = styled12.img`
|
|
1153
|
+
width: 20px;
|
|
1154
|
+
height: 20px;
|
|
1155
|
+
`;
|
|
1156
|
+
|
|
1157
|
+
// packages/react-ui/src/lib/gamification/vote/components/voting-header/components/points/styles.tsx
|
|
1158
|
+
import styled13 from "@emotion/styled";
|
|
1159
|
+
var Container10 = styled13.div`
|
|
1160
|
+
display: flex;
|
|
1161
|
+
flex-direction: column;
|
|
1162
|
+
align-items: flex-end;
|
|
1163
|
+
margin-right: 10px;
|
|
1164
|
+
font-weight: 700;
|
|
1165
|
+
`;
|
|
1166
|
+
var Title7 = styled13.div`
|
|
1167
|
+
color: rgba(255, 255, 255, 0.8);
|
|
1168
|
+
font-size: 8px;
|
|
1169
|
+
line-height: 12px;
|
|
1170
|
+
text-align: right;
|
|
1171
|
+
`;
|
|
1172
|
+
var PointContainer = styled13.div`
|
|
1173
|
+
text-align: right;
|
|
1174
|
+
`;
|
|
1175
|
+
var Point = styled13.span`
|
|
1176
|
+
color: rgba(255, 255, 255, 0.9);
|
|
1177
|
+
font-size: 14px;
|
|
1178
|
+
line-height: 16px;
|
|
1179
|
+
margin-right: 2px;
|
|
1180
|
+
`;
|
|
1181
|
+
var PointLabel = styled13.span`
|
|
1182
|
+
color: white;
|
|
1183
|
+
font-size: 10px;
|
|
1184
|
+
font-weight: 600;
|
|
1185
|
+
line-height: 16px;
|
|
1186
|
+
`;
|
|
1187
|
+
|
|
1188
|
+
// packages/react-ui/src/lib/gamification/vote/components/voting-header/components/points/index.tsx
|
|
1189
|
+
import { jsx as jsx27, jsxs as jsxs14 } from "@emotion/react/jsx-runtime";
|
|
1190
|
+
var Points = ({ points }) => /* @__PURE__ */ jsxs14(Container10, { children: [
|
|
1191
|
+
/* @__PURE__ */ jsx27(Title7, { children: "YOU WON" }),
|
|
1192
|
+
/* @__PURE__ */ jsxs14(PointContainer, { children: [
|
|
1193
|
+
/* @__PURE__ */ jsx27(Point, { children: points }),
|
|
1194
|
+
/* @__PURE__ */ jsx27(PointLabel, { children: "PTS" })
|
|
1195
|
+
] })
|
|
1196
|
+
] });
|
|
1197
|
+
|
|
1198
|
+
// packages/react-ui/src/lib/gamification/vote/components/voting-header/index.tsx
|
|
1199
|
+
import { Fragment, jsx as jsx28, jsxs as jsxs15 } from "@emotion/react/jsx-runtime";
|
|
1200
|
+
var VotingHeader = ({
|
|
1201
|
+
logo,
|
|
1202
|
+
points,
|
|
1203
|
+
questionAnswered,
|
|
1204
|
+
questionAnsweredCorrectly,
|
|
1205
|
+
questionType,
|
|
1206
|
+
closeQuestion,
|
|
1207
|
+
setTimeToExpire
|
|
1208
|
+
}) => {
|
|
1209
|
+
const isShowTimer = !questionAnswered && questionType !== QuestionType.PREDICTION;
|
|
1210
|
+
const isShowTriviaFeedback = questionAnswered && questionType === QuestionType.TRIVIA;
|
|
1211
|
+
const successTriviaFeedback = isShowTriviaFeedback && questionAnsweredCorrectly;
|
|
1212
|
+
const errorTriviaFeedback = isShowTriviaFeedback && !questionAnsweredCorrectly;
|
|
1213
|
+
const isShowPredictionFeedback = questionAnswered && questionType === QuestionType.PREDICTION;
|
|
1214
|
+
return /* @__PURE__ */ jsxs15(Container9, { children: [
|
|
1215
|
+
/* @__PURE__ */ jsxs15(RightBlock, { children: [
|
|
1216
|
+
/* @__PURE__ */ jsxs15(Interactive, { children: [
|
|
1217
|
+
isShowTimer && /* @__PURE__ */ jsx28(Timer, { setTimeToExpire }),
|
|
1218
|
+
successTriviaFeedback && /* @__PURE__ */ jsxs15(Fragment, { children: [
|
|
1219
|
+
/* @__PURE__ */ jsx28(Points, { points }),
|
|
1220
|
+
/* @__PURE__ */ jsx28(ReactionIconWrap, { isSuccess: true, children: /* @__PURE__ */ jsx28(ReactionIcon, { alt: "reaction-icon", src: icon_trophy_green_default }) })
|
|
1221
|
+
] }),
|
|
1222
|
+
errorTriviaFeedback && /* @__PURE__ */ jsxs15(Fragment, { children: [
|
|
1223
|
+
/* @__PURE__ */ jsx28(Points, { points: 0 }),
|
|
1224
|
+
/* @__PURE__ */ jsx28(ReactionIconWrap, { isSuccess: false, children: /* @__PURE__ */ jsx28(ReactionIcon, { alt: "reaction-icon", src: icon_thumb_down_default }) })
|
|
1225
|
+
] }),
|
|
1226
|
+
isShowPredictionFeedback && /* @__PURE__ */ jsx28(Points, { points })
|
|
1227
|
+
] }),
|
|
1228
|
+
/* @__PURE__ */ jsx28(ExitBtn, { onClick: closeQuestion, children: /* @__PURE__ */ jsx28(ExitIcon, { alt: "exit-icon", src: icon_exit_default }) })
|
|
1229
|
+
] }),
|
|
1230
|
+
logo && /* @__PURE__ */ jsx28(Logo, { src: logo })
|
|
1231
|
+
] });
|
|
1232
|
+
};
|
|
1233
|
+
|
|
1234
|
+
// packages/react-ui/src/assets/icons/fedex.svg
|
|
1235
|
+
import * as React15 from "react";
|
|
1236
|
+
import { jsx as jsx29, jsxs as jsxs16 } from "@emotion/react/jsx-runtime";
|
|
1237
|
+
var SvgFedex = (props) => /* @__PURE__ */ jsx29("svg", { width: 68, height: 22, viewBox: "0 0 68 22", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsxs16("g", { id: "Vector", children: [
|
|
1238
|
+
/* @__PURE__ */ jsx29("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M56.6155 7.44146H50.7066L56.3072 13.8615L50.7066 20.2805H56.4357L59.1587 17.137L61.9068 20.2805H67.84L62.19 13.8348L67.7636 7.44146H62.0606L59.3897 10.5602L56.6155 7.44146ZM62.2721 7.91659L59.3964 11.2747L56.4092 7.91659H51.7446L56.9307 13.8615L51.7447 19.8054H56.2257L59.1571 16.4213L62.1156 19.8054H66.7987L61.566 13.8357L66.7261 7.91659H62.2721Z", fill: "white" }),
|
|
1239
|
+
/* @__PURE__ */ jsx29("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M44.3635 7.44146V4.56406H50.7066V0.0559998H39.702V20.2805H50.7066V15.7601H44.3635V11.7794H50.7066V7.44146H44.3635ZM50.2408 7.91659H43.8978V4.08893H50.2408V0.531132H40.1678V19.8054H50.2408V16.2352H43.8978V11.3043H50.2408V7.91659Z", fill: "white" }),
|
|
1240
|
+
/* @__PURE__ */ jsx29("path", { d: "M35.06 0.0559998V8.33281H35.0087C33.9803 7.12787 32.6966 6.70881 31.207 6.70881C28.1552 6.70881 25.8561 8.826 25.0493 11.6236C24.128 8.54092 21.7544 6.65084 18.2349 6.65084C15.3769 6.65084 13.1197 7.95936 11.9422 10.0918V7.44146H6.03416V4.56406H12.4815V0.0559998H0.768005V20.2805H6.03416V11.7794H11.2836C11.127 12.4037 11.0432 13.0727 11.0432 13.7788C11.0432 17.997 14.2031 20.958 18.2349 20.958C21.6258 20.958 23.8607 19.334 25.0419 16.374H20.5284C19.9183 17.2644 19.4553 17.5276 18.2349 17.5276C16.8199 17.5276 15.5995 16.2685 15.5995 14.7756H24.7894C25.1881 18.1262 27.7472 21.016 31.2582 21.016C32.773 21.016 34.1601 20.2558 35.0078 18.9729H35.059V20.2824H39.701L39.702 0.0559998H35.06ZM15.7467 11.8393C16.0392 10.5545 17.0164 9.71545 18.2358 9.71545C19.5782 9.71545 20.5051 10.5289 20.7492 11.8393C20.8517 11.8393 15.7467 11.8393 15.7467 11.8393ZM32.242 17.2016C30.5307 17.2016 29.4668 15.5748 29.4668 13.8767C29.4668 12.0617 30.3919 10.316 32.242 10.316C34.1601 10.316 34.924 12.0617 34.924 13.8767C34.924 15.5976 34.1144 17.2016 32.242 17.2016Z", fill: "white" })
|
|
1241
|
+
] }) });
|
|
1242
|
+
var fedex_default = SvgFedex;
|
|
1243
|
+
|
|
1244
|
+
// packages/react-ui/src/lib/demo/components/Question.tsx
|
|
1245
|
+
import { jsx as jsx30, jsxs as jsxs17 } from "@emotion/react/jsx-runtime";
|
|
1246
|
+
var QuestionContainer = styled14.div`
|
|
1247
|
+
position: absolute;
|
|
1248
|
+
top: 0;
|
|
1249
|
+
background: ${(props) => props.theme.COLORS.BG_TRANSPARENT_ITEM};
|
|
1250
|
+
width: 100%;
|
|
1251
|
+
height: 100%;
|
|
1252
|
+
|
|
1253
|
+
display: flex;
|
|
1254
|
+
align-items: center;
|
|
1255
|
+
justify-content: center;
|
|
1256
|
+
flex-direction: column;
|
|
1257
|
+
|
|
1258
|
+
> div {
|
|
1259
|
+
width: 100%;
|
|
1260
|
+
background: #000;
|
|
1261
|
+
animation: slidein 0.3s ease-in;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
@keyframes slidein {
|
|
1265
|
+
from {
|
|
1266
|
+
transform: translateX(-100%);
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
to {
|
|
1270
|
+
transform: translateX(0);
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
`;
|
|
1274
|
+
var Question2 = ({ store: store2, closeQuestion, vote }) => {
|
|
1275
|
+
const { data: openedQuestion } = useStore3(store2);
|
|
1276
|
+
const [answerTimeExpired, setAnswerTimeExpired] = useState2(false);
|
|
1277
|
+
const setTimeToExpire = useCallback2(
|
|
1278
|
+
(flag) => {
|
|
1279
|
+
setAnswerTimeExpired(flag);
|
|
1280
|
+
},
|
|
1281
|
+
[setAnswerTimeExpired]
|
|
1282
|
+
);
|
|
1283
|
+
const questionAnswered = useMemo(
|
|
1284
|
+
() => openedQuestion?.answers.find((answer) => answer.youVoted === true),
|
|
1285
|
+
[openedQuestion]
|
|
1286
|
+
);
|
|
1287
|
+
const hasCorrectAnswer = useMemo(
|
|
1288
|
+
() => !!openedQuestion?.answers.find((answer) => answer.correct === true),
|
|
1289
|
+
[openedQuestion]
|
|
1290
|
+
);
|
|
1291
|
+
if (!openedQuestion) {
|
|
1292
|
+
return null;
|
|
1293
|
+
}
|
|
1294
|
+
return /* @__PURE__ */ jsx30(QuestionContainer, { children: /* @__PURE__ */ jsxs17("div", { children: [
|
|
1295
|
+
/* @__PURE__ */ jsx30(
|
|
1296
|
+
VotingHeader,
|
|
1297
|
+
{
|
|
1298
|
+
points: questionAnswered?.points || 0,
|
|
1299
|
+
questionAnswered: !!questionAnswered,
|
|
1300
|
+
questionAnsweredCorrectly: questionAnswered?.correct,
|
|
1301
|
+
logo: fedex_default,
|
|
1302
|
+
closeQuestion,
|
|
1303
|
+
setTimeToExpire,
|
|
1304
|
+
questionType: openedQuestion.type
|
|
1305
|
+
}
|
|
1306
|
+
),
|
|
1307
|
+
/* @__PURE__ */ jsx30("div", { children: /* @__PURE__ */ jsx30(
|
|
1308
|
+
Vote,
|
|
1309
|
+
{
|
|
1310
|
+
title: openedQuestion.subject,
|
|
1311
|
+
feedbackMessages: openedQuestion.options?.options.value,
|
|
1312
|
+
questionType: openedQuestion.type,
|
|
1313
|
+
questionId: openedQuestion.id,
|
|
1314
|
+
questionAnswered: !!questionAnswered,
|
|
1315
|
+
questionAnsweredCorrectly: questionAnswered?.correct,
|
|
1316
|
+
options: openedQuestion.answers.map((answer) => ({
|
|
1317
|
+
id: answer.id,
|
|
1318
|
+
title: answer.text,
|
|
1319
|
+
icon: answer.icon,
|
|
1320
|
+
type: openedQuestion.type,
|
|
1321
|
+
correct: answer.correct,
|
|
1322
|
+
percentage: answer.percentage,
|
|
1323
|
+
answered: answer.youVoted,
|
|
1324
|
+
disabled: !!questionAnswered || openedQuestion.marketClosed || answerTimeExpired,
|
|
1325
|
+
questionAnswered: !!questionAnswered,
|
|
1326
|
+
hasCorrectAnswer,
|
|
1327
|
+
onVote: vote
|
|
1328
|
+
}))
|
|
1329
|
+
}
|
|
1330
|
+
) })
|
|
1331
|
+
] }) });
|
|
1332
|
+
};
|
|
1333
|
+
|
|
1334
|
+
// packages/react-ui/src/lib/demo/components/Notifications.tsx
|
|
1335
|
+
import { useStore as useStore4 } from "@nanostores/react";
|
|
1336
|
+
import { useEffect as useEffect2, useRef, useState as useState3 } from "react";
|
|
1337
|
+
import { jsx as jsx31 } from "@emotion/react/jsx-runtime";
|
|
1338
|
+
var Notifications = ({ notificationsStore, openQuestion }) => {
|
|
1339
|
+
const timeout = useRef();
|
|
1340
|
+
const [lastNotification, setLastNotification] = useState3();
|
|
1341
|
+
const notifications2 = useStore4(notificationsStore);
|
|
1342
|
+
useEffect2(() => {
|
|
1343
|
+
if (notifications2) {
|
|
1344
|
+
setLastNotification(notifications2[notifications2.length - 1]?.data);
|
|
1345
|
+
timeout.current = setTimeout(() => {
|
|
1346
|
+
setLastNotification(void 0);
|
|
1347
|
+
}, 5e3);
|
|
1348
|
+
}
|
|
1349
|
+
return () => {
|
|
1350
|
+
if (timeout.current) {
|
|
1351
|
+
clearTimeout(timeout.current);
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
}, [notifications2]);
|
|
1355
|
+
if (!lastNotification?.question || !lastNotification?.notification) {
|
|
1356
|
+
return null;
|
|
1357
|
+
}
|
|
1358
|
+
const closeInApp = () => {
|
|
1359
|
+
if (timeout.current) {
|
|
1360
|
+
clearTimeout(timeout.current);
|
|
1361
|
+
}
|
|
1362
|
+
setLastNotification(void 0);
|
|
1363
|
+
};
|
|
1364
|
+
const openVoiting = () => {
|
|
1365
|
+
closeInApp();
|
|
1366
|
+
openQuestion(lastNotification.question.id);
|
|
1367
|
+
};
|
|
1368
|
+
return /* @__PURE__ */ jsx31(
|
|
1369
|
+
InApp,
|
|
1370
|
+
{
|
|
1371
|
+
openVoiting,
|
|
1372
|
+
closeInApp,
|
|
1373
|
+
title: lastNotification.notification.title,
|
|
1374
|
+
icon: lastNotification.notification.image,
|
|
1375
|
+
color: lastNotification.notification.indicatorColor
|
|
1376
|
+
}
|
|
1377
|
+
);
|
|
1378
|
+
};
|
|
1379
|
+
|
|
1380
|
+
// packages/react-ui/src/lib/demo/components/InPlayGame.tsx
|
|
1381
|
+
import { jsx as jsx32 } from "@emotion/react/jsx-runtime";
|
|
1382
|
+
var InPlayGame = ({ action }) => {
|
|
1383
|
+
return /* @__PURE__ */ jsx32(Onboarding, { action });
|
|
1384
|
+
};
|
|
1385
|
+
|
|
1386
|
+
// packages/react-ui/src/lib/demo/styles.tsx
|
|
1387
|
+
import styled15 from "@emotion/styled";
|
|
1388
|
+
var DemoContainer = styled15.div`
|
|
1389
|
+
position: relative;
|
|
1390
|
+
height: 100%;
|
|
1391
|
+
overflow: hidden;
|
|
1392
|
+
`;
|
|
1393
|
+
var DemoContainerNotifications = styled15.div`
|
|
1394
|
+
position: absolute;
|
|
1395
|
+
width: 100%;
|
|
1396
|
+
`;
|
|
1397
|
+
var UserStatisticsContainer = styled15.div`
|
|
1398
|
+
margin-bottom: 15px;
|
|
1399
|
+
`;
|
|
1400
|
+
|
|
1401
|
+
// packages/react-ui/src/lib/demo/Gamification.tsx
|
|
1402
|
+
import { jsx as jsx33, jsxs as jsxs18 } from "@emotion/react/jsx-runtime";
|
|
1403
|
+
var GamificationComponent = ({
|
|
1404
|
+
gamification,
|
|
1405
|
+
sdk
|
|
1406
|
+
}) => {
|
|
1407
|
+
const onbordingComplete = useStore5(gamification.onbordingComplete);
|
|
1408
|
+
if (!onbordingComplete) {
|
|
1409
|
+
return /* @__PURE__ */ jsx33(DemoContainer, { children: /* @__PURE__ */ jsx33(InPlayGame, { action: gamification.submitInplay }) });
|
|
1410
|
+
}
|
|
1411
|
+
const openQuestion = (questionId) => {
|
|
1412
|
+
gamification.openQuestion(questionId);
|
|
1413
|
+
};
|
|
1414
|
+
const closeQuestion = () => {
|
|
1415
|
+
gamification.closeQuestion();
|
|
1416
|
+
};
|
|
1417
|
+
const vote = (questionId, answerId) => {
|
|
1418
|
+
void gamification.submitAnswer(questionId, answerId);
|
|
1419
|
+
};
|
|
1420
|
+
return /* @__PURE__ */ jsxs18(DemoContainer, { children: [
|
|
1421
|
+
/* @__PURE__ */ jsx33(DemoContainerNotifications, { children: /* @__PURE__ */ jsx33(Notifications, { notificationsStore: sdk.getNotificationsStore(), openQuestion }) }),
|
|
1422
|
+
/* @__PURE__ */ jsx33(UserStatisticsContainer, { children: gamification.userSummary && /* @__PURE__ */ jsx33(UserSummary, { store: gamification.userSummary.getStore() }) }),
|
|
1423
|
+
gamification.questions && /* @__PURE__ */ jsx33(QuestionsList, { openQuestion, store: gamification.questions.getStore() }),
|
|
1424
|
+
gamification.openedQuestion && /* @__PURE__ */ jsx33(Question2, { closeQuestion, vote, store: gamification.openedQuestion.getStore() })
|
|
1425
|
+
] });
|
|
1426
|
+
};
|
|
1427
|
+
|
|
1428
|
+
// packages/react-ui/src/lib/demo/Login.tsx
|
|
1429
|
+
import { jsx as jsx34 } from "@emotion/react/jsx-runtime";
|
|
1430
|
+
var LoginComponent = ({ sdk }) => {
|
|
1431
|
+
const login2 = async (token) => {
|
|
1432
|
+
try {
|
|
1433
|
+
await sdk.authorizationBypass("streamlayer:streamlayer", token);
|
|
1434
|
+
} catch (err) {
|
|
1435
|
+
console.log("login err", err);
|
|
1436
|
+
throw err;
|
|
1437
|
+
}
|
|
1438
|
+
};
|
|
1439
|
+
return /* @__PURE__ */ jsx34(Login, { login: login2, anonymousLogin: sdk.anonymousAuthorization });
|
|
1440
|
+
};
|
|
1441
|
+
|
|
1442
|
+
// packages/react-ui/src/lib/demo/index.tsx
|
|
1443
|
+
import { jsx as jsx35 } from "@emotion/react/jsx-runtime";
|
|
1444
|
+
var Demo = ({ sdk }) => {
|
|
1445
|
+
const user = useStore6(sdk.getUserStore());
|
|
1446
|
+
if (user.loading) {
|
|
1447
|
+
return /* @__PURE__ */ jsx35("div", { children: "authentificating..." });
|
|
1448
|
+
}
|
|
1449
|
+
if (!user.data) {
|
|
1450
|
+
return /* @__PURE__ */ jsx35(LoginComponent, { sdk });
|
|
1451
|
+
}
|
|
1452
|
+
const gamification = sdk.getFeatures().get("games");
|
|
1453
|
+
if (!gamification) {
|
|
1454
|
+
return /* @__PURE__ */ jsx35("div", { children: "wait gamification..." });
|
|
1455
|
+
}
|
|
1456
|
+
return /* @__PURE__ */ jsx35(GamificationComponent, { gamification, sdk });
|
|
1457
|
+
};
|
|
1458
|
+
|
|
1459
|
+
// packages/react-ui/src/lib/theme/index.tsx
|
|
1460
|
+
import { ThemeProvider } from "@emotion/react";
|
|
1461
|
+
import { jsx as jsx36 } from "@emotion/react/jsx-runtime";
|
|
1462
|
+
var StreamLayerThemeProvider = ({ children }) => /* @__PURE__ */ jsx36(ThemeProvider, { theme, children });
|
|
1463
|
+
|
|
1464
|
+
// packages/react/src/app/provider.tsx
|
|
1465
|
+
import { createContext, useMemo as useMemo2 } from "react";
|
|
1466
|
+
|
|
1467
|
+
// packages/sdk-web-interfaces/src/auth.ts
|
|
1468
|
+
var AbstractAuthenticationProvider = class {
|
|
1469
|
+
};
|
|
1470
|
+
|
|
1471
|
+
// packages/sdk-web-interfaces/src/feature.ts
|
|
1472
|
+
import { SdkOverlayType as SdkOverlayType2 } from "@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb";
|
|
1473
|
+
import { atom } from "nanostores";
|
|
1474
|
+
|
|
1475
|
+
// packages/sdk-web-interfaces/src/store/map.ts
|
|
1476
|
+
import { map } from "nanostores";
|
|
1477
|
+
|
|
1478
|
+
// packages/sdk-web-interfaces/src/store/abstract.ts
|
|
1479
|
+
import { computed } from "nanostores";
|
|
1480
|
+
import { buildLogger } from "@nanostores/logger";
|
|
1481
|
+
import diff from "microdiff";
|
|
1482
|
+
window.storeLogger = /* @__PURE__ */ Object.create(null);
|
|
1483
|
+
var slStoreLogger = (store2, name) => buildLogger(store2, name, {
|
|
1484
|
+
mount: ({ storeName }) => {
|
|
1485
|
+
if (!window.storeLogger[storeName]) {
|
|
1486
|
+
window.storeLogger[storeName] = { mounted: true, history: [{ type: "mount" }] };
|
|
1487
|
+
}
|
|
1488
|
+
window.storeLogger[storeName].store = store2;
|
|
1489
|
+
},
|
|
1490
|
+
unmount: ({ storeName }) => {
|
|
1491
|
+
window.storeLogger[storeName].mounted = false;
|
|
1492
|
+
window.storeLogger[storeName]?.history.push({ type: "unmount" });
|
|
1493
|
+
},
|
|
1494
|
+
change: ({ actionName, storeName, changed, newValue, oldValue, valueMessage }) => {
|
|
1495
|
+
window.storeLogger[storeName]?.history.push({
|
|
1496
|
+
type: "change",
|
|
1497
|
+
changed,
|
|
1498
|
+
newValue,
|
|
1499
|
+
oldValue,
|
|
1500
|
+
diff: diff({ ...oldValue }, { ...newValue }, { cyclesFix: false }),
|
|
1501
|
+
actionName,
|
|
1502
|
+
valueMessage
|
|
1503
|
+
});
|
|
1504
|
+
},
|
|
1505
|
+
action: {
|
|
1506
|
+
start: ({ actionName, args, storeName }) => {
|
|
1507
|
+
window.storeLogger[storeName]?.history.push({
|
|
1508
|
+
type: "action:start",
|
|
1509
|
+
actionName,
|
|
1510
|
+
args,
|
|
1511
|
+
storeName
|
|
1512
|
+
});
|
|
1513
|
+
},
|
|
1514
|
+
error: ({ actionName, error, storeName }) => {
|
|
1515
|
+
window.storeLogger[storeName]?.history.push({
|
|
1516
|
+
type: "action:error",
|
|
1517
|
+
actionName,
|
|
1518
|
+
error
|
|
1519
|
+
});
|
|
1520
|
+
},
|
|
1521
|
+
end: ({ actionName, storeName }) => {
|
|
1522
|
+
window.storeLogger[storeName]?.history.push({
|
|
1523
|
+
type: "action:end",
|
|
1524
|
+
actionName
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
});
|
|
1529
|
+
var AbstractStore = class {
|
|
1530
|
+
/**
|
|
1531
|
+
* store instance (nanostores)
|
|
1532
|
+
*/
|
|
1533
|
+
store;
|
|
1534
|
+
name;
|
|
1535
|
+
constructor(store2, name) {
|
|
1536
|
+
this.store = store2;
|
|
1537
|
+
this.name = name;
|
|
1538
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1539
|
+
slStoreLogger(this.store, this.name);
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
/**
|
|
1543
|
+
* return store instance
|
|
1544
|
+
*/
|
|
1545
|
+
getStore() {
|
|
1546
|
+
return this.store;
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
var mergeStores = (stores) => {
|
|
1550
|
+
const storeKeys = Object.keys(stores);
|
|
1551
|
+
return computed(
|
|
1552
|
+
storeKeys.map((key) => stores[key].getStore()),
|
|
1553
|
+
(...storeValues) => Object.fromEntries(storeKeys.map((key, i) => [key, storeValues[i]]))
|
|
1554
|
+
);
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
// packages/sdk-web-interfaces/src/store/map.ts
|
|
1558
|
+
var MapStore = class extends AbstractStore {
|
|
1559
|
+
getValues = () => {
|
|
1560
|
+
const store2 = this.getStore();
|
|
1561
|
+
return store2.get();
|
|
1562
|
+
};
|
|
1563
|
+
getValue = (key) => {
|
|
1564
|
+
const store2 = this.getStore();
|
|
1565
|
+
return store2.get()[key];
|
|
1566
|
+
};
|
|
1567
|
+
setValue = (path, value) => {
|
|
1568
|
+
const store2 = this.getStore();
|
|
1569
|
+
return store2.setKey(path, value);
|
|
1570
|
+
};
|
|
1571
|
+
subscribe = (...args) => {
|
|
1572
|
+
const store2 = this.getStore();
|
|
1573
|
+
return store2.subscribe(...args);
|
|
1574
|
+
};
|
|
1575
|
+
unsubscribe = () => {
|
|
1576
|
+
const store2 = this.getStore();
|
|
1577
|
+
return store2.off();
|
|
1578
|
+
};
|
|
1579
|
+
};
|
|
1580
|
+
var createMapStore = (initialData) => {
|
|
1581
|
+
return map(initialData);
|
|
1582
|
+
};
|
|
1583
|
+
|
|
1584
|
+
// packages/sdk-web-interfaces/src/feature.ts
|
|
1585
|
+
var FeatureTypes = {
|
|
1586
|
+
[SdkOverlayType2.BETTING]: "betting",
|
|
1587
|
+
[SdkOverlayType2.GAMES]: "games",
|
|
1588
|
+
[SdkOverlayType2.PUBLIC_CHAT]: "publicChat",
|
|
1589
|
+
[SdkOverlayType2.TWITTER]: "twitter"
|
|
1590
|
+
};
|
|
1591
|
+
var AbstractFeature = class {
|
|
1592
|
+
status;
|
|
1593
|
+
source;
|
|
1594
|
+
config;
|
|
1595
|
+
settings;
|
|
1596
|
+
listeners = /* @__PURE__ */ new Set();
|
|
1597
|
+
settingsKey;
|
|
1598
|
+
constructor({ settings, ...config }, source) {
|
|
1599
|
+
this.settingsKey = FeatureTypes[config.type];
|
|
1600
|
+
this.status = atom("suspended" /* Suspended */);
|
|
1601
|
+
this.config = new MapStore(createMapStore(config), `feature:config:${this.settingsKey}`);
|
|
1602
|
+
if (this.settingsKey !== void 0 && settings?.overlaySettings.case === this.settingsKey) {
|
|
1603
|
+
this.settings = new MapStore(
|
|
1604
|
+
createMapStore(settings.overlaySettings.value),
|
|
1605
|
+
`feature:settings:${this.settingsKey}`
|
|
1606
|
+
);
|
|
1607
|
+
} else {
|
|
1608
|
+
this.settings = new MapStore(createMapStore({}), `feature:settings:${this.settingsKey}`);
|
|
1609
|
+
}
|
|
1610
|
+
this.source = source;
|
|
1611
|
+
}
|
|
1612
|
+
get featureConfig() {
|
|
1613
|
+
return this.config.getStore();
|
|
1614
|
+
}
|
|
1615
|
+
get featureSettings() {
|
|
1616
|
+
return this.settings.getStore();
|
|
1617
|
+
}
|
|
1618
|
+
registerEventListener(listener) {
|
|
1619
|
+
this.listeners.add(listener);
|
|
1620
|
+
}
|
|
1621
|
+
enable = () => {
|
|
1622
|
+
this.status.set("ready" /* Ready */);
|
|
1623
|
+
};
|
|
1624
|
+
disabled = () => {
|
|
1625
|
+
this.status.set("suspended" /* Suspended */);
|
|
1626
|
+
};
|
|
1627
|
+
setFeatureConfig = ({ settings, ...config }) => {
|
|
1628
|
+
let configKey;
|
|
1629
|
+
for (configKey in config) {
|
|
1630
|
+
this.config.setValue(configKey, config[configKey]);
|
|
1631
|
+
}
|
|
1632
|
+
if (settings?.overlaySettings.case === this.settingsKey) {
|
|
1633
|
+
const newSettings = settings.overlaySettings.value;
|
|
1634
|
+
if (newSettings !== void 0) {
|
|
1635
|
+
let key;
|
|
1636
|
+
for (key in newSettings) {
|
|
1637
|
+
console.log(key, newSettings[key]);
|
|
1638
|
+
if (newSettings[key] !== 0 && newSettings[key] !== "") {
|
|
1639
|
+
this.settings.setValue(key, newSettings[key]);
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
};
|
|
1645
|
+
update = (config, source) => {
|
|
1646
|
+
if (this.source === "STREAM" /* STREAM */ && source === "ORGANIZATION" /* ORGANIZATION */) {
|
|
1647
|
+
return;
|
|
1648
|
+
}
|
|
1649
|
+
this.setFeatureConfig(config);
|
|
1650
|
+
this.source = source;
|
|
1651
|
+
};
|
|
1652
|
+
fireEvent(event) {
|
|
1653
|
+
for (const listener of this.listeners.values()) {
|
|
1654
|
+
try {
|
|
1655
|
+
listener.onEvent(event);
|
|
1656
|
+
} catch (err) {
|
|
1657
|
+
console.error(err);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
|
|
1663
|
+
// packages/sdk-web-interfaces/src/store/single.ts
|
|
1664
|
+
import { atom as atom2 } from "nanostores";
|
|
1665
|
+
var SingleStore = class extends AbstractStore {
|
|
1666
|
+
getValue = () => {
|
|
1667
|
+
const store2 = this.getStore();
|
|
1668
|
+
return store2.get();
|
|
1669
|
+
};
|
|
1670
|
+
getValues() {
|
|
1671
|
+
throw new Error("not implemented");
|
|
1672
|
+
}
|
|
1673
|
+
setValue = (value) => {
|
|
1674
|
+
const store2 = this.getStore();
|
|
1675
|
+
return store2.set(value);
|
|
1676
|
+
};
|
|
1677
|
+
subscribe = (listener) => {
|
|
1678
|
+
const store2 = this.getStore();
|
|
1679
|
+
return store2.subscribe(listener);
|
|
1680
|
+
};
|
|
1681
|
+
unsubscribe = () => {
|
|
1682
|
+
const store2 = this.getStore();
|
|
1683
|
+
return store2.off();
|
|
1684
|
+
};
|
|
1685
|
+
listen(listener) {
|
|
1686
|
+
const store2 = this.getStore();
|
|
1687
|
+
return store2.listen(listener);
|
|
1688
|
+
}
|
|
1689
|
+
get() {
|
|
1690
|
+
const store2 = this.getStore();
|
|
1691
|
+
return store2.get();
|
|
1692
|
+
}
|
|
1693
|
+
};
|
|
1694
|
+
var createSingleStore = (initialData) => atom2(initialData);
|
|
1695
|
+
|
|
1696
|
+
// packages/sdk-web-interfaces/src/store/api.ts
|
|
1697
|
+
import { atom as atom3 } from "nanostores";
|
|
1698
|
+
var ApiStore = class extends AbstractStore {
|
|
1699
|
+
atomStore;
|
|
1700
|
+
constructor(store2, name, atomPicker) {
|
|
1701
|
+
super(store2, `api:${name}`);
|
|
1702
|
+
this.atomStore = atom3();
|
|
1703
|
+
if (atomPicker) {
|
|
1704
|
+
store2.subscribe((data) => {
|
|
1705
|
+
this.atomStore.set(atomPicker(data));
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
getAtomStore = () => this.atomStore;
|
|
1710
|
+
getValue = async () => {
|
|
1711
|
+
const store2 = this.getStore();
|
|
1712
|
+
if (store2.value === void 0) {
|
|
1713
|
+
throw new Error("no store");
|
|
1714
|
+
}
|
|
1715
|
+
await store2.value.promise;
|
|
1716
|
+
return store2.get().data;
|
|
1717
|
+
};
|
|
1718
|
+
getValues = () => {
|
|
1719
|
+
throw new Error("not implemented");
|
|
1720
|
+
};
|
|
1721
|
+
setValue = (value) => {
|
|
1722
|
+
const store2 = this.getStore();
|
|
1723
|
+
return store2.set({ loading: false, data: value?.data });
|
|
1724
|
+
};
|
|
1725
|
+
subscribe = (listener) => {
|
|
1726
|
+
const store2 = this.getStore();
|
|
1727
|
+
return store2.subscribe(listener);
|
|
1728
|
+
};
|
|
1729
|
+
unsubscribe = () => {
|
|
1730
|
+
throw new Error("not implemented");
|
|
1731
|
+
};
|
|
1732
|
+
invalidate = () => {
|
|
1733
|
+
this.store.invalidate();
|
|
1734
|
+
};
|
|
1735
|
+
listen = (cb) => {
|
|
1736
|
+
const store2 = this.getStore();
|
|
1737
|
+
return store2.listen(cb);
|
|
1738
|
+
};
|
|
1739
|
+
get() {
|
|
1740
|
+
throw new Error("not implemented");
|
|
1741
|
+
}
|
|
1742
|
+
key = () => {
|
|
1743
|
+
const store2 = this.getStore();
|
|
1744
|
+
return store2.key;
|
|
1745
|
+
};
|
|
1746
|
+
off = () => {
|
|
1747
|
+
const store2 = this.getStore();
|
|
1748
|
+
return store2.off();
|
|
1749
|
+
};
|
|
1750
|
+
};
|
|
1751
|
+
|
|
1752
|
+
// packages/sdk-web-api/src/grpc/transport.ts
|
|
1753
|
+
import {
|
|
1754
|
+
createRouterTransport,
|
|
1755
|
+
createPromiseClient as createPromiseClient2,
|
|
1756
|
+
createCallbackClient
|
|
1757
|
+
} from "@connectrpc/connect";
|
|
1758
|
+
import { createGrpcWebTransport as createGrpcWebTransport2 } from "@bufbuild/connect-web";
|
|
1759
|
+
import { nanoquery } from "@nanostores/query";
|
|
1760
|
+
|
|
1761
|
+
// packages/sdk-web-api/src/utils/devtools.ts
|
|
1762
|
+
async function* logEach(store2, stream) {
|
|
1763
|
+
for await (const m of stream) {
|
|
1764
|
+
store2.response.message = m;
|
|
1765
|
+
store2.received_at = Date.now();
|
|
1766
|
+
const msg = {
|
|
1767
|
+
type: "__GRPC_DEVTOOLS_EXTENSION__",
|
|
1768
|
+
data: store2
|
|
1769
|
+
};
|
|
1770
|
+
window.postMessage(msg);
|
|
1771
|
+
yield m;
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
var __GRPC_DEVTOOLS_EXTENSION__ = () => (next) => async (request) => {
|
|
1775
|
+
const store2 = {
|
|
1776
|
+
name: request.url,
|
|
1777
|
+
request: {},
|
|
1778
|
+
response: {}
|
|
1779
|
+
};
|
|
1780
|
+
store2.request.header = Object.fromEntries(request.header.entries());
|
|
1781
|
+
store2.sent_at = Date.now();
|
|
1782
|
+
try {
|
|
1783
|
+
const response = await next(request);
|
|
1784
|
+
store2.received_at = Date.now();
|
|
1785
|
+
store2.stream = response.stream;
|
|
1786
|
+
store2.response.header = Object.fromEntries(response.header.entries());
|
|
1787
|
+
store2.response.trailer = Object.fromEntries(response.trailer.entries());
|
|
1788
|
+
if (!response.stream) {
|
|
1789
|
+
store2.request.message = request.message;
|
|
1790
|
+
store2.response.message = response.message;
|
|
1791
|
+
store2.latency = store2.received_at - store2.sent_at;
|
|
1792
|
+
const msg = {
|
|
1793
|
+
type: "__GRPC_DEVTOOLS_EXTENSION__",
|
|
1794
|
+
data: store2
|
|
1795
|
+
};
|
|
1796
|
+
window.postMessage(msg);
|
|
1797
|
+
} else {
|
|
1798
|
+
return {
|
|
1799
|
+
...response,
|
|
1800
|
+
message: logEach(store2, response.message)
|
|
1801
|
+
};
|
|
1802
|
+
}
|
|
1803
|
+
return response;
|
|
1804
|
+
} catch (e) {
|
|
1805
|
+
store2.received_at = Date.now();
|
|
1806
|
+
store2.request.message = request.message;
|
|
1807
|
+
store2.response.trailer = {
|
|
1808
|
+
["grpc-status"]: e.code,
|
|
1809
|
+
["grpc-message"]: e.rawMessage
|
|
1810
|
+
};
|
|
1811
|
+
store2.response.message = e.rawMessage;
|
|
1812
|
+
store2.latency = store2.received_at - store2.sent_at;
|
|
1813
|
+
const msg = {
|
|
1814
|
+
type: "__GRPC_DEVTOOLS_EXTENSION__",
|
|
1815
|
+
data: store2
|
|
1816
|
+
};
|
|
1817
|
+
window.postMessage(msg);
|
|
1818
|
+
throw e;
|
|
1819
|
+
}
|
|
1820
|
+
};
|
|
1821
|
+
window.dispatchEvent(new CustomEvent("grpc_devtools_loaded"));
|
|
1822
|
+
|
|
1823
|
+
// packages/sdk-web-api/src/grpc/subscription.ts
|
|
1824
|
+
var ServerStreamSubscription = class {
|
|
1825
|
+
params;
|
|
1826
|
+
stream;
|
|
1827
|
+
method;
|
|
1828
|
+
name;
|
|
1829
|
+
headers;
|
|
1830
|
+
listeners;
|
|
1831
|
+
state;
|
|
1832
|
+
store;
|
|
1833
|
+
constructor(headers, method, params, options) {
|
|
1834
|
+
const initState = {
|
|
1835
|
+
status: "init" /* Init */,
|
|
1836
|
+
ts: /* @__PURE__ */ new Date(),
|
|
1837
|
+
log: []
|
|
1838
|
+
};
|
|
1839
|
+
this.state = new MapStore(createMapStore(initState), `subscription:${options.name}:state`);
|
|
1840
|
+
this.name = options.name;
|
|
1841
|
+
this.headers = headers;
|
|
1842
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
1843
|
+
this.params = params;
|
|
1844
|
+
this.method = method;
|
|
1845
|
+
if (options.withStore) {
|
|
1846
|
+
this.store = new SingleStore(createSingleStore(null), `subscription:${options.name}:store`);
|
|
1847
|
+
}
|
|
1848
|
+
if ("subscribe" in params && typeof params.subscribe === "function") {
|
|
1849
|
+
params.subscribe(() => {
|
|
1850
|
+
this.reconnect();
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
this.updateState("ready" /* Ready */);
|
|
1854
|
+
}
|
|
1855
|
+
updateState = (status) => {
|
|
1856
|
+
this.state.setValue("status", status);
|
|
1857
|
+
this.state.setValue("ts", /* @__PURE__ */ new Date());
|
|
1858
|
+
this.addStateLog(`status => ${status}`);
|
|
1859
|
+
};
|
|
1860
|
+
addStateLog = (msg) => {
|
|
1861
|
+
const log = this.state.getStore().get()["log"];
|
|
1862
|
+
this.state.setValue("log", [...log, `${(/* @__PURE__ */ new Date()).toLocaleString()}: ${msg}`]);
|
|
1863
|
+
};
|
|
1864
|
+
addListener = (name, listener) => {
|
|
1865
|
+
if (this.listeners.has(name)) {
|
|
1866
|
+
this.addStateLog(`listener '${name}' not added`);
|
|
1867
|
+
return false;
|
|
1868
|
+
}
|
|
1869
|
+
this.listeners.set(name, listener);
|
|
1870
|
+
this.addStateLog(`listener '${name}' added`);
|
|
1871
|
+
return true;
|
|
1872
|
+
};
|
|
1873
|
+
removeListener = (name) => {
|
|
1874
|
+
this.listeners.delete(name);
|
|
1875
|
+
this.addStateLog(`listener '${name}' removed`);
|
|
1876
|
+
};
|
|
1877
|
+
connect = () => {
|
|
1878
|
+
this.updateState("connecting" /* Connecting */);
|
|
1879
|
+
if (this.stream) {
|
|
1880
|
+
this.addStateLog(`disconnect prev connection`);
|
|
1881
|
+
this.stream();
|
|
1882
|
+
}
|
|
1883
|
+
const params = "get" in this.params && typeof this.params.get === "function" ? this.params.get() : this.params;
|
|
1884
|
+
this.stream = this.method(
|
|
1885
|
+
params,
|
|
1886
|
+
// ToDo: fix types
|
|
1887
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1888
|
+
// @ts-ignore
|
|
1889
|
+
this.onData,
|
|
1890
|
+
this.onStreamError,
|
|
1891
|
+
{ headers: this.headers.getValues() }
|
|
1892
|
+
);
|
|
1893
|
+
this.updateState("connected" /* Connected */);
|
|
1894
|
+
};
|
|
1895
|
+
disconnect = () => {
|
|
1896
|
+
if (this.stream) {
|
|
1897
|
+
this.stream();
|
|
1898
|
+
}
|
|
1899
|
+
this.listeners.clear();
|
|
1900
|
+
this.updateState("disconnected" /* Disconnected */);
|
|
1901
|
+
};
|
|
1902
|
+
reconnect = () => {
|
|
1903
|
+
this.updateState("reconnecting" /* Reconnecting */);
|
|
1904
|
+
this.connect();
|
|
1905
|
+
};
|
|
1906
|
+
getStore = () => this.store?.getStore();
|
|
1907
|
+
onData = (response) => {
|
|
1908
|
+
this.addStateLog(`received data => ${JSON.stringify(response)}`);
|
|
1909
|
+
if (this.store) {
|
|
1910
|
+
this.store.setValue(response);
|
|
1911
|
+
}
|
|
1912
|
+
for (const [, listener] of this.listeners) {
|
|
1913
|
+
listener(response);
|
|
1914
|
+
}
|
|
1915
|
+
this.addStateLog(`data routed to ${this.listeners.size} listeners`);
|
|
1916
|
+
};
|
|
1917
|
+
onStreamError = (error) => {
|
|
1918
|
+
console.error(error);
|
|
1919
|
+
this.updateState("failed" /* Failed */);
|
|
1920
|
+
this.state.setValue("error", error);
|
|
1921
|
+
};
|
|
1922
|
+
};
|
|
1923
|
+
|
|
1924
|
+
// packages/sdk-web-api/src/grpc/transport.ts
|
|
1925
|
+
var Transport = class {
|
|
1926
|
+
toJsonOptions = {
|
|
1927
|
+
emitDefaultValues: false,
|
|
1928
|
+
enumAsInteger: true,
|
|
1929
|
+
useProtoFieldName: false
|
|
1930
|
+
};
|
|
1931
|
+
transport;
|
|
1932
|
+
nanoquery;
|
|
1933
|
+
interceptors = [];
|
|
1934
|
+
$headers;
|
|
1935
|
+
clients;
|
|
1936
|
+
callbackClients;
|
|
1937
|
+
subscriptions;
|
|
1938
|
+
constructor() {
|
|
1939
|
+
this.$headers = new MapStore(
|
|
1940
|
+
createMapStore({
|
|
1941
|
+
["sl-device-id"]: process.env.NX_DEVICE_ID || "sdk-web-dev"
|
|
1942
|
+
}),
|
|
1943
|
+
"transport:headers"
|
|
1944
|
+
);
|
|
1945
|
+
this.initInterceptors();
|
|
1946
|
+
this.clients = /* @__PURE__ */ new Map();
|
|
1947
|
+
this.callbackClients = /* @__PURE__ */ new Map();
|
|
1948
|
+
this.subscriptions = /* @__PURE__ */ new Map();
|
|
1949
|
+
const [createFetcherStore, createMutatorStore, utils] = nanoquery();
|
|
1950
|
+
this.nanoquery = { createFetcherStore, createMutatorStore, utils };
|
|
1951
|
+
this.transport = createGrpcWebTransport2({
|
|
1952
|
+
baseUrl: process.env.NX_GRPC_HOST || "https://grpc-web.next.streamlayer.io:443",
|
|
1953
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1954
|
+
// @ts-ignore
|
|
1955
|
+
interceptors: this.interceptors,
|
|
1956
|
+
useBinaryFormat: true
|
|
1957
|
+
});
|
|
1958
|
+
}
|
|
1959
|
+
// use shared request params, based on Atom, each new Atom will create new subscription
|
|
1960
|
+
// mutate Atom, subscription automatically reconnect with new params
|
|
1961
|
+
// if headers changed, reconnect subscription with new headers automatically
|
|
1962
|
+
addSubscription = (method, params, options) => {
|
|
1963
|
+
const currentSubscription = this.subscriptions.get(params);
|
|
1964
|
+
if (currentSubscription) {
|
|
1965
|
+
return currentSubscription;
|
|
1966
|
+
}
|
|
1967
|
+
const subscription = new ServerStreamSubscription(this.$headers, method, params, options);
|
|
1968
|
+
this.subscriptions.set(params, subscription);
|
|
1969
|
+
return subscription;
|
|
1970
|
+
};
|
|
1971
|
+
removeSubscription = (subscription) => {
|
|
1972
|
+
subscription.disconnect();
|
|
1973
|
+
this.subscriptions.delete(subscription.params);
|
|
1974
|
+
};
|
|
1975
|
+
// cleanup subscriptions
|
|
1976
|
+
disconnect = () => {
|
|
1977
|
+
for (const [name, subscription] of this.subscriptions) {
|
|
1978
|
+
subscription.disconnect();
|
|
1979
|
+
this.subscriptions.delete(name);
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
registerInterceptor = (interceptor) => {
|
|
1983
|
+
this.interceptors.push(interceptor);
|
|
1984
|
+
};
|
|
1985
|
+
removeInterceptor = (interceptor) => {
|
|
1986
|
+
this.interceptors = this.interceptors.filter((i) => i !== interceptor);
|
|
1987
|
+
};
|
|
1988
|
+
getClient = (service) => {
|
|
1989
|
+
const serviceName = service.typeName;
|
|
1990
|
+
if (this.clients.has(serviceName)) {
|
|
1991
|
+
return this.clients.get(serviceName);
|
|
1992
|
+
}
|
|
1993
|
+
const client = createPromiseClient2(service, this.transport);
|
|
1994
|
+
this.clients.set(serviceName, client);
|
|
1995
|
+
return client;
|
|
1996
|
+
};
|
|
1997
|
+
getCallbackClient = (service) => {
|
|
1998
|
+
const serviceName = service.typeName;
|
|
1999
|
+
if (this.callbackClients.has(serviceName)) {
|
|
2000
|
+
return this.callbackClients.get(serviceName);
|
|
2001
|
+
}
|
|
2002
|
+
const client = createCallbackClient(service, this.transport);
|
|
2003
|
+
this.callbackClients.set(serviceName, client);
|
|
2004
|
+
return client;
|
|
2005
|
+
};
|
|
2006
|
+
// create unary client, used for query request
|
|
2007
|
+
createPromiseClient = (service, { params = [], method }) => {
|
|
2008
|
+
const client = this.getClient(service);
|
|
2009
|
+
const methodName = service.methods[method].name;
|
|
2010
|
+
const queryKey = [
|
|
2011
|
+
service.typeName,
|
|
2012
|
+
methodName.charAt(0).toLowerCase() + methodName.slice(1),
|
|
2013
|
+
...Array.isArray(params) ? params : [params]
|
|
2014
|
+
];
|
|
2015
|
+
const queryKeyWithoutParams = [service.typeName, methodName.charAt(0).toLowerCase() + methodName.slice(1)];
|
|
2016
|
+
return { client, queryKey, queryKeyStr: queryKeyWithoutParams.join("") };
|
|
2017
|
+
};
|
|
2018
|
+
// create callback client, used for server stream subscriptions
|
|
2019
|
+
createCallbackClient = (service) => {
|
|
2020
|
+
const client = this.getCallbackClient(service);
|
|
2021
|
+
return { client };
|
|
2022
|
+
};
|
|
2023
|
+
setSdkKey = (sdkKey) => {
|
|
2024
|
+
this.$headers.setValue("sdk", sdkKey);
|
|
2025
|
+
};
|
|
2026
|
+
setAuth = (token) => {
|
|
2027
|
+
this.$headers.setValue("authorization", token);
|
|
2028
|
+
};
|
|
2029
|
+
setHeader = (name, value) => this.$headers.setValue(name, value);
|
|
2030
|
+
getHeader = (name) => this.$headers.getValue(name);
|
|
2031
|
+
getHeaders = () => this.$headers.getValues();
|
|
2032
|
+
initInterceptors = () => {
|
|
2033
|
+
if (this.interceptors.length !== 0) {
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
const auth = (next) => async (req) => {
|
|
2037
|
+
const headers = this.$headers.getValues();
|
|
2038
|
+
for (const header in headers) {
|
|
2039
|
+
req.header.set(header, headers[header]);
|
|
2040
|
+
}
|
|
2041
|
+
try {
|
|
2042
|
+
return await next(req);
|
|
2043
|
+
} catch (err) {
|
|
2044
|
+
console.log({ err, req }, "catch err");
|
|
2045
|
+
throw err;
|
|
2046
|
+
}
|
|
2047
|
+
};
|
|
2048
|
+
this.interceptors.push(auth);
|
|
2049
|
+
this.interceptors.push(__GRPC_DEVTOOLS_EXTENSION__());
|
|
2050
|
+
};
|
|
2051
|
+
};
|
|
2052
|
+
|
|
2053
|
+
// packages/sdk-web-api/src/grpc/queries/index.ts
|
|
2054
|
+
var queries_exports = {};
|
|
2055
|
+
__export(queries_exports, {
|
|
2056
|
+
$bypassLogin: () => $bypassLogin,
|
|
2057
|
+
$organizationAdvertising: () => $organizationAdvertising,
|
|
2058
|
+
$organizationSettings: () => $organizationSettings,
|
|
2059
|
+
$retrieveEventId: () => $retrieveEventId,
|
|
2060
|
+
$streamSettings: () => $streamSettings,
|
|
2061
|
+
$user: () => $user,
|
|
2062
|
+
$userSettings: () => $userSettings,
|
|
2063
|
+
bypassAuth: () => bypassAuth,
|
|
2064
|
+
register: () => register
|
|
2065
|
+
});
|
|
2066
|
+
|
|
2067
|
+
// packages/sdk-web-api/src/grpc/queries/event.ts
|
|
2068
|
+
import { Events } from "@streamlayer/sl-eslib/sports/events/events_connect";
|
|
2069
|
+
import { Client } from "@streamlayer/sl-eslib/sdkSettings/client/client_connect";
|
|
2070
|
+
var $retrieveEventId = ($providerStreamId, transport2) => {
|
|
2071
|
+
const { client, queryKey } = transport2.createPromiseClient(Events, {
|
|
2072
|
+
method: "retrieveEventId",
|
|
2073
|
+
params: [$providerStreamId]
|
|
2074
|
+
});
|
|
2075
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2076
|
+
fetcher: async (_, __, id) => {
|
|
2077
|
+
if (!id || typeof id !== "string") {
|
|
2078
|
+
return "";
|
|
2079
|
+
}
|
|
2080
|
+
try {
|
|
2081
|
+
const res = await client.retrieveEventId({
|
|
2082
|
+
id
|
|
2083
|
+
});
|
|
2084
|
+
return res.data?.id || "";
|
|
2085
|
+
} catch (err) {
|
|
2086
|
+
return "";
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
});
|
|
2090
|
+
};
|
|
2091
|
+
var $streamSettings = (slStreamId, transport2) => {
|
|
2092
|
+
const { client, queryKey } = transport2.createPromiseClient(Client, { method: "getStream", params: [slStreamId] });
|
|
2093
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2094
|
+
fetcher: async (_, __, id) => {
|
|
2095
|
+
if (!id) {
|
|
2096
|
+
return void 0;
|
|
2097
|
+
}
|
|
2098
|
+
const res = await client.getStream({
|
|
2099
|
+
id
|
|
2100
|
+
// we are sure that id is a string
|
|
2101
|
+
});
|
|
2102
|
+
return res.data?.attributes;
|
|
2103
|
+
}
|
|
2104
|
+
});
|
|
2105
|
+
};
|
|
2106
|
+
|
|
2107
|
+
// packages/sdk-web-api/src/grpc/queries/organization.ts
|
|
2108
|
+
import { Client as Client3 } from "@streamlayer/sl-eslib/sdkSettings/client/client_connect";
|
|
2109
|
+
|
|
2110
|
+
// packages/sdk-web-api/src/grpc/queries/user.ts
|
|
2111
|
+
import { Users as Users2 } from "@streamlayer/sl-eslib/users/users_connect";
|
|
2112
|
+
import { Client as Client2 } from "@streamlayer/sl-eslib/sdkSettings/client/client_connect";
|
|
2113
|
+
var $user = ($userToken, transport2) => {
|
|
2114
|
+
const { queryKey, client } = transport2.createPromiseClient(Users2, { method: "me", params: [$userToken] });
|
|
2115
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2116
|
+
fetcher: () => client.me({})
|
|
2117
|
+
});
|
|
2118
|
+
};
|
|
2119
|
+
var $bypassLogin = (transport2) => {
|
|
2120
|
+
const { client, queryKeyStr } = transport2.createPromiseClient(Users2, { method: "bypassAuth" });
|
|
2121
|
+
return transport2.nanoquery.createMutatorStore(
|
|
2122
|
+
async ({ data: { userKey, schema, init }, getCacheUpdater }) => {
|
|
2123
|
+
const [updateCache] = getCacheUpdater(queryKeyStr);
|
|
2124
|
+
const user = await client.bypassAuth({ userKey, schema, init });
|
|
2125
|
+
updateCache(user);
|
|
2126
|
+
return user;
|
|
2127
|
+
}
|
|
2128
|
+
);
|
|
2129
|
+
};
|
|
2130
|
+
var bypassAuth = (transport2, params) => {
|
|
2131
|
+
const { client } = transport2.createPromiseClient(Users2, { method: "bypassAuth" });
|
|
2132
|
+
return client.bypassAuth(params);
|
|
2133
|
+
};
|
|
2134
|
+
var $userSettings = ($userToken, transport2) => {
|
|
2135
|
+
const { client, queryKey } = transport2.createPromiseClient(Client2, { method: "get", params: [$userToken] });
|
|
2136
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2137
|
+
fetcher: async () => {
|
|
2138
|
+
const data = await client.get({});
|
|
2139
|
+
return data.data?.attributes;
|
|
2140
|
+
}
|
|
2141
|
+
});
|
|
2142
|
+
};
|
|
2143
|
+
var register = (transport2, phone) => {
|
|
2144
|
+
const { client } = transport2.createPromiseClient(Users2, { method: "register" });
|
|
2145
|
+
return client.register({ id: phone });
|
|
2146
|
+
};
|
|
2147
|
+
|
|
2148
|
+
// packages/sdk-web-api/src/grpc/queries/organization.ts
|
|
2149
|
+
var $organizationSettings = ($enabled, transport2) => {
|
|
2150
|
+
const { client, queryKey } = transport2.createPromiseClient(Client3, { method: "getOrganization", params: [$enabled] });
|
|
2151
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2152
|
+
fetcher: async () => {
|
|
2153
|
+
const res = await client.getOrganization({});
|
|
2154
|
+
return res.data ? {
|
|
2155
|
+
...res.data.attributes,
|
|
2156
|
+
id: res.data.id
|
|
2157
|
+
} : void 0;
|
|
2158
|
+
}
|
|
2159
|
+
});
|
|
2160
|
+
};
|
|
2161
|
+
var $organizationAdvertising = ($enabled, transport2) => {
|
|
2162
|
+
const { client, queryKey } = transport2.createPromiseClient(Client3, {
|
|
2163
|
+
method: "getOrganizationAdvertising",
|
|
2164
|
+
params: [$enabled]
|
|
2165
|
+
});
|
|
2166
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2167
|
+
fetcher: async () => {
|
|
2168
|
+
const res = await client.getOrganizationAdvertising({});
|
|
2169
|
+
return res.data?.attributes;
|
|
2170
|
+
}
|
|
2171
|
+
});
|
|
2172
|
+
};
|
|
2173
|
+
|
|
2174
|
+
// packages/sdk-web-api/src/index.ts
|
|
2175
|
+
var transport = (instance, opts, done) => {
|
|
2176
|
+
instance.transport = new Transport();
|
|
2177
|
+
instance.transport.setSdkKey(opts.sdkKey);
|
|
2178
|
+
done();
|
|
2179
|
+
};
|
|
2180
|
+
|
|
2181
|
+
// packages/sdk-web-core/src/store/store.ts
|
|
2182
|
+
var initializeStore = (transport2) => {
|
|
2183
|
+
const enabled = new SingleStore(createSingleStore(), "enabled");
|
|
2184
|
+
const status = new SingleStore(createSingleStore("disabled" /* DISABLED */), "status");
|
|
2185
|
+
const userKey = new SingleStore(createSingleStore(), "userKey");
|
|
2186
|
+
const userToken = new SingleStore(createSingleStore(), "userToken");
|
|
2187
|
+
userToken.listen((token) => {
|
|
2188
|
+
if (token) {
|
|
2189
|
+
localStorage.setItem("sl-user-token", token);
|
|
2190
|
+
} else {
|
|
2191
|
+
localStorage.removeItem("sl-user-token");
|
|
2192
|
+
}
|
|
2193
|
+
});
|
|
2194
|
+
const providerStreamId = new SingleStore(createSingleStore(), "providerStreamId");
|
|
2195
|
+
const slStreamId = new ApiStore(
|
|
2196
|
+
queries_exports.$retrieveEventId(providerStreamId.getStore(), transport2),
|
|
2197
|
+
"slStreamId",
|
|
2198
|
+
(data) => data?.data
|
|
2199
|
+
);
|
|
2200
|
+
const user = new ApiStore(
|
|
2201
|
+
queries_exports.$user(userToken.getStore(), transport2),
|
|
2202
|
+
"user",
|
|
2203
|
+
(data) => data?.data?.data?.id
|
|
2204
|
+
);
|
|
2205
|
+
const userSettings = new ApiStore(
|
|
2206
|
+
queries_exports.$userSettings(userToken.getStore(), transport2),
|
|
2207
|
+
"userSettings"
|
|
2208
|
+
);
|
|
2209
|
+
const streamSettings = new ApiStore(
|
|
2210
|
+
queries_exports.$streamSettings(slStreamId.getAtomStore(), transport2),
|
|
2211
|
+
"streamSettings"
|
|
2212
|
+
);
|
|
2213
|
+
slStreamId.getAtomStore().listen((eventId) => {
|
|
2214
|
+
if (eventId === "" || eventId === void 0) {
|
|
2215
|
+
streamSettings.getStore().mutate(void 0);
|
|
2216
|
+
}
|
|
2217
|
+
});
|
|
2218
|
+
const organizationSettings = new ApiStore(
|
|
2219
|
+
queries_exports.$organizationSettings(enabled.getStore(), transport2),
|
|
2220
|
+
"organizationSettings",
|
|
2221
|
+
(data) => data?.data?.id
|
|
2222
|
+
);
|
|
2223
|
+
const organizationAdvertising = new ApiStore(
|
|
2224
|
+
queries_exports.$organizationAdvertising(organizationSettings.getAtomStore(), transport2),
|
|
2225
|
+
"organizationAdvertising"
|
|
2226
|
+
);
|
|
2227
|
+
return {
|
|
2228
|
+
enabled,
|
|
2229
|
+
status,
|
|
2230
|
+
providerStreamId,
|
|
2231
|
+
slStreamId,
|
|
2232
|
+
streamSettings,
|
|
2233
|
+
user,
|
|
2234
|
+
userKey,
|
|
2235
|
+
userToken,
|
|
2236
|
+
userSettings,
|
|
2237
|
+
organizationSettings,
|
|
2238
|
+
organizationAdvertising
|
|
2239
|
+
};
|
|
2240
|
+
};
|
|
2241
|
+
var CoreStore = class extends AbstractStore {
|
|
2242
|
+
stores;
|
|
2243
|
+
constructor(transport2) {
|
|
2244
|
+
const storesObj = initializeStore(transport2);
|
|
2245
|
+
const store2 = mergeStores(storesObj);
|
|
2246
|
+
super(store2, "core");
|
|
2247
|
+
this.stores = storesObj;
|
|
2248
|
+
}
|
|
2249
|
+
getValue() {
|
|
2250
|
+
throw new Error("Not implemented");
|
|
2251
|
+
}
|
|
2252
|
+
getValues() {
|
|
2253
|
+
return this.stores;
|
|
2254
|
+
}
|
|
2255
|
+
setValue() {
|
|
2256
|
+
throw new Error("Not implemented");
|
|
2257
|
+
}
|
|
2258
|
+
subscribe = (subscribes) => {
|
|
2259
|
+
let storeKey;
|
|
2260
|
+
for (storeKey in this.stores) {
|
|
2261
|
+
const fn = subscribes[storeKey];
|
|
2262
|
+
if (storeKey in subscribes && fn !== void 0) {
|
|
2263
|
+
this.stores[storeKey].subscribe(subscribes[storeKey]);
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
};
|
|
2267
|
+
unsubscribe = () => {
|
|
2268
|
+
const store2 = this.getStore();
|
|
2269
|
+
return store2.off();
|
|
2270
|
+
};
|
|
2271
|
+
};
|
|
2272
|
+
|
|
2273
|
+
// packages/sdk-web-core/src/index.ts
|
|
2274
|
+
var core = (instance, opts, done) => {
|
|
2275
|
+
instance.sdk = /* @__PURE__ */ Object.create(null);
|
|
2276
|
+
instance.sdk.initializeApp = async () => {
|
|
2277
|
+
instance.storeSubscribe();
|
|
2278
|
+
instance.stores.enabled.setValue("on");
|
|
2279
|
+
instance.stores.status.setValue("initialization" /* INITIALIZATION */);
|
|
2280
|
+
try {
|
|
2281
|
+
const organizationSettings = await instance.stores.organizationSettings.getValue();
|
|
2282
|
+
if (organizationSettings) {
|
|
2283
|
+
instance.stores.status.setValue("ready" /* READY */);
|
|
2284
|
+
return { enabled: !!organizationSettings };
|
|
2285
|
+
}
|
|
2286
|
+
instance.stores.status.setValue("failed" /* FAILED */);
|
|
2287
|
+
return { err: "failed" };
|
|
2288
|
+
} catch (err) {
|
|
2289
|
+
instance.stores.enabled.setValue();
|
|
2290
|
+
instance.stores.status.setValue("failed" /* FAILED */);
|
|
2291
|
+
return { err: `${err}` };
|
|
2292
|
+
}
|
|
2293
|
+
};
|
|
2294
|
+
instance.sdk.disableApp = () => {
|
|
2295
|
+
instance.stores.enabled.setValue();
|
|
2296
|
+
instance.stores.status.setValue("disabled" /* DISABLED */);
|
|
2297
|
+
instance.storeUnsubscribe();
|
|
2298
|
+
};
|
|
2299
|
+
instance.sdk.createEventSession = (providerStreamId) => {
|
|
2300
|
+
instance.stores.providerStreamId.setValue("");
|
|
2301
|
+
instance.stores.providerStreamId.setValue(providerStreamId);
|
|
2302
|
+
};
|
|
2303
|
+
done();
|
|
2304
|
+
};
|
|
2305
|
+
|
|
2306
|
+
// packages/feature-gamification/src/queries/index.ts
|
|
2307
|
+
import { atom as atom4 } from "nanostores";
|
|
2308
|
+
import { Feed } from "@streamlayer/sl-eslib/interactive/feed/interactive.feed_connect";
|
|
2309
|
+
|
|
2310
|
+
// packages/feature-gamification/src/queries/leaderboard.ts
|
|
2311
|
+
import { Leaderboard } from "@streamlayer/sl-eslib/interactive/leaderboard/interactive.leaderboard_connect";
|
|
2312
|
+
var $userSummary = ($eventId, $userId, transport2) => {
|
|
2313
|
+
const { client, queryKey } = transport2.createPromiseClient(Leaderboard, {
|
|
2314
|
+
method: "summary",
|
|
2315
|
+
params: [$eventId, $userId]
|
|
2316
|
+
});
|
|
2317
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2318
|
+
fetcher: async (_, __, eventId, userId) => {
|
|
2319
|
+
const res = await client.summary({
|
|
2320
|
+
eventId,
|
|
2321
|
+
userId
|
|
2322
|
+
});
|
|
2323
|
+
return res.data?.attributes;
|
|
2324
|
+
}
|
|
2325
|
+
});
|
|
2326
|
+
};
|
|
2327
|
+
|
|
2328
|
+
// packages/feature-gamification/src/queries/index.ts
|
|
2329
|
+
var $activeQuestion = (slStreamId, transport2) => {
|
|
2330
|
+
const { client, queryKey } = transport2.createPromiseClient(Feed, { method: "syncQuestion", params: [slStreamId] });
|
|
2331
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2332
|
+
fetcher: async (_, __, id) => {
|
|
2333
|
+
if (!id) {
|
|
2334
|
+
return void 0;
|
|
2335
|
+
}
|
|
2336
|
+
const res = await client.syncQuestion({
|
|
2337
|
+
filter: {
|
|
2338
|
+
eventId: id
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2341
|
+
return res.data?.attributes;
|
|
2342
|
+
}
|
|
2343
|
+
});
|
|
2344
|
+
};
|
|
2345
|
+
var feedSubscription = ($slStreamId, transport2) => {
|
|
2346
|
+
const { client } = transport2.createCallbackClient(Feed);
|
|
2347
|
+
const params = atom4({ eventId: $slStreamId.get() || "", feedId: "" });
|
|
2348
|
+
$slStreamId.subscribe((eventId = "") => {
|
|
2349
|
+
params.set({ eventId, feedId: "" });
|
|
2350
|
+
});
|
|
2351
|
+
const subscription = transport2.addSubscription(
|
|
2352
|
+
client.subscription,
|
|
2353
|
+
params,
|
|
2354
|
+
{ name: "feedSubscription" }
|
|
2355
|
+
);
|
|
2356
|
+
return subscription;
|
|
2357
|
+
};
|
|
2358
|
+
var questionSubscription = (questionId, transport2) => {
|
|
2359
|
+
const { client } = transport2.createCallbackClient(Feed);
|
|
2360
|
+
const subscription = transport2.addSubscription(client.questionSubscription, { questionId }, { name: "questionSubscription" });
|
|
2361
|
+
return subscription;
|
|
2362
|
+
};
|
|
2363
|
+
var $questionByUser = ($questionId, transport2) => {
|
|
2364
|
+
const { client, queryKey } = transport2.createPromiseClient(Feed, { method: "questionByUser", params: [$questionId] });
|
|
2365
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2366
|
+
fetcher: async (_, __, questionId) => {
|
|
2367
|
+
const res = await client.questionByUser({
|
|
2368
|
+
questionId
|
|
2369
|
+
});
|
|
2370
|
+
return res.data?.attributes?.question;
|
|
2371
|
+
}
|
|
2372
|
+
});
|
|
2373
|
+
};
|
|
2374
|
+
var $pickHistory = (slStreamId, transport2) => {
|
|
2375
|
+
const { client, queryKey } = transport2.createPromiseClient(Feed, { method: "pickHistory", params: [slStreamId] });
|
|
2376
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2377
|
+
fetcher: async (_, __, eventId) => {
|
|
2378
|
+
if (!eventId) {
|
|
2379
|
+
return void 0;
|
|
2380
|
+
}
|
|
2381
|
+
const res = await client.pickHistory({
|
|
2382
|
+
eventId
|
|
2383
|
+
});
|
|
2384
|
+
return res.data?.map(({ attributes }) => attributes);
|
|
2385
|
+
}
|
|
2386
|
+
});
|
|
2387
|
+
};
|
|
2388
|
+
|
|
2389
|
+
// packages/feature-gamification/src/queries/actions.ts
|
|
2390
|
+
import { Feed as Feed2 } from "@streamlayer/sl-eslib/interactive/feed/interactive.feed_connect";
|
|
2391
|
+
var submitAnswer = (transport2, data) => {
|
|
2392
|
+
const { client } = transport2.createPromiseClient(Feed2, { method: "submitAnswer" });
|
|
2393
|
+
return client.submitAnswer({ data });
|
|
2394
|
+
};
|
|
2395
|
+
var submitInplay = (transport2, eventId) => {
|
|
2396
|
+
const { client } = transport2.createPromiseClient(Feed2, { method: "submitInplay" });
|
|
2397
|
+
return client.submitInplay({ data: { eventId: +eventId } });
|
|
2398
|
+
};
|
|
2399
|
+
var skipQuestion = (transport2, questionId) => {
|
|
2400
|
+
const { client } = transport2.createPromiseClient(Feed2, { method: "skipQuestion" });
|
|
2401
|
+
return client.skipQuestion({ data: { id: questionId } });
|
|
2402
|
+
};
|
|
2403
|
+
|
|
2404
|
+
// packages/feature-gamification/src/index.ts
|
|
2405
|
+
var Gamification = class extends AbstractFeature {
|
|
2406
|
+
// user statistics (leaderboard panel)
|
|
2407
|
+
userSummary;
|
|
2408
|
+
// questions list (pick history)
|
|
2409
|
+
questions;
|
|
2410
|
+
// pinned leaderboard id
|
|
2411
|
+
leaderboardId;
|
|
2412
|
+
// sl event id
|
|
2413
|
+
slStreamId;
|
|
2414
|
+
// current user id
|
|
2415
|
+
userId;
|
|
2416
|
+
organizationId;
|
|
2417
|
+
// opened question, using to download statistics
|
|
2418
|
+
openedQuestionId;
|
|
2419
|
+
// opened question statistics
|
|
2420
|
+
openedQuestion;
|
|
2421
|
+
// last active question in feed
|
|
2422
|
+
activeQuestionId;
|
|
2423
|
+
// moderation id
|
|
2424
|
+
moderationId;
|
|
2425
|
+
// feed id (deprecated?)
|
|
2426
|
+
feedId;
|
|
2427
|
+
// pinned leaderboard id
|
|
2428
|
+
onbordingComplete;
|
|
2429
|
+
notifications;
|
|
2430
|
+
transport;
|
|
2431
|
+
constructor(config, source, instance) {
|
|
2432
|
+
super(config, source);
|
|
2433
|
+
this.leaderboardId = new SingleStore(
|
|
2434
|
+
createSingleStore(this.settings.getValue("pinnedLeaderboardId")),
|
|
2435
|
+
"pinnedLeaderboardId"
|
|
2436
|
+
).getStore();
|
|
2437
|
+
this.slStreamId = instance.stores.slStreamId.getAtomStore();
|
|
2438
|
+
this.userId = instance.stores.user.getAtomStore();
|
|
2439
|
+
this.organizationId = instance.stores.organizationSettings.getAtomStore();
|
|
2440
|
+
this.moderationId = new SingleStore(createSingleStore(), "moderationId").getStore();
|
|
2441
|
+
this.feedId = new SingleStore(createSingleStore(), "feedId").getStore();
|
|
2442
|
+
this.onbordingComplete = new SingleStore(createSingleStore(false), "onbordingComplete").getStore();
|
|
2443
|
+
this.openedQuestionId = new SingleStore(createSingleStore(), "openedQuestionId").getStore();
|
|
2444
|
+
this.notifications = instance.notifications;
|
|
2445
|
+
this.transport = instance.transport;
|
|
2446
|
+
if (!this.userId.get()) {
|
|
2447
|
+
this.userId.subscribe((userId) => {
|
|
2448
|
+
if (userId) {
|
|
2449
|
+
this.connect(instance.transport);
|
|
2450
|
+
const cached = localStorage.getItem(`sl-onbording:${userId}:${this.slStreamId.get()}`);
|
|
2451
|
+
this.onbordingComplete.set(!!cached);
|
|
2452
|
+
}
|
|
2453
|
+
});
|
|
2454
|
+
} else {
|
|
2455
|
+
this.connect(instance.transport);
|
|
2456
|
+
const userId = this.userId.get();
|
|
2457
|
+
const cached = localStorage.getItem(`sl-onbording:${userId}:${this.slStreamId.get()}`);
|
|
2458
|
+
this.onbordingComplete.set(!!cached);
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
getCurrentSessionIdPrefix = (opts) => {
|
|
2462
|
+
const eventId = opts.eventId || this.slStreamId.get();
|
|
2463
|
+
const userId = opts.userId || this.userId.get();
|
|
2464
|
+
const organizationId = opts.organizationId || this.organizationId.get();
|
|
2465
|
+
return `${organizationId}:${userId}:${eventId}:${opts.prefix || ""}`;
|
|
2466
|
+
};
|
|
2467
|
+
connect = (transport2) => {
|
|
2468
|
+
this.userSummary = new ApiStore(
|
|
2469
|
+
$userSummary(this.slStreamId, this.userId, transport2),
|
|
2470
|
+
"gamification:userSummary"
|
|
2471
|
+
);
|
|
2472
|
+
this.questions = new ApiStore(
|
|
2473
|
+
$pickHistory(this.slStreamId, transport2),
|
|
2474
|
+
"gamification:questions"
|
|
2475
|
+
);
|
|
2476
|
+
this.activeQuestionId = new ApiStore(
|
|
2477
|
+
$activeQuestion(this.slStreamId, transport2),
|
|
2478
|
+
"gamification:activeQuestionId"
|
|
2479
|
+
);
|
|
2480
|
+
this.openedQuestion = new ApiStore(
|
|
2481
|
+
$questionByUser(this.openedQuestionId, transport2),
|
|
2482
|
+
"gamification:activeQuestionId"
|
|
2483
|
+
);
|
|
2484
|
+
let questionSubscription2 = void 0;
|
|
2485
|
+
this.openedQuestionId.listen((questionId) => {
|
|
2486
|
+
if (questionId) {
|
|
2487
|
+
questionSubscription2 = questionSubscription(questionId, transport2);
|
|
2488
|
+
questionSubscription2.addListener(
|
|
2489
|
+
"feed-subscription-opened-question",
|
|
2490
|
+
(response) => {
|
|
2491
|
+
window.requestAnimationFrame(() => {
|
|
2492
|
+
this.openedQuestion?.getStore().mutate(response.data?.attributes?.question);
|
|
2493
|
+
this.openedQuestion?.getStore().invalidate();
|
|
2494
|
+
this.userSummary?.getStore().invalidate();
|
|
2495
|
+
});
|
|
2496
|
+
}
|
|
2497
|
+
);
|
|
2498
|
+
questionSubscription2.connect();
|
|
2499
|
+
} else {
|
|
2500
|
+
console.log("cleanup on close question");
|
|
2501
|
+
this.openedQuestion?.getStore().mutate(void 0);
|
|
2502
|
+
if (questionSubscription2 !== void 0) {
|
|
2503
|
+
transport2.removeSubscription(questionSubscription2);
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
});
|
|
2507
|
+
this.activeQuestionId?.listen((question) => {
|
|
2508
|
+
if (question?.data?.notification?.title) {
|
|
2509
|
+
if (question.data.question.status === QuestionStatus.ACTIVE) {
|
|
2510
|
+
this.notifications.add({
|
|
2511
|
+
id: this.getCurrentSessionIdPrefix({ prefix: `notification-id:${question.data.question.id}` }),
|
|
2512
|
+
data: question.data
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
});
|
|
2517
|
+
const feedSubscription2 = feedSubscription(this.slStreamId, transport2);
|
|
2518
|
+
feedSubscription2.addListener("feed-subscription-active-question", (response) => {
|
|
2519
|
+
window.requestAnimationFrame(() => {
|
|
2520
|
+
const $activeQuestionId = this.activeQuestionId?.getStore();
|
|
2521
|
+
if ($activeQuestionId) {
|
|
2522
|
+
$activeQuestionId.mutate(response.data?.attributes);
|
|
2523
|
+
}
|
|
2524
|
+
});
|
|
2525
|
+
});
|
|
2526
|
+
feedSubscription2.addListener("feed-subscription-questions-list", () => {
|
|
2527
|
+
window.requestAnimationFrame(() => {
|
|
2528
|
+
this.questions?.invalidate();
|
|
2529
|
+
});
|
|
2530
|
+
});
|
|
2531
|
+
};
|
|
2532
|
+
// onboarding
|
|
2533
|
+
submitInplay = async () => {
|
|
2534
|
+
const eventId = this.slStreamId.get();
|
|
2535
|
+
if (eventId) {
|
|
2536
|
+
await submitInplay(this.transport, eventId);
|
|
2537
|
+
this.onbordingComplete.set(true);
|
|
2538
|
+
localStorage.setItem(`sl-onbording:${this.userId.get()}:${eventId}`, "true");
|
|
2539
|
+
}
|
|
2540
|
+
};
|
|
2541
|
+
submitAnswer = async (questionId, answerId) => {
|
|
2542
|
+
await submitAnswer(this.transport, { questionId, answerId });
|
|
2543
|
+
this.questions?.invalidate();
|
|
2544
|
+
};
|
|
2545
|
+
skipQuestion = async (questionId) => {
|
|
2546
|
+
await skipQuestion(this.transport, questionId);
|
|
2547
|
+
this.questions?.invalidate();
|
|
2548
|
+
};
|
|
2549
|
+
openQuestion = (questionId) => {
|
|
2550
|
+
this.openedQuestionId.set(questionId);
|
|
2551
|
+
this.notifications.markAsViewed(this.getCurrentSessionIdPrefix({ prefix: `notification-id:${questionId}` }));
|
|
2552
|
+
};
|
|
2553
|
+
closeQuestion = () => {
|
|
2554
|
+
this.notifications.markAsViewed(
|
|
2555
|
+
this.getCurrentSessionIdPrefix({ prefix: `notification-id:${this.openedQuestionId.get()}` })
|
|
2556
|
+
);
|
|
2557
|
+
window.requestAnimationFrame(() => {
|
|
2558
|
+
this.openedQuestionId.set(void 0);
|
|
2559
|
+
});
|
|
2560
|
+
};
|
|
2561
|
+
};
|
|
2562
|
+
|
|
2563
|
+
// packages/sdk-web-features/src/index.ts
|
|
2564
|
+
var Feature = class extends AbstractFeature {
|
|
2565
|
+
};
|
|
2566
|
+
var initFeature = (overlay, source, instance) => {
|
|
2567
|
+
if (overlay.type === SdkOverlayType.GAMES) {
|
|
2568
|
+
return new Gamification(overlay, source, instance);
|
|
2569
|
+
}
|
|
2570
|
+
return new Feature(overlay, source);
|
|
2571
|
+
};
|
|
2572
|
+
var features = (instance, opts, done) => {
|
|
2573
|
+
instance.features = /* @__PURE__ */ new Map();
|
|
2574
|
+
instance.sdk.getFeatures = () => instance.features;
|
|
2575
|
+
instance.initFeature = (overlay, source = "ORGANIZATION" /* ORGANIZATION */) => {
|
|
2576
|
+
const feature = initFeature(overlay, source, instance);
|
|
2577
|
+
instance.features.set(overlay.name, feature);
|
|
2578
|
+
};
|
|
2579
|
+
instance.updateFeature = (overlay, source) => {
|
|
2580
|
+
instance.features.get(overlay.name)?.update(overlay, source);
|
|
2581
|
+
};
|
|
2582
|
+
instance.destroyFeature = (overlay) => {
|
|
2583
|
+
instance.features.delete(overlay.name);
|
|
2584
|
+
};
|
|
2585
|
+
instance.reinitializeFeatures = async () => {
|
|
2586
|
+
const organizationSettings = await instance.stores.organizationSettings.getValue();
|
|
2587
|
+
instance.features.clear();
|
|
2588
|
+
for (const overlay of organizationSettings?.overlays || []) {
|
|
2589
|
+
instance.initFeature(overlay, "ORGANIZATION" /* ORGANIZATION */);
|
|
2590
|
+
}
|
|
2591
|
+
};
|
|
2592
|
+
instance.stores.providerStreamId.listen((eventId) => {
|
|
2593
|
+
if (!eventId) {
|
|
2594
|
+
void instance.reinitializeFeatures();
|
|
2595
|
+
}
|
|
2596
|
+
});
|
|
2597
|
+
done();
|
|
2598
|
+
};
|
|
2599
|
+
|
|
2600
|
+
// packages/sdk-web/src/index.ts
|
|
2601
|
+
import avvio from "avvio";
|
|
2602
|
+
|
|
2603
|
+
// packages/sdk-web-core/src/store/index.ts
|
|
2604
|
+
var store = (instance, opts, done) => {
|
|
2605
|
+
instance.store = new CoreStore(instance.transport);
|
|
2606
|
+
instance.stores = instance.store.getValues();
|
|
2607
|
+
instance.sdk.sdkStore = instance.store.getStore();
|
|
2608
|
+
instance.storeSubscribe = () => {
|
|
2609
|
+
const processSettings = (source, settings) => {
|
|
2610
|
+
if (!settings?.overlays)
|
|
2611
|
+
return;
|
|
2612
|
+
if (source === "STREAM" /* STREAM */) {
|
|
2613
|
+
instance.features.clear();
|
|
2614
|
+
}
|
|
2615
|
+
for (const overlay of settings.overlays) {
|
|
2616
|
+
const featureName = overlay.name;
|
|
2617
|
+
if (!instance.features.has(featureName)) {
|
|
2618
|
+
instance.initFeature(overlay, source);
|
|
2619
|
+
} else {
|
|
2620
|
+
instance.updateFeature(overlay, source);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
};
|
|
2624
|
+
const subscribes = {
|
|
2625
|
+
/**
|
|
2626
|
+
* During the initial SDK initialization, it's imperative to initialize features first,
|
|
2627
|
+
* followed by their direct subscriptions to store fields.
|
|
2628
|
+
* This section is currently in development, and it's
|
|
2629
|
+
* essential to implement checks to determine whether a feature
|
|
2630
|
+
* has already been initialized. If it has, events related to
|
|
2631
|
+
* that feature should be skipped. Conversely, if a feature is
|
|
2632
|
+
* missing in the new settings, it should be deinitialized.
|
|
2633
|
+
*/
|
|
2634
|
+
organizationSettings: (orgSettings) => {
|
|
2635
|
+
if (orgSettings.data) {
|
|
2636
|
+
try {
|
|
2637
|
+
processSettings("ORGANIZATION" /* ORGANIZATION */, orgSettings.data);
|
|
2638
|
+
} catch (err) {
|
|
2639
|
+
console.log(err);
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
},
|
|
2643
|
+
streamSettings: (streamSettings) => {
|
|
2644
|
+
if (streamSettings.data) {
|
|
2645
|
+
try {
|
|
2646
|
+
processSettings("STREAM" /* STREAM */, streamSettings.data);
|
|
2647
|
+
} catch (err) {
|
|
2648
|
+
console.log(err);
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
};
|
|
2653
|
+
instance.store.subscribe(subscribes);
|
|
2654
|
+
};
|
|
2655
|
+
instance.storeUnsubscribe = () => {
|
|
2656
|
+
instance.store.unsubscribe();
|
|
2657
|
+
};
|
|
2658
|
+
done();
|
|
2659
|
+
};
|
|
2660
|
+
|
|
2661
|
+
// packages/sdk-web-core/src/auth/bypass/index.ts
|
|
2662
|
+
var BypassAuth = class extends AbstractAuthenticationProvider {
|
|
2663
|
+
$coreStore;
|
|
2664
|
+
transport;
|
|
2665
|
+
$bypassLogin;
|
|
2666
|
+
constructor(store2, transport2) {
|
|
2667
|
+
super();
|
|
2668
|
+
this.$coreStore = store2;
|
|
2669
|
+
this.transport = transport2;
|
|
2670
|
+
this.$bypassLogin = queries_exports.$bypassLogin(this.transport);
|
|
2671
|
+
this.subscribe();
|
|
2672
|
+
}
|
|
2673
|
+
me = async () => {
|
|
2674
|
+
const res = await this.$coreStore.getValues().user.getValue();
|
|
2675
|
+
return res?.data;
|
|
2676
|
+
};
|
|
2677
|
+
login = async (schema, userKey) => {
|
|
2678
|
+
this.$coreStore.getValues().userKey.setValue(userKey);
|
|
2679
|
+
await this.$bypassLogin.mutate({ schema, userKey, init: false });
|
|
2680
|
+
return this.me();
|
|
2681
|
+
};
|
|
2682
|
+
isAuthenticated = () => {
|
|
2683
|
+
return this.me();
|
|
2684
|
+
};
|
|
2685
|
+
logout = () => {
|
|
2686
|
+
this.$coreStore.getValues().user.setValue();
|
|
2687
|
+
this.$coreStore.getValues().userKey.setValue();
|
|
2688
|
+
this.$coreStore.getValues().userToken.setValue();
|
|
2689
|
+
this.transport.setAuth("");
|
|
2690
|
+
};
|
|
2691
|
+
/**
|
|
2692
|
+
* subscribe to user store and set auth header to the Transport on user update
|
|
2693
|
+
*/
|
|
2694
|
+
subscribe = () => {
|
|
2695
|
+
this.$bypassLogin.subscribe((user, key) => {
|
|
2696
|
+
if (key === "data") {
|
|
2697
|
+
this.transport.setAuth(user?.data?.meta?.jwt);
|
|
2698
|
+
this.$coreStore.getValues().userToken.setValue(user?.data?.meta?.jwt);
|
|
2699
|
+
}
|
|
2700
|
+
});
|
|
2701
|
+
};
|
|
2702
|
+
};
|
|
2703
|
+
|
|
2704
|
+
// packages/sdk-web-core/src/auth/index.ts
|
|
2705
|
+
var bypass = async (instance, opts, done) => {
|
|
2706
|
+
instance.auth = new BypassAuth(instance.store, instance.transport);
|
|
2707
|
+
const prevUserSchema = localStorage.getItem("sl-user-schema");
|
|
2708
|
+
const prevUserToken = localStorage.getItem("sl-user-token");
|
|
2709
|
+
if (prevUserSchema && prevUserToken) {
|
|
2710
|
+
console.log("try to login prev user");
|
|
2711
|
+
await instance.auth.login(prevUserSchema, prevUserToken);
|
|
2712
|
+
}
|
|
2713
|
+
instance.sdk.authorizationBypass = async (schema, userKey) => {
|
|
2714
|
+
await instance.auth.login(schema, userKey);
|
|
2715
|
+
localStorage.setItem("sl-user-schema", schema);
|
|
2716
|
+
};
|
|
2717
|
+
instance.sdk.logout = () => {
|
|
2718
|
+
instance.auth.logout();
|
|
2719
|
+
};
|
|
2720
|
+
instance.sdk.getUserStore = () => {
|
|
2721
|
+
return instance.stores.user.getStore();
|
|
2722
|
+
};
|
|
2723
|
+
instance.sdk.isUserAuthorized = () => {
|
|
2724
|
+
return instance.auth.isAuthenticated();
|
|
2725
|
+
};
|
|
2726
|
+
done();
|
|
2727
|
+
};
|
|
2728
|
+
|
|
2729
|
+
// packages/sdk-web-core/src/notifications/notifications.ts
|
|
2730
|
+
var Notifications2 = class {
|
|
2731
|
+
queue;
|
|
2732
|
+
constructor() {
|
|
2733
|
+
this.queue = new SingleStore(createSingleStore([]), "notifications");
|
|
2734
|
+
}
|
|
2735
|
+
add = (notification) => {
|
|
2736
|
+
if (this.isNewNotify(notification.id)) {
|
|
2737
|
+
this.queue.getStore().set([...this.queue.getValue() || [], notification]);
|
|
2738
|
+
} else {
|
|
2739
|
+
console.log("skip notification:", notification);
|
|
2740
|
+
}
|
|
2741
|
+
};
|
|
2742
|
+
getQueueStore = () => {
|
|
2743
|
+
return this.queue.getStore();
|
|
2744
|
+
};
|
|
2745
|
+
isNewNotify = (id) => {
|
|
2746
|
+
const exist = localStorage.getItem(`opened:${id}`);
|
|
2747
|
+
return !exist;
|
|
2748
|
+
};
|
|
2749
|
+
markAsViewed = (id) => {
|
|
2750
|
+
localStorage.setItem(`opened:${id}`, id);
|
|
2751
|
+
};
|
|
2752
|
+
};
|
|
2753
|
+
|
|
2754
|
+
// packages/sdk-web-core/src/notifications/index.ts
|
|
2755
|
+
var notifications = (instance, opts, done) => {
|
|
2756
|
+
instance.notifications = new Notifications2();
|
|
2757
|
+
instance.addNotification = instance.notifications.add;
|
|
2758
|
+
instance.sdk.getNotificationsStore = () => instance.notifications.getQueueStore();
|
|
2759
|
+
done();
|
|
2760
|
+
};
|
|
2761
|
+
|
|
2762
|
+
// packages/sdk-web/src/index.ts
|
|
2763
|
+
function StreamLayer(sdkKey) {
|
|
2764
|
+
const streamLayer = avvio(/* @__PURE__ */ Object.create(null), { autostart: false });
|
|
2765
|
+
streamLayer.use(core);
|
|
2766
|
+
streamLayer.use(transport, { sdkKey });
|
|
2767
|
+
streamLayer.use(store);
|
|
2768
|
+
streamLayer.use(bypass);
|
|
2769
|
+
streamLayer.use(features);
|
|
2770
|
+
streamLayer.use(notifications);
|
|
2771
|
+
streamLayer.after(async (err, context, done) => {
|
|
2772
|
+
if (err) {
|
|
2773
|
+
throw err;
|
|
2774
|
+
}
|
|
2775
|
+
await context.sdk.initializeApp();
|
|
2776
|
+
done();
|
|
2777
|
+
});
|
|
2778
|
+
streamLayer.onClose(() => {
|
|
2779
|
+
console.log("close");
|
|
2780
|
+
});
|
|
2781
|
+
return streamLayer;
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2784
|
+
// packages/react/src/app/useStreamLayer.ts
|
|
2785
|
+
import { useState as useState4, useEffect as useEffect3 } from "react";
|
|
2786
|
+
window.instance = null;
|
|
2787
|
+
var useStreamLayer = (sdkKey, plugins) => {
|
|
2788
|
+
const [sdk, setSdk] = useState4(null);
|
|
2789
|
+
useEffect3(() => {
|
|
2790
|
+
let ignore = false;
|
|
2791
|
+
if (!sdkKey) {
|
|
2792
|
+
throw new Error("sdk key should be provided");
|
|
2793
|
+
}
|
|
2794
|
+
const instance = StreamLayer(sdkKey);
|
|
2795
|
+
if (plugins) {
|
|
2796
|
+
for (const plugin of plugins) {
|
|
2797
|
+
instance.use(plugin);
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
instance.ready().then((service) => {
|
|
2801
|
+
if (!ignore) {
|
|
2802
|
+
window.instance = service;
|
|
2803
|
+
setSdk(service.sdk);
|
|
2804
|
+
}
|
|
2805
|
+
}).catch((err) => console.log(err));
|
|
2806
|
+
return () => {
|
|
2807
|
+
ignore = true;
|
|
2808
|
+
instance.close(function(err) {
|
|
2809
|
+
if (err)
|
|
2810
|
+
throw err;
|
|
2811
|
+
});
|
|
2812
|
+
};
|
|
2813
|
+
}, [sdkKey]);
|
|
2814
|
+
return sdk;
|
|
2815
|
+
};
|
|
2816
|
+
|
|
2817
|
+
// packages/react/src/app/provider.tsx
|
|
2818
|
+
import { jsx as jsx37 } from "@emotion/react/jsx-runtime";
|
|
2819
|
+
var StreamLayerContext3 = createContext({
|
|
2820
|
+
status: 0 /* UNSET */
|
|
2821
|
+
});
|
|
2822
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2823
|
+
StreamLayerContext3.displayName = "StreamLayerProvider";
|
|
2824
|
+
}
|
|
2825
|
+
var StreamLayerProvider = ({
|
|
2826
|
+
sdkKey,
|
|
2827
|
+
plugins,
|
|
2828
|
+
children
|
|
2829
|
+
}) => {
|
|
2830
|
+
const streamLayer = useStreamLayer(sdkKey, plugins);
|
|
2831
|
+
const value = useMemo2(() => {
|
|
2832
|
+
if (!streamLayer) {
|
|
2833
|
+
return { status: 1 /* CONNECTED */ };
|
|
2834
|
+
}
|
|
2835
|
+
return { sdk: streamLayer, status: 2 /* READY */ };
|
|
2836
|
+
}, [streamLayer]);
|
|
2837
|
+
return /* @__PURE__ */ jsx37(StreamLayerThemeProvider, { children: /* @__PURE__ */ jsx37(StreamLayerContext3.Provider, { value, children }) });
|
|
2838
|
+
};
|
|
2839
|
+
|
|
2840
|
+
// packages/react/src/app/app.tsx
|
|
2841
|
+
import { useContext } from "react";
|
|
2842
|
+
import { jsx as jsx38 } from "@emotion/react/jsx-runtime";
|
|
2843
|
+
var useSDK = () => {
|
|
2844
|
+
const { sdk } = useContext(StreamLayerContext3);
|
|
2845
|
+
return sdk;
|
|
2846
|
+
};
|
|
2847
|
+
var StreamLayerSDKReact = () => {
|
|
2848
|
+
const { sdk, status } = useContext(StreamLayerContext3);
|
|
2849
|
+
if (status === 0 /* UNSET */) {
|
|
2850
|
+
throw new Error("Wrap app in `StreamLayerProvider`");
|
|
2851
|
+
}
|
|
2852
|
+
if (status === 1 /* CONNECTED */) {
|
|
2853
|
+
return /* @__PURE__ */ jsx38("div", { children: "wait" });
|
|
2854
|
+
}
|
|
2855
|
+
if (sdk === void 0) {
|
|
2856
|
+
return /* @__PURE__ */ jsx38("div", { children: "sdk not initialized" });
|
|
2857
|
+
}
|
|
2858
|
+
return /* @__PURE__ */ jsx38(Demo, { sdk });
|
|
2859
|
+
};
|
|
2860
|
+
export {
|
|
2861
|
+
StreamLayerProvider,
|
|
2862
|
+
StreamLayerSDKReact,
|
|
2863
|
+
useSDK,
|
|
2864
|
+
useStreamLayer
|
|
2865
|
+
};
|