Skip to content

Commit

Permalink
Feat: implement user settings and redirect users
Browse files Browse the repository at this point in the history
  • Loading branch information
synox committed Dec 12, 2023
1 parent f90e1df commit 81ecef3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion contenthub/unified-shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ const defaultSettings = { isOnboardingCompleted: false };
* @returns {Promise<UserSettings>}
*/
export async function getUserSettings() {
return await settingsApi.get({
const response = await settingsApi.get({
groupId: 'general',
level: SettingsLevel.USER,
settings: defaultSettings,
});
return response.settings;
}

/**
Expand Down
25 changes: 20 additions & 5 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
loadBlocks,
loadCSS,
} from './lib-franklin.js';
import { getAdminConfig, getBrandingConfig } from './site-config.js';
import { getAdminConfig, getBrandingConfig, isContentHub } from './site-config.js';
import { getBearerToken, checkUserAccess, isPublicPage } from './security.js';
import {
getSearchIndex,
Expand All @@ -21,8 +21,10 @@ import {
} from './polaris.js';
import { EventNames, emitEvent } from './events.js';
import { showNextPageToast } from './toast-message.js';
import { bootstrapUnifiedShell } from '../contenthub/unified-shell.js';
import { createLinkHref, navigateTo, setCSSVar } from './shared.js';
import { bootstrapUnifiedShell, getUserSettings } from '../contenthub/unified-shell.js';
import {
createLinkHref, navigateTo, setCSSVar,
} from './shared.js';
import { getPlatformConnector } from '../contenthub/discovery-service.js';

// Load a list of dependencies the site needs
Expand Down Expand Up @@ -326,8 +328,21 @@ function loadDelayed() {
}

export async function loadPage() {
await loadEager(document);
await bootstrapUnifiedShell();
// load resource in parallel
const unifiedShellPromise = bootstrapUnifiedShell();
const eagerPromise = loadEager(document);

await unifiedShellPromise;
if (await isContentHub()) {
const settings = await getUserSettings();
if (window.location.pathname !== '/onboarding' && !settings.isOnboardingCompleted) {
// TODO: activate onboarding
// navigateTo(createLinkHref('/onboarding'));
// return;
}
}

await eagerPromise;
await loadLazy(document);
loadDelayed();
}
Expand Down

0 comments on commit 81ecef3

Please sign in to comment.