Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improved urlChangeListenerInitializer #248

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 55 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@
"@angular/router": "^18.2.1",
"@ngx-translate/core": "^15.0.0",
"@nx/angular": "19.6.3",
"@onecx/accelerator": "^5.9.0",
"@onecx/angular-accelerator": "^5.9.0",
"@onecx/angular-auth": "^5.9.0",
"@onecx/angular-integration-interface": "^5.9.0",
"@onecx/angular-remote-components": "^5.9.0",
"@onecx/angular-webcomponents": "^5.9.0",
"@onecx/integration-interface": "^5.9.0",
"@onecx/keycloak-auth": "^5.9.0",
"@onecx/portal-integration-angular": "^5.9.0",
"@onecx/portal-layout-styles": "^5.9.0",
"@onecx/shell-core": "^5.9.0",
"@onecx/accelerator": "^5.9.2",
"@onecx/angular-accelerator": "^5.9.2",
"@onecx/angular-auth": "^5.9.2",
"@onecx/angular-integration-interface": "^5.9.2",
"@onecx/angular-remote-components": "^5.9.2",
"@onecx/angular-webcomponents": "^5.9.2",
"@onecx/integration-interface": "^5.9.2",
"@onecx/keycloak-auth": "^5.9.2",
"@onecx/portal-integration-angular": "^5.9.2",
"@onecx/portal-layout-styles": "^5.9.2",
"@onecx/shell-core": "^5.9.2",
"@openapitools/openapi-generator-cli": "^2.13.5",
"keycloak-angular": "^16.0.1",
"keycloak-js": "^25.0.4",
Expand Down
44 changes: 24 additions & 20 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ import { EventsPublisher, EventsTopic } from '@onecx/integration-interface';

export function createTranslateLoader(
http: HttpClient,
translationCacheService: TranslationCacheService
translationCacheService: TranslationCacheService,
) {
return new TranslateCombinedLoader(
new CachingTranslateLoader(
translationCacheService,
http,
`./assets/i18n/`,
'.json'
'.json',
),
new CachingTranslateLoader(
translationCacheService,
http,
`./onecx-portal-lib/assets/i18n/`,
'.json'
)
'.json',
),
);
}

function publishCurrentWorkspace(
appStateService: AppStateService,
loadWorkspaceConfigResponse: LoadWorkspaceConfigResponse
loadWorkspaceConfigResponse: LoadWorkspaceConfigResponse,
) {
return appStateService.currentWorkspace$.publish({
baseUrl: loadWorkspaceConfigResponse.workspace.baseUrl,
Expand All @@ -83,7 +83,7 @@ function publishCurrentWorkspace(
routes: loadWorkspaceConfigResponse.routes,
homePage: loadWorkspaceConfigResponse.workspace.homePage,
microfrontendRegistrations: [],
displayName: loadWorkspaceConfigResponse.workspace.displayName
displayName: loadWorkspaceConfigResponse.workspace.displayName,
});
}

Expand All @@ -93,7 +93,7 @@ export function workspaceConfigInitializer(
themeService: ThemeService,
appStateService: AppStateService,
remoteComponentsService: RemoteComponentsService,
router: Router
router: Router,
) {
return async () => {
await appStateService.isAuthenticated$.isInitialized;
Expand All @@ -106,13 +106,13 @@ export function workspaceConfigInitializer(
retry({ delay: 500, count: 3 }),
catchError((error) => {
return initializationErrorHandler(error, router);
})
)
}),
),
);

if (loadWorkspaceConfigResponse) {
const parsedProperties = JSON.parse(
loadWorkspaceConfigResponse.theme.properties
loadWorkspaceConfigResponse.theme.properties,
) as Record<string, Record<string, string>>;
const themeWithParsedProperties = {
...loadWorkspaceConfigResponse.theme,
Expand All @@ -138,7 +138,7 @@ export function userProfileInitializer(
userProfileBffService: UserProfileBffService,
userService: UserService,
appStateService: AppStateService,
router: Router
router: Router,
) {
return async () => {
await appStateService.isAuthenticated$.isInitialized;
Expand All @@ -147,14 +147,14 @@ export function userProfileInitializer(
retry({ delay: 500, count: 3 }),
catchError((error) => {
return initializationErrorHandler(error, router);
})
)
}),
),
);

if (getUserProfileResponse) {
console.log(
'ORGANIZATION : ',
getUserProfileResponse.userProfile.organization
getUserProfileResponse.userProfile.organization,
);

await userService.profile$.publish(getUserProfileResponse.userProfile);
Expand All @@ -167,13 +167,13 @@ export function slotInitializer(slotService: SlotService) {
}

export function permissionProxyInitializer(
permissionProxyService: PermissionProxyService
permissionProxyService: PermissionProxyService,
) {
return () => permissionProxyService.init();
}

export function configurationServiceInitializer(
configurationService: ConfigurationService
configurationService: ConfigurationService,
) {
return () => configurationService.init();
}
Expand Down Expand Up @@ -201,21 +201,25 @@ window.history.replaceState = (data: any, unused: string, url?: string) => {

export function urlChangeListenerInitializer(
router: Router,
appStateService: AppStateService
appStateService: AppStateService,
) {
return async () => {
await appStateService.isAuthenticated$.isInitialized;
let lastUrl = '';
let lastHash = '';
let isFirstRoute = true;
const observer = new EventsTopic();
observer.pipe(filter((e) => e.type === 'navigated')).subscribe(() => {
const routerUrl = `${location.pathname.substring(
getLocation().deploymentPath.length
getLocation().deploymentPath.length,
)}${location.search}`;
if (routerUrl !== lastUrl) {
if (routerUrl !== lastUrl || location.hash !== lastHash) {
lastUrl = routerUrl;
lastHash = location.hash;
if (!isFirstRoute) {
router.navigateByUrl(routerUrl);
router.navigate([routerUrl], {
fragment: location.hash.substring(1),
});
} else {
isFirstRoute = false;
}
Expand Down
Loading