@learningpool/ui 2.3.0 → 2.3.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.
@@ -11,10 +11,5 @@ declare const AppSwitcher: {
11
11
  baseUrl: PropTypes.Requireable<string>;
12
12
  localization: PropTypes.Requireable<object>;
13
13
  };
14
- defaultProps: {
15
- layout: string;
16
- baseUrl: "https://api.home.learningpool.com/";
17
- localization: {};
18
- };
19
14
  };
20
15
  export default AppSwitcher;
@@ -14,20 +14,31 @@ import AppHub from '../AppHub/AppHub';
14
14
  import { Box, Typography } from '@mui/material';
15
15
  import { DrawerShadow } from '../../navigation/VerticalNavigation/VerticalNavigationStyles';
16
16
  const AppSwitcher = (props) => {
17
- const { isAppSwitcherOpen, handleToggleAppSwitcher, isDrawerOpen, localization, dataAttributes, baseUrl, avatarName, hubDashboardData, apiKey = '', isStandalone = true } = props;
17
+ const { isAppSwitcherOpen, handleToggleAppSwitcher, isDrawerOpen, dataAttributes, avatarName, hubDashboardData, StreamHomeUrl, localization = {}, baseUrl = Constants.BaseUrl, apiKey = '', isStandalone = true } = props;
18
18
  let { token } = props;
19
+ let userId = props.userId ?? '';
20
+ // Use prop state when provided, otherwise use internal state for standalone mode
21
+ const [standaloneIsOpen, setStandaloneIsOpen] = useState(false);
22
+ const resolvedIsOpen = isAppSwitcherOpen !== undefined
23
+ ? isAppSwitcherOpen
24
+ : (isStandalone ? standaloneIsOpen : false);
19
25
  const [dashboardData, setDashboardData] = useState([]);
20
26
  const [hasPromotionalCampaigns, setHasPromotionalCampaigns] = useState(false);
21
27
  const [userOrg, setUserOrg] = useState('');
22
28
  const userFirstName = avatarName?.split(' ')[0];
23
29
  const messages = { ...Constants.DefaultMessages, ...localization };
24
30
  const dataIds = { ...defaultAttributes, ...dataAttributes };
25
- let userId = props.userId ?? '';
26
31
  /**
27
32
  * Handles closing of the application dialog.
28
33
  */
29
34
  const handleDialogClose = () => {
30
- handleToggleAppSwitcher();
35
+ if (isAppSwitcherOpen !== undefined && handleToggleAppSwitcher) {
36
+ handleToggleAppSwitcher();
37
+ }
38
+ else if (isStandalone) {
39
+ setStandaloneIsOpen(false);
40
+ }
41
+ // If neither condition is met, we can't close (should not happen in normal usage)
31
42
  };
32
43
  /**
33
44
  * Queries the Steam Home API to fetch dashboard data.
@@ -175,13 +186,13 @@ const AppSwitcher = (props) => {
175
186
  loadData().catch(console.error);
176
187
  }, [token, userId, hubDashboardData]);
177
188
  useEffect(() => {
178
- if (isAppSwitcherOpen) {
189
+ if (resolvedIsOpen) {
179
190
  document.addEventListener('mousedown', handleAppSwitcherClose);
180
191
  }
181
192
  return () => {
182
193
  document.removeEventListener('mousedown', handleAppSwitcherClose);
183
194
  };
184
- }, [isAppSwitcherOpen]);
195
+ }, [resolvedIsOpen]);
185
196
  useEffect(() => document.addEventListener('keydown', handleKeyDown));
186
197
  const handleAppSwitcherClose = (event) => {
187
198
  const appSwitcherButton = document.getElementById(defaultAttributes.VerticalNavigationAppSwitcherToggle);
@@ -193,7 +204,7 @@ const AppSwitcher = (props) => {
193
204
  handleDialogClose();
194
205
  };
195
206
  const handleKeyDown = (event) => {
196
- if (isAppSwitcherOpen && event && event.type === EVENT_KEYS.Keydown) {
207
+ if (resolvedIsOpen && event && event.type === EVENT_KEYS.Keydown) {
197
208
  // Close AppSwitcher if Escape key is pressed
198
209
  if (event.key === EVENT_KEYS.Escape) {
199
210
  handleDialogClose();
@@ -207,13 +218,13 @@ const AppSwitcher = (props) => {
207
218
  }
208
219
  const docTextDirection = window.document?.dir;
209
220
  return (_jsxs(_Fragment, { children: [_jsxs(AppSwitcherPanel, { id: "app-switcher-menu", style: {
210
- display: isAppSwitcherOpen ? 'block' : 'none',
221
+ display: resolvedIsOpen ? 'block' : 'none',
211
222
  left: isDrawerOpen ? Constants.DrawerWidth.Expanded : Constants.DrawerWidth.Collapsed - 3,
212
223
  right: (docTextDirection === 'rtl' && isDrawerOpen) ? Constants.DrawerWidth.Expanded : Constants.DrawerWidth.Collapsed - 3
213
- }, role: 'dialog', "aria-label": "App Switcher", onKeyDown: handleKeyDown, "data-id": dataIds.AppSwitcherContainer, onMouseDown: (event) => event.stopPropagation(), children: [_jsx(AppSwitcherHeaderPanel, { children: _jsx(AppSwitcherCloseButton, { onClick: handleDialogClose }) }), dashboardData.length > 0 && _jsx(Box, { sx: { marginBottom: '3rem' }, children: _jsx(AppHub, { data: dashboardData, hasPromotionalCampaigns: hasPromotionalCampaigns, isAppSwitcher: true, userName: userFirstName || avatarName, userOrganization: userOrg, hubApiUrl: baseUrl || Constants.BaseUrl, hubApiKey: apiKey, hubToken: token }) }), dashboardData.length === 0 && _jsx(Typography, { variant: 'h2', component: 'h4', sx: { marginTop: '1rem', justifySelf: 'anchor-center' }, children: messages['data-not-found'] }), _jsx(AppSwitcherFooterPanel, { children: _jsx(StyledHomeButton, { "aria-label": messages['go-to-hub'], endIcon: docTextDirection === 'rtl' ? _jsx(ChevronLeftIcon, { sx: { marginRight: '0.5em' } }) : _jsx(ChevronRightIcon, {}), onClick: e => window.open(props.StreamHomeUrl || Constants.DefaultStreamHomeUrl), children: messages['go-to-hub'] }) })] }), _jsx(AppSwitcherShadow, { style: {
214
- display: isAppSwitcherOpen ? 'block' : 'none',
224
+ }, role: 'dialog', "aria-label": "App Switcher", onKeyDown: handleKeyDown, "data-id": dataIds.AppSwitcherContainer, onMouseDown: (event) => event.stopPropagation(), children: [_jsx(AppSwitcherHeaderPanel, { children: _jsx(AppSwitcherCloseButton, { onClick: handleDialogClose }) }), dashboardData.length > 0 && _jsx(Box, { sx: { marginBottom: '3rem' }, children: _jsx(AppHub, { data: dashboardData, hasPromotionalCampaigns: hasPromotionalCampaigns, isAppSwitcher: true, userName: userFirstName || avatarName, userOrganization: userOrg, hubApiUrl: baseUrl || Constants.BaseUrl, hubApiKey: apiKey, hubToken: token }) }), dashboardData.length === 0 && _jsx(Typography, { variant: 'h2', component: 'h4', sx: { marginTop: '1rem', justifySelf: 'anchor-center' }, children: messages['data-not-found'] }), _jsx(AppSwitcherFooterPanel, { children: _jsx(StyledHomeButton, { "aria-label": messages['go-to-hub'], endIcon: docTextDirection === 'rtl' ? _jsx(ChevronLeftIcon, { sx: { marginRight: '0.5em' } }) : _jsx(ChevronRightIcon, {}), onClick: e => window.open(StreamHomeUrl || Constants.DefaultStreamHomeUrl), children: messages['go-to-hub'] }) })] }), _jsx(AppSwitcherShadow, { style: {
225
+ display: resolvedIsOpen ? 'block' : 'none',
215
226
  left: isDrawerOpen ? Constants.DrawerWidth.Expanded : Constants.DrawerWidth.Collapsed - 3
216
- } }), isAppSwitcherOpen && !isStandalone &&
227
+ } }), resolvedIsOpen && !isStandalone &&
217
228
  _jsx(DrawerShadow, { className: 'drawerShadow', "aria-hidden": 'true', sx: {
218
229
  zIndex: -1
219
230
  } })] }));
@@ -226,9 +237,4 @@ AppSwitcher.propTypes = {
226
237
  baseUrl: PropTypes.string,
227
238
  localization: PropTypes.object
228
239
  };
229
- AppSwitcher.defaultProps = {
230
- layout: Constants.Layout.Vertical,
231
- baseUrl: Constants.BaseUrl,
232
- localization: {}
233
- };
234
240
  export default AppSwitcher;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "components",
10
10
  "ui"
11
11
  ],
12
- "version": "2.3.0",
12
+ "version": "2.3.2",
13
13
  "private": false,
14
14
  "main": "index.js",
15
15
  "module": "index.js",