@learningpool/ui 1.14.0 → 1.15.1
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/components/stream/AppHub/AppHub.js +4 -0
- package/components/stream/AppHub/AppHubAdvertStyles.d.ts +13 -0
- package/components/stream/AppHub/AppHubAdvertStyles.js +10 -0
- package/components/stream/AppHub/AppHubBannerAdvert.d.ts +3 -0
- package/components/stream/AppHub/AppHubBannerAdvert.js +120 -0
- package/components/stream/AppHub/AppHubStyles.js +2 -2
- package/components/stream/AppHub/constants.d.ts +6 -0
- package/components/stream/AppHub/constants.js +7 -1
- package/components/stream/AppSwitcher/AppSwitcher.d.ts +2 -2
- package/components/stream/AppSwitcher/AppSwitcher.js +76 -53
- package/components/stream/AppSwitcher/AppSwitcherStyles.js +1 -1
- package/components/stream/AppSwitcher/constants.js +2 -2
- package/package.json +1 -1
|
@@ -27,6 +27,7 @@ import AppHubCustom from './AppHubCustom';
|
|
|
27
27
|
import { AppHubPanel, AppHubTitle, AppHubHeader, AppHubRow } from './AppHubStyles';
|
|
28
28
|
import Grid from '@mui/material/Unstable_Grid2';
|
|
29
29
|
import { Constants } from './constants';
|
|
30
|
+
import { renderBannerAdvertRow } from './AppHubBannerAdvert';
|
|
30
31
|
var AppHub = function (props) {
|
|
31
32
|
var isPageLayout = props.isPageLayout, localization = props.localization, customLinkBgColor = props.customLinkBgColor, data = props.data;
|
|
32
33
|
var messages = __assign(__assign({}, defaultMessages), localization);
|
|
@@ -34,6 +35,9 @@ var AppHub = function (props) {
|
|
|
34
35
|
var _a, _b;
|
|
35
36
|
var type = rowData.type, items = rowData.items, title = rowData.title, addButton = rowData.addButton;
|
|
36
37
|
switch (type) {
|
|
38
|
+
case Constants.DataRowType.BannerAdvert: {
|
|
39
|
+
return (renderBannerAdvertRow(rowData, rowIndex));
|
|
40
|
+
}
|
|
37
41
|
case Constants.DataRowType.Product: {
|
|
38
42
|
return (_jsxs(AppHubRow, { children: [title && _jsx(AppHubHeader
|
|
39
43
|
// @ts-ignore
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const StyledAdvertPaper: import("@emotion/styled").StyledComponent<{
|
|
3
|
+
children?: import("react").ReactNode;
|
|
4
|
+
classes?: Partial<import("@mui/material").PaperClasses> | undefined;
|
|
5
|
+
elevation?: number | undefined;
|
|
6
|
+
square?: boolean | undefined;
|
|
7
|
+
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
8
|
+
variant?: "outlined" | "elevation" | undefined;
|
|
9
|
+
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
10
|
+
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
11
|
+
}, keyof import("@mui/material/OverridableComponent").CommonProps | "children" | "sx" | "variant" | "square" | "elevation"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
12
|
+
export declare const StyledAdvertLink: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, import("react").DetailedHTMLProps<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, {}>;
|
|
13
|
+
export declare const StyledAdvertImage: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, import("react").DetailedHTMLProps<import("react").ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, {}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
2
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
+
return cooked;
|
|
4
|
+
};
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
6
|
+
import { Paper } from '@mui/material';
|
|
7
|
+
export var StyledAdvertPaper = styled(Paper)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: 100%;\n height: 138px;\n overflow: hidden;\n position: relative;\n box-shadow: 0 0 0 1px #ddd;\n border-radius: 10px;\n border: #ddd;\n transition: all 180ms ease;\n"], ["\n width: 100%;\n height: 138px;\n overflow: hidden;\n position: relative;\n box-shadow: 0 0 0 1px #ddd;\n border-radius: 10px;\n border: #ddd;\n transition: all 180ms ease;\n"])));
|
|
8
|
+
export var StyledAdvertLink = styled('a')(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: block;\n width: 100%;\n height: 100%;\n"], ["\n display: block;\n width: 100%;\n height: 100%;\n"])));
|
|
9
|
+
export var StyledAdvertImage = styled('img')(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 100%;\n height: 100%;\n object-fit: cover;\n"], ["\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 100%;\n height: 100%;\n object-fit: cover;\n"])));
|
|
10
|
+
var templateObject_1, templateObject_2, templateObject_3;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
49
|
+
import { useState, useEffect } from 'react';
|
|
50
|
+
import { AppHubRow } from './AppHubStyles';
|
|
51
|
+
import Grid from '@mui/material/Unstable_Grid2';
|
|
52
|
+
import { StyledAdvertPaper, StyledAdvertLink, StyledAdvertImage } from './AppHubAdvertStyles';
|
|
53
|
+
var addUtmParams = function (baseUrl, source, medium, campaign) {
|
|
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
|
+
}
|
|
65
|
+
};
|
|
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;
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
export var renderBannerAdvertRow = function (rowData, rowIndex) {
|
|
85
|
+
var items = rowData.items;
|
|
86
|
+
var _a = useState([]), validAdverts = _a[0], setValidAdverts = _a[1];
|
|
87
|
+
useEffect(function () {
|
|
88
|
+
var validateImages = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
89
|
+
var validatedItems;
|
|
90
|
+
return __generator(this, function (_a) {
|
|
91
|
+
switch (_a.label) {
|
|
92
|
+
case 0: return [4 /*yield*/, Promise.all(items.map(function (item) { return __awaiter(void 0, void 0, void 0, function () {
|
|
93
|
+
var isValid;
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
switch (_a.label) {
|
|
96
|
+
case 0:
|
|
97
|
+
if (!item.hubImageUrl) return [3 /*break*/, 2];
|
|
98
|
+
return [4 /*yield*/, checkImageExists(item.hubImageUrl)];
|
|
99
|
+
case 1:
|
|
100
|
+
isValid = _a.sent();
|
|
101
|
+
return [2 /*return*/, isValid ? item : null];
|
|
102
|
+
case 2: return [2 /*return*/, null];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}); }))];
|
|
106
|
+
case 1:
|
|
107
|
+
validatedItems = _a.sent();
|
|
108
|
+
setValidAdverts(validatedItems.filter(function (item) { return item !== null; }));
|
|
109
|
+
return [2 /*return*/];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}); };
|
|
113
|
+
validateImages();
|
|
114
|
+
}, [items]);
|
|
115
|
+
if (validAdverts.length === 0) {
|
|
116
|
+
console.error('No valid images found for banner adverts');
|
|
117
|
+
return null; // Don't render the row if no valid images
|
|
118
|
+
}
|
|
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)));
|
|
120
|
+
};
|
|
@@ -5,8 +5,8 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
5
5
|
import { styled } from '@mui/material/styles';
|
|
6
6
|
import { Paper, Box, Typography } from '../../../index';
|
|
7
7
|
export var AppHubPanel = styled('div')(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n padding: 1rem;\n max-width: 1000px;\n"], ["\n padding: 1rem;\n max-width: 1000px;\n"])));
|
|
8
|
-
export var AppHubRow = styled(Box)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n margin:
|
|
9
|
-
export var AppHubTitle = styled(Typography)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n font-size: 2rem;\n font-weight: 700;\n line-height: 1.3;\n color: ", ";\n margin-bottom:
|
|
8
|
+
export var AppHubRow = styled(Box)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n margin: 2rem 0 0;\n"], ["\n margin: 2rem 0 0;\n"])));
|
|
9
|
+
export var AppHubTitle = styled(Typography)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n font-size: 2rem;\n font-weight: 700;\n line-height: 1.3;\n color: ", ";\n margin-bottom: 0.5rem;\n"], ["\n font-size: 2rem;\n font-weight: 700;\n line-height: 1.3;\n color: ", ";\n margin-bottom: 0.5rem;\n"])), function (props) { return props.theme.palette.text.primary; });
|
|
10
10
|
export var AppHubHeader = styled(Typography)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n font-size: 1rem;\n font-weight: 500;\n color: ", ";\n margin: 0 0 1rem;\n"], ["\n font-size: 1rem;\n font-weight: 500;\n color: ", ";\n margin: 0 0 1rem;\n"])), function (props) { return props.theme.palette.text.secondary; });
|
|
11
11
|
export var StyledPaper = styled(Paper)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n display: flex;\n flex-direction: row;\n width: 100%;\n height: 100%;\n background: #fff;\n"], ["\n display: flex;\n flex-direction: row;\n width: 100%;\n height: 100%;\n background: #fff;\n"])));
|
|
12
12
|
export var StyledBox = styled(Box)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n"], ["\n display: flex;\n flex-direction: column;\n"])));
|
|
@@ -3,6 +3,7 @@ export declare const Constants: Readonly<{
|
|
|
3
3
|
DataRowType: {
|
|
4
4
|
Product: string;
|
|
5
5
|
CustomLink: string;
|
|
6
|
+
BannerAdvert: string;
|
|
6
7
|
};
|
|
7
8
|
AssetsUrl: "https://uuicdn.learningpool.com/";
|
|
8
9
|
AddButtonOrder: {
|
|
@@ -83,3 +84,8 @@ export declare const hubSupportItems: {
|
|
|
83
84
|
url: string;
|
|
84
85
|
icon: JSX.Element;
|
|
85
86
|
}[];
|
|
87
|
+
export declare const hubBannerAdverts: {
|
|
88
|
+
name: string;
|
|
89
|
+
imageUrl: string;
|
|
90
|
+
url: string;
|
|
91
|
+
}[];
|
|
@@ -3,7 +3,8 @@ import HomeIcon from '@mui/icons-material/Home';
|
|
|
3
3
|
export var Constants = Object.freeze({
|
|
4
4
|
DataRowType: {
|
|
5
5
|
Product: 'product',
|
|
6
|
-
CustomLink: 'custom-link'
|
|
6
|
+
CustomLink: 'custom-link',
|
|
7
|
+
BannerAdvert: 'banner-advert'
|
|
7
8
|
},
|
|
8
9
|
AssetsUrl: 'https://uuicdn.learningpool.com/',
|
|
9
10
|
AddButtonOrder: {
|
|
@@ -55,3 +56,8 @@ export var hubCustomLinks = [
|
|
|
55
56
|
export var hubSupportItems = [
|
|
56
57
|
{ name: 'Contact us', url: 'https://learningpool.com', icon: _jsx(HomeIcon, {}) }
|
|
57
58
|
];
|
|
59
|
+
export var hubBannerAdverts = [
|
|
60
|
+
{ name: 'Banner Advert', imageUrl: 'https://uuicdn.learningpool.com/promotionalcampaigns/banner/latest/1000x138.png', url: 'https://learningpool.com' },
|
|
61
|
+
{ name: 'Another Banner Advert no image', imageUrl: '3', url: 'https://learningpool.com' },
|
|
62
|
+
{ name: 'Another Banner Advert', imageUrl: 'https://uuicdn.learningpool.com/promotionalcampaigns/banner/latest/1000x138.png', url: 'https://learningpool.com' }
|
|
63
|
+
];
|
|
@@ -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>;
|
|
@@ -58,7 +58,7 @@ import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
|
|
58
58
|
import PromotionalCampaignItem from './PromotionalCampaignItem';
|
|
59
59
|
var addUtmParams = function (baseUrl, source, medium, campaign) {
|
|
60
60
|
var url = new URL(baseUrl);
|
|
61
|
-
url.searchParams.append('utm_source
|
|
61
|
+
url.searchParams.append('utm_source', source);
|
|
62
62
|
url.searchParams.append('utm_medium', medium);
|
|
63
63
|
url.searchParams.append('utm_campaign', campaign);
|
|
64
64
|
return url.toString();
|
|
@@ -87,15 +87,13 @@ var AppSwitcher = function (props) {
|
|
|
87
87
|
* @returns {Promise<IApplication[]>} Get a Promotional Campaign to show.
|
|
88
88
|
*/
|
|
89
89
|
var getLatestPromotionalCampaign = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
90
|
-
var
|
|
90
|
+
var response, data, error_1;
|
|
91
91
|
return __generator(this, function (_a) {
|
|
92
92
|
switch (_a.label) {
|
|
93
93
|
case 0:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
decodedToken = jwtDecode(token);
|
|
98
|
-
userId = decodedToken[Constants.HomeAttributes.UserId];
|
|
94
|
+
// If the access token has changed the endpoint should be called again.
|
|
95
|
+
if (!token || typeof token !== 'string') {
|
|
96
|
+
return [2 /*return*/, null];
|
|
99
97
|
}
|
|
100
98
|
_a.label = 1;
|
|
101
99
|
case 1:
|
|
@@ -109,8 +107,8 @@ var AppSwitcher = function (props) {
|
|
|
109
107
|
})];
|
|
110
108
|
case 2:
|
|
111
109
|
response = _a.sent();
|
|
112
|
-
if (response.
|
|
113
|
-
console.error('Unable to retrieve latest promotional campaign from Stream Home');
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
console.error('Unable to retrieve latest promotional campaign from Stream Home, statuscode:', response.status);
|
|
114
112
|
return [2 /*return*/, null];
|
|
115
113
|
}
|
|
116
114
|
return [4 /*yield*/, response.json()
|
|
@@ -120,28 +118,23 @@ var AppSwitcher = function (props) {
|
|
|
120
118
|
data = _a.sent();
|
|
121
119
|
// Store the latest access token.
|
|
122
120
|
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];
|
|
121
|
+
return [2 /*return*/, (data === null || data === void 0 ? void 0 : data.map(function (_a) {
|
|
122
|
+
var id = _a.id, name = _a.name, appSwitcherImageUrl = _a.appSwitcherImageUrl, hubImageUrl = _a.hubImageUrl, altText = _a.altText, basePromoUrl = _a.basePromoUrl, isActive = _a.isActive;
|
|
123
|
+
return ({
|
|
124
|
+
id: id,
|
|
125
|
+
name: name,
|
|
126
|
+
appSwitcherImageUrl: appSwitcherImageUrl,
|
|
127
|
+
hubImageUrl: hubImageUrl,
|
|
128
|
+
altText: altText,
|
|
129
|
+
basePromoUrl: basePromoUrl,
|
|
130
|
+
isActive: isActive
|
|
131
|
+
});
|
|
132
|
+
})) || null];
|
|
138
133
|
case 4:
|
|
139
134
|
error_1 = _a.sent();
|
|
140
135
|
console.error('Unable to retrieve latest promotional campaign from Stream Home', error_1);
|
|
141
136
|
return [2 /*return*/, null];
|
|
142
|
-
case 5: return [
|
|
143
|
-
case 6: return [2 /*return*/, null];
|
|
144
|
-
case 7: return [2 /*return*/, null];
|
|
137
|
+
case 5: return [2 /*return*/];
|
|
145
138
|
}
|
|
146
139
|
});
|
|
147
140
|
}); };
|
|
@@ -246,13 +239,12 @@ var AppSwitcher = function (props) {
|
|
|
246
239
|
}); };
|
|
247
240
|
useEffect(function () {
|
|
248
241
|
var loadData = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
249
|
-
var applicationInstances, userApplications,
|
|
242
|
+
var applicationInstances, userApplications, parsedQueryString, match, uniqueApplicationIds, localApplications;
|
|
250
243
|
return __generator(this, function (_a) {
|
|
251
244
|
switch (_a.label) {
|
|
252
245
|
case 0:
|
|
253
246
|
applicationInstances = [];
|
|
254
247
|
userApplications = [];
|
|
255
|
-
promotionalCampaigns = null;
|
|
256
248
|
if (!token) {
|
|
257
249
|
parsedQueryString = queryString.parse(window.location.search);
|
|
258
250
|
if (parsedQueryString.token && typeof parsedQueryString.token === 'string') {
|
|
@@ -320,37 +312,68 @@ var AppSwitcher = function (props) {
|
|
|
320
312
|
}
|
|
321
313
|
// Store the user's applications.
|
|
322
314
|
setApplications(userApplications);
|
|
323
|
-
|
|
315
|
+
return [2 /*return*/];
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}); };
|
|
319
|
+
loadData()
|
|
320
|
+
.catch(console.error);
|
|
321
|
+
}, [token, userId, props.applications]);
|
|
322
|
+
useEffect(function () {
|
|
323
|
+
var loadPromotionalCampaigns = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
324
|
+
var promotionalCampaigns_1, localPromotionalCampaignsJson, parsedCampaigns, error_2;
|
|
325
|
+
return __generator(this, function (_a) {
|
|
326
|
+
switch (_a.label) {
|
|
327
|
+
case 0:
|
|
328
|
+
_a.trys.push([0, 5, , 6]);
|
|
329
|
+
promotionalCampaigns_1 = null;
|
|
330
|
+
if (!(props.promotionalCampaigns && props.promotionalCampaigns.length > 0)) return [3 /*break*/, 1];
|
|
331
|
+
promotionalCampaigns_1 = props.promotionalCampaigns;
|
|
332
|
+
return [3 /*break*/, 4];
|
|
333
|
+
case 1:
|
|
334
|
+
if (!(token && typeof token === 'string' &&
|
|
335
|
+
token !== window.localStorage.getItem(Constants.LocalStorageKey.Token))) return [3 /*break*/, 3];
|
|
324
336
|
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) {
|
|
337
|
+
case 2:
|
|
338
|
+
// Fetch from API if token has changed
|
|
339
|
+
promotionalCampaigns_1 = _a.sent();
|
|
340
|
+
return [3 /*break*/, 4];
|
|
341
|
+
case 3:
|
|
342
|
+
localPromotionalCampaignsJson = window.localStorage.getItem(Constants.LocalStorageKey.PromotionalCampaigns);
|
|
343
|
+
if (localPromotionalCampaignsJson) {
|
|
344
|
+
try {
|
|
339
345
|
parsedCampaigns = JSON.parse(localPromotionalCampaignsJson);
|
|
340
|
-
// Type assertion to ensure type safety
|
|
341
346
|
if (Array.isArray(parsedCampaigns)) {
|
|
342
|
-
|
|
347
|
+
promotionalCampaigns_1 = parsedCampaigns;
|
|
343
348
|
}
|
|
344
349
|
}
|
|
345
|
-
|
|
350
|
+
catch (error) {
|
|
351
|
+
console.error('Error parsing stored campaigns:', error);
|
|
352
|
+
}
|
|
346
353
|
}
|
|
347
|
-
|
|
354
|
+
_a.label = 4;
|
|
355
|
+
case 4:
|
|
356
|
+
// Update state and cache if we have campaigns
|
|
357
|
+
if (Array.isArray(promotionalCampaigns_1) && promotionalCampaigns_1.length > 0) {
|
|
358
|
+
setPromotionalCampaigns(promotionalCampaigns_1);
|
|
359
|
+
window.localStorage.setItem(Constants.LocalStorageKey.PromotionalCampaigns, JSON.stringify(promotionalCampaigns_1));
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
setPromotionalCampaigns(null);
|
|
363
|
+
}
|
|
364
|
+
return [3 /*break*/, 6];
|
|
365
|
+
case 5:
|
|
366
|
+
error_2 = _a.sent();
|
|
367
|
+
console.error('Error loading promotional campaigns:', error_2);
|
|
368
|
+
setPromotionalCampaigns(null);
|
|
369
|
+
return [3 /*break*/, 6];
|
|
370
|
+
case 6: return [2 /*return*/];
|
|
348
371
|
}
|
|
349
372
|
});
|
|
350
373
|
}); };
|
|
351
|
-
|
|
374
|
+
loadPromotionalCampaigns()
|
|
352
375
|
.catch(console.error);
|
|
353
|
-
}, [token,
|
|
376
|
+
}, [token, props.promotionalCampaigns]);
|
|
354
377
|
useEffect(function () {
|
|
355
378
|
if (isAppSwitcherOpen) {
|
|
356
379
|
document.addEventListener('mousedown', handleAppSwitcherClose);
|
|
@@ -374,7 +397,7 @@ var AppSwitcher = function (props) {
|
|
|
374
397
|
// Close AppSwitcher if Escape key is pressed
|
|
375
398
|
if (event.key === 'Escape') {
|
|
376
399
|
handleDialogClose();
|
|
377
|
-
//
|
|
400
|
+
// Doesn't return focus but we need to investigate MUI again
|
|
378
401
|
// so that should handle it
|
|
379
402
|
}
|
|
380
403
|
}
|
|
@@ -405,10 +428,10 @@ var AppSwitcher = function (props) {
|
|
|
405
428
|
: null] })));
|
|
406
429
|
};
|
|
407
430
|
AppSwitcher.propTypes = {
|
|
408
|
-
|
|
431
|
+
token: PropTypes.string,
|
|
409
432
|
apiKey: PropTypes.string,
|
|
410
433
|
layout: PropTypes.string,
|
|
411
|
-
userId: PropTypes.
|
|
434
|
+
userId: PropTypes.string,
|
|
412
435
|
baseUrl: PropTypes.string,
|
|
413
436
|
localization: PropTypes.object,
|
|
414
437
|
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%',
|
|
@@ -52,8 +52,8 @@ export var promotionalContent = [
|
|
|
52
52
|
{
|
|
53
53
|
id: 1,
|
|
54
54
|
name: 'AIC campaign',
|
|
55
|
-
appSwitcherImageUrl: 'https://
|
|
56
|
-
hubImageUrl: '',
|
|
55
|
+
appSwitcherImageUrl: 'https://uuicdn.learningpool.com/promotionalcampaigns/appswitcheradvert/latest/300x150.png',
|
|
56
|
+
hubImageUrl: 'https://uuicdn.learningpool.com/promotionalcampaigns/banner/latest/1000x138.png',
|
|
57
57
|
altText: 'AIC',
|
|
58
58
|
basePromoUrl: 'https://aic.lp-home-web-sever.js.com',
|
|
59
59
|
isActive: true
|