@learningpool/ui 1.15.0 → 1.15.2
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.
|
@@ -51,30 +51,36 @@ import { AppHubRow } from './AppHubStyles';
|
|
|
51
51
|
import Grid from '@mui/material/Unstable_Grid2';
|
|
52
52
|
import { StyledAdvertPaper, StyledAdvertLink, StyledAdvertImage } from './AppHubAdvertStyles';
|
|
53
53
|
var addUtmParams = function (baseUrl, source, medium, campaign) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
try {
|
|
55
|
+
var url = new URL(baseUrl);
|
|
56
|
+
url.searchParams.append('utm_source', source);
|
|
57
|
+
url.searchParams.append('utm_medium', medium);
|
|
58
|
+
url.searchParams.append('utm_campaign', campaign);
|
|
59
|
+
return url.toString();
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error('Invalid Banner Advert URL provided:', error);
|
|
63
|
+
return baseUrl;
|
|
64
|
+
}
|
|
59
65
|
};
|
|
60
|
-
var checkImageExists = function (url) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
var checkImageExists = function (url) {
|
|
67
|
+
return new Promise(function (resolve) {
|
|
68
|
+
var img = new window.Image();
|
|
69
|
+
var timeoutId = setTimeout(function () {
|
|
70
|
+
resolve(false);
|
|
71
|
+
}, 5000);
|
|
72
|
+
img.onload = function () {
|
|
73
|
+
clearTimeout(timeoutId);
|
|
74
|
+
resolve(true);
|
|
75
|
+
};
|
|
76
|
+
img.onerror = function (error) {
|
|
77
|
+
clearTimeout(timeoutId);
|
|
78
|
+
console.error('Banner Image failed to load:', url, error);
|
|
79
|
+
resolve(false);
|
|
80
|
+
};
|
|
81
|
+
img.src = url;
|
|
76
82
|
});
|
|
77
|
-
}
|
|
83
|
+
};
|
|
78
84
|
export var renderBannerAdvertRow = function (rowData, rowIndex) {
|
|
79
85
|
var items = rowData.items;
|
|
80
86
|
var _a = useState([]), validAdverts = _a[0], setValidAdverts = _a[1];
|
|
@@ -88,8 +94,8 @@ export var renderBannerAdvertRow = function (rowData, rowIndex) {
|
|
|
88
94
|
return __generator(this, function (_a) {
|
|
89
95
|
switch (_a.label) {
|
|
90
96
|
case 0:
|
|
91
|
-
if (!item.
|
|
92
|
-
return [4 /*yield*/, checkImageExists(item.
|
|
97
|
+
if (!item.hubImageUrl) return [3 /*break*/, 2];
|
|
98
|
+
return [4 /*yield*/, checkImageExists(item.hubImageUrl)];
|
|
93
99
|
case 1:
|
|
94
100
|
isValid = _a.sent();
|
|
95
101
|
return [2 /*return*/, isValid ? item : null];
|
|
@@ -107,7 +113,8 @@ export var renderBannerAdvertRow = function (rowData, rowIndex) {
|
|
|
107
113
|
validateImages();
|
|
108
114
|
}, [items]);
|
|
109
115
|
if (validAdverts.length === 0) {
|
|
116
|
+
console.error('No valid images found for banner adverts');
|
|
110
117
|
return null; // Don't render the row if no valid images
|
|
111
118
|
}
|
|
112
|
-
return (_jsx(AppHubRow, { children: _jsx(Grid, __assign({ container: true, spacing: 2 }, { children: validAdverts.map(function (item, index) { return (_jsx(Grid, __assign({ xs: 12 }, { children: _jsx(StyledAdvertPaper, __assign({ elevation: 0 }, { children: _jsx(StyledAdvertLink, __assign({ href: addUtmParams(item.
|
|
119
|
+
return (_jsx(AppHubRow, { children: _jsx(Grid, __assign({ container: true, spacing: 2 }, { children: validAdverts.map(function (item, index) { return (_jsx(Grid, __assign({ xs: 12 }, { children: _jsx(StyledAdvertPaper, __assign({ elevation: 0 }, { children: _jsx(StyledAdvertLink, __assign({ href: addUtmParams(item.basePromoUrl, 'stream-home', 'App-Hub-Banner-Advert', item.name), target: "_blank" }, { children: _jsx(StyledAdvertImage, { src: item.hubImageUrl, alt: item.altText }) })) })) }), index)); }) })) }, "row_".concat(rowIndex)));
|
|
113
120
|
};
|
|
@@ -31,10 +31,10 @@ interface IProps {
|
|
|
31
31
|
declare const AppSwitcher: {
|
|
32
32
|
(props: IProps): ReactElement | null;
|
|
33
33
|
propTypes: {
|
|
34
|
-
|
|
34
|
+
token: PropTypes.Requireable<string>;
|
|
35
35
|
apiKey: PropTypes.Requireable<string>;
|
|
36
36
|
layout: PropTypes.Requireable<string>;
|
|
37
|
-
userId: PropTypes.Requireable<
|
|
37
|
+
userId: PropTypes.Requireable<string>;
|
|
38
38
|
baseUrl: PropTypes.Requireable<string>;
|
|
39
39
|
localization: PropTypes.Requireable<object>;
|
|
40
40
|
currentApplicationId: PropTypes.Requireable<number>;
|
|
@@ -57,11 +57,17 @@ import { defaultAttributes } from '../../../utils/dataAttributes';
|
|
|
57
57
|
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
|
58
58
|
import PromotionalCampaignItem from './PromotionalCampaignItem';
|
|
59
59
|
var addUtmParams = function (baseUrl, source, medium, campaign) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
try {
|
|
61
|
+
var url = new URL(baseUrl);
|
|
62
|
+
url.searchParams.append('utm_source', source);
|
|
63
|
+
url.searchParams.append('utm_medium', medium);
|
|
64
|
+
url.searchParams.append('utm_campaign', campaign);
|
|
65
|
+
return url.toString();
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error('Error adding UTM params to advert redirect - invalid URL:', baseUrl, error);
|
|
69
|
+
return baseUrl;
|
|
70
|
+
}
|
|
65
71
|
};
|
|
66
72
|
var AppSwitcher = function (props) {
|
|
67
73
|
var _a;
|
|
@@ -87,15 +93,13 @@ var AppSwitcher = function (props) {
|
|
|
87
93
|
* @returns {Promise<IApplication[]>} Get a Promotional Campaign to show.
|
|
88
94
|
*/
|
|
89
95
|
var getLatestPromotionalCampaign = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
90
|
-
var
|
|
96
|
+
var response, responseData, data, error_1;
|
|
91
97
|
return __generator(this, function (_a) {
|
|
92
98
|
switch (_a.label) {
|
|
93
99
|
case 0:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
decodedToken = jwtDecode(token);
|
|
98
|
-
userId = decodedToken[Constants.HomeAttributes.UserId];
|
|
100
|
+
// If the access token has changed the endpoint should be called again.
|
|
101
|
+
if (!token || typeof token !== 'string') {
|
|
102
|
+
return [2 /*return*/, null];
|
|
99
103
|
}
|
|
100
104
|
_a.label = 1;
|
|
101
105
|
case 1:
|
|
@@ -109,39 +113,33 @@ var AppSwitcher = function (props) {
|
|
|
109
113
|
})];
|
|
110
114
|
case 2:
|
|
111
115
|
response = _a.sent();
|
|
112
|
-
if (response.
|
|
113
|
-
console.error('Unable to retrieve latest promotional campaign from
|
|
116
|
+
if (!response.ok) {
|
|
117
|
+
console.error('Unable to retrieve latest promotional campaign from Hub API, returned statuscode:', response.status);
|
|
114
118
|
return [2 /*return*/, null];
|
|
115
119
|
}
|
|
116
|
-
return [4 /*yield*/, response.json()
|
|
117
|
-
// Store the latest access token.
|
|
118
|
-
];
|
|
120
|
+
return [4 /*yield*/, response.json()];
|
|
119
121
|
case 3:
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
responseData = _a.sent();
|
|
123
|
+
data = responseData.records;
|
|
124
|
+
// Store the latest access token
|
|
122
125
|
window.localStorage.setItem(Constants.LocalStorageKey.Token, token);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
})];
|
|
136
|
-
}
|
|
137
|
-
return [3 /*break*/, 5];
|
|
126
|
+
return [2 /*return*/, (data === null || data === void 0 ? void 0 : data.map(function (_a) {
|
|
127
|
+
var id = _a.id, name = _a.name, appSwitcherImageUrl = _a.appSwitcherImageUrl, hubImageUrl = _a.hubImageUrl, altText = _a.altText, basePromoUrl = _a.basePromoUrl, isActive = _a.isActive;
|
|
128
|
+
return ({
|
|
129
|
+
id: id,
|
|
130
|
+
name: name,
|
|
131
|
+
appSwitcherImageUrl: appSwitcherImageUrl,
|
|
132
|
+
hubImageUrl: hubImageUrl,
|
|
133
|
+
altText: altText,
|
|
134
|
+
basePromoUrl: basePromoUrl,
|
|
135
|
+
isActive: isActive
|
|
136
|
+
});
|
|
137
|
+
})) || null];
|
|
138
138
|
case 4:
|
|
139
139
|
error_1 = _a.sent();
|
|
140
|
-
console.error('Unable to retrieve latest promotional campaign from
|
|
140
|
+
console.error('Unable to retrieve and display latest promotional campaign from Hub API', error_1);
|
|
141
141
|
return [2 /*return*/, null];
|
|
142
|
-
case 5: return [
|
|
143
|
-
case 6: return [2 /*return*/, null];
|
|
144
|
-
case 7: return [2 /*return*/, null];
|
|
142
|
+
case 5: return [2 /*return*/];
|
|
145
143
|
}
|
|
146
144
|
});
|
|
147
145
|
}); };
|
|
@@ -246,13 +244,12 @@ var AppSwitcher = function (props) {
|
|
|
246
244
|
}); };
|
|
247
245
|
useEffect(function () {
|
|
248
246
|
var loadData = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
249
|
-
var applicationInstances, userApplications,
|
|
247
|
+
var applicationInstances, userApplications, parsedQueryString, match, uniqueApplicationIds, localApplications;
|
|
250
248
|
return __generator(this, function (_a) {
|
|
251
249
|
switch (_a.label) {
|
|
252
250
|
case 0:
|
|
253
251
|
applicationInstances = [];
|
|
254
252
|
userApplications = [];
|
|
255
|
-
promotionalCampaigns = null;
|
|
256
253
|
if (!token) {
|
|
257
254
|
parsedQueryString = queryString.parse(window.location.search);
|
|
258
255
|
if (parsedQueryString.token && typeof parsedQueryString.token === 'string') {
|
|
@@ -320,37 +317,68 @@ var AppSwitcher = function (props) {
|
|
|
320
317
|
}
|
|
321
318
|
// Store the user's applications.
|
|
322
319
|
setApplications(userApplications);
|
|
323
|
-
|
|
320
|
+
return [2 /*return*/];
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}); };
|
|
324
|
+
loadData()
|
|
325
|
+
.catch(console.error);
|
|
326
|
+
}, [token, userId, props.applications]);
|
|
327
|
+
useEffect(function () {
|
|
328
|
+
var loadPromotionalCampaigns = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
329
|
+
var promotionalCampaigns_1, localPromotionalCampaignsJson, parsedCampaigns, error_2;
|
|
330
|
+
return __generator(this, function (_a) {
|
|
331
|
+
switch (_a.label) {
|
|
332
|
+
case 0:
|
|
333
|
+
_a.trys.push([0, 5, , 6]);
|
|
334
|
+
promotionalCampaigns_1 = null;
|
|
335
|
+
if (!(props.promotionalCampaigns && props.promotionalCampaigns.length > 0)) return [3 /*break*/, 1];
|
|
336
|
+
promotionalCampaigns_1 = props.promotionalCampaigns;
|
|
337
|
+
return [3 /*break*/, 4];
|
|
338
|
+
case 1:
|
|
339
|
+
if (!(token && typeof token === 'string' &&
|
|
340
|
+
token !== window.localStorage.getItem(Constants.LocalStorageKey.Token))) return [3 /*break*/, 3];
|
|
324
341
|
return [4 /*yield*/, getLatestPromotionalCampaign()];
|
|
325
|
-
case
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
// Serialize and cache the promotional campaigns returned.
|
|
334
|
-
window.localStorage.setItem(Constants.LocalStorageKey.PromotionalCampaigns, JSON.stringify(promotionalCampaigns));
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
localPromotionalCampaignsJson = window.localStorage.getItem(Constants.LocalStorageKey.PromotionalCampaigns);
|
|
338
|
-
if (localPromotionalCampaignsJson) {
|
|
342
|
+
case 2:
|
|
343
|
+
// Fetch from API if token has changed
|
|
344
|
+
promotionalCampaigns_1 = _a.sent();
|
|
345
|
+
return [3 /*break*/, 4];
|
|
346
|
+
case 3:
|
|
347
|
+
localPromotionalCampaignsJson = window.localStorage.getItem(Constants.LocalStorageKey.PromotionalCampaigns);
|
|
348
|
+
if (localPromotionalCampaignsJson) {
|
|
349
|
+
try {
|
|
339
350
|
parsedCampaigns = JSON.parse(localPromotionalCampaignsJson);
|
|
340
|
-
// Type assertion to ensure type safety
|
|
341
351
|
if (Array.isArray(parsedCampaigns)) {
|
|
342
|
-
|
|
352
|
+
promotionalCampaigns_1 = parsedCampaigns;
|
|
343
353
|
}
|
|
344
354
|
}
|
|
345
|
-
|
|
355
|
+
catch (error) {
|
|
356
|
+
console.error('Error parsing stored campaigns:', error);
|
|
357
|
+
}
|
|
346
358
|
}
|
|
347
|
-
|
|
359
|
+
_a.label = 4;
|
|
360
|
+
case 4:
|
|
361
|
+
// Update state and cache if we have campaigns
|
|
362
|
+
if (Array.isArray(promotionalCampaigns_1) && promotionalCampaigns_1.length > 0) {
|
|
363
|
+
setPromotionalCampaigns(promotionalCampaigns_1);
|
|
364
|
+
window.localStorage.setItem(Constants.LocalStorageKey.PromotionalCampaigns, JSON.stringify(promotionalCampaigns_1));
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
setPromotionalCampaigns(null);
|
|
368
|
+
}
|
|
369
|
+
return [3 /*break*/, 6];
|
|
370
|
+
case 5:
|
|
371
|
+
error_2 = _a.sent();
|
|
372
|
+
console.error('Error loading promotional campaigns:', error_2);
|
|
373
|
+
setPromotionalCampaigns(null);
|
|
374
|
+
return [3 /*break*/, 6];
|
|
375
|
+
case 6: return [2 /*return*/];
|
|
348
376
|
}
|
|
349
377
|
});
|
|
350
378
|
}); };
|
|
351
|
-
|
|
379
|
+
loadPromotionalCampaigns()
|
|
352
380
|
.catch(console.error);
|
|
353
|
-
}, [token,
|
|
381
|
+
}, [token, props.promotionalCampaigns]);
|
|
354
382
|
useEffect(function () {
|
|
355
383
|
if (isAppSwitcherOpen) {
|
|
356
384
|
document.addEventListener('mousedown', handleAppSwitcherClose);
|
|
@@ -374,7 +402,7 @@ var AppSwitcher = function (props) {
|
|
|
374
402
|
// Close AppSwitcher if Escape key is pressed
|
|
375
403
|
if (event.key === 'Escape') {
|
|
376
404
|
handleDialogClose();
|
|
377
|
-
//
|
|
405
|
+
// Doesn't return focus but we need to investigate MUI again
|
|
378
406
|
// so that should handle it
|
|
379
407
|
}
|
|
380
408
|
}
|
|
@@ -405,10 +433,10 @@ var AppSwitcher = function (props) {
|
|
|
405
433
|
: null] })));
|
|
406
434
|
};
|
|
407
435
|
AppSwitcher.propTypes = {
|
|
408
|
-
|
|
436
|
+
token: PropTypes.string,
|
|
409
437
|
apiKey: PropTypes.string,
|
|
410
438
|
layout: PropTypes.string,
|
|
411
|
-
userId: PropTypes.
|
|
439
|
+
userId: PropTypes.string,
|
|
412
440
|
baseUrl: PropTypes.string,
|
|
413
441
|
localization: PropTypes.object,
|
|
414
442
|
currentApplicationId: PropTypes.number,
|
|
@@ -53,7 +53,7 @@ export var StyleHomeButton = styled(Button)(templateObject_17 || (templateObject
|
|
|
53
53
|
export var PromotionalCampaignImage = styled(CardMedia)(templateObject_18 || (templateObject_18 = __makeTemplateObject(["\n height: 150px;\n width: 300px;\n"], ["\n height: 150px;\n width: 300px;\n"])));
|
|
54
54
|
export var PromotionalCampaignCard = styled(Card)(templateObject_19 || (templateObject_19 = __makeTemplateObject(["\n background: ", ";\n "], ["\n background: ", ";\n "])), function (props) { return props.theme.palette.primary.main; });
|
|
55
55
|
export var PromotionalCampaignCardStyled = styled(Card)(templateObject_20 || (templateObject_20 = __makeTemplateObject(["\n width: 100%;\n height: 162px;\n margin-bottom: 4px;\n background: ", ";\n"], ["\n width: 100%;\n height: 162px;\n margin-bottom: 4px;\n background: ", ";\n"])), function (props) { return props.theme.palette.primary.main; });
|
|
56
|
-
export var PromotionalCampaignCardActionArea = styled(CardActionArea)(templateObject_21 || (templateObject_21 = __makeTemplateObject(["\n width: 100%;\n height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n padding:
|
|
56
|
+
export var PromotionalCampaignCardActionArea = styled(CardActionArea)(templateObject_21 || (templateObject_21 = __makeTemplateObject(["\n width: 100%;\n height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n padding: 6px;\n"], ["\n width: 100%;\n height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n padding: 6px;\n"])));
|
|
57
57
|
export var PromotionalCampaignCardMedia = styled(CardMedia)(function () { return ({
|
|
58
58
|
width: '100%',
|
|
59
59
|
height: '100%',
|