Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit a00e26a

Browse files
committed
cross import demo
e2e tests are NOT supported
1 parent 4fa5e66 commit a00e26a

13 files changed

+153
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,5 @@ dist
102102

103103
# TernJS port file
104104
.tern-port
105+
106+
.DS_Store

extra-webpack.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ const singleSpaAngularWebpack = require('single-spa-angular/lib/webpack').defaul
33
module.exports = (config, options) => {
44
const singleSpaWebpackConfig = singleSpaAngularWebpack(config, options);
55

6+
// we have to list here all the microapps which we would like to use in imports
7+
// so webpack doesn't tries to import them
8+
singleSpaWebpackConfig.externals = {
9+
'@topcoder/micro-frontends-navbar-app':
10+
'@topcoder/micro-frontends-navbar-app',
11+
};
12+
613
// Feel free to modify this webpack config however you'd like to
714
return singleSpaWebpackConfig;
815
};

src/app/app.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ <h1>Angular child app example</h1>
88
/>
99

1010
<div><a routerLink="/micro-frontends-react-route">Link to React child app</a></div>
11+
12+
<tc-ex-auth-demo></tc-ex-auth-demo>
1113
</div>
1214

1315
<router-outlet></router-outlet>

src/app/app.component.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
2+
import { setAppMenu } from '@topcoder/micro-frontends-navbar-app';
3+
import appMenu from './constants/appMenu';
24

35
@Component({
46
selector: 'tc-ex-root',
57
templateUrl: './app.component.html',
6-
styleUrls: ['./app.component.scss']
8+
styleUrls: ['./app.component.scss'],
79
})
8-
export class AppComponent {
10+
export class AppComponent implements OnInit {
911
title = 'micro-frontends-angular-app';
12+
13+
ngOnInit(): void {
14+
// when app starts it should set its side menu structure
15+
setAppMenu('/micro-frontends-angular-route', appMenu);
16+
}
1017
}

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { NgModule } from '@angular/core';
44
import { AppRoutingModule } from './app-routing.module';
55
import { AppComponent } from './app.component';
66
import { EmptyRouteComponent } from './empty-route/empty-route.component';
7+
import { AuthDemoComponent } from './auth-demo/auth-demo.component';
78

89
@NgModule({
910
declarations: [
1011
AppComponent,
11-
EmptyRouteComponent
12+
EmptyRouteComponent,
13+
AuthDemoComponent
1214
],
1315
imports: [
1416
BrowserModule,
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Loading

src/app/assets/images/home-green.svg

Lines changed: 3 additions & 0 deletions
Loading

src/app/assets/images/home.svg

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<h2>Authentication</h2>
2+
<div *ngIf="authUserTokens.loading">Authentication...</div>
3+
<div *ngIf="!authUserTokens.loading && authUserTokens.error">Authentication Error: {{authUserTokens.error.message}}</div>
4+
<div *ngIf="!authUserTokens.loading && !authUserTokens.error && authUserTokens.value.tokenV3">
5+
User is logged-in <button (click)="logout()">Logout</button>
6+
7+
<h3>User Profile</h3>
8+
<div *ngIf="authUserProfile.loading">User Profile Loading...</div>
9+
<div *ngIf="!authUserProfile.loading && authUserProfile.error">Profile Loading Error: {{authUserProfile.error.message}}</div>
10+
<ul *ngIf="!authUserProfile.loading && !authUserProfile.error && authUserProfile.value">
11+
<li><strong>Handle:</strong> {{authUserProfile.value.handle}}</li>
12+
<li><strong>First Name:</strong> {{authUserProfile.value.firstName}}</li>
13+
<li><strong>Last Name:</strong> {{authUserProfile.value.lastName}}</li>
14+
</ul>
15+
</div>
16+
<div *ngIf="!authUserTokens.loading && !authUserTokens.error && !authUserTokens.value.tokenV3">
17+
User is logged-out <button (click)="login()">Login</button>
18+
</div>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { Component, OnInit, NgZone } from '@angular/core';
2+
import {
3+
login,
4+
logout,
5+
getAuthUserTokens,
6+
getAuthUserProfile,
7+
} from '@topcoder/micro-frontends-navbar-app';
8+
9+
@Component({
10+
selector: 'tc-ex-auth-demo',
11+
templateUrl: './auth-demo.component.html',
12+
})
13+
export class AuthDemoComponent implements OnInit {
14+
authUserTokens = { loading: true, error: null, value: null };
15+
authUserProfile = { loading: true, error: null, value: null };
16+
login = login;
17+
logout = logout;
18+
constructor(private zone: NgZone) {}
19+
20+
ngOnInit(): void {
21+
// get authenticated user tokens
22+
getAuthUserTokens()
23+
.then((tokens) => {
24+
// as this promise is not handled by Zone we
25+
// have to manually trigger change detection
26+
this.zone.run(() => {
27+
this.authUserTokens.value = tokens;
28+
this.authUserTokens.loading = false;
29+
});
30+
})
31+
.catch((error) => {
32+
// as this promise is not handled by Zone we
33+
// have to manually trigger change detection
34+
this.zone.run(() => {
35+
this.authUserTokens.error = error;
36+
this.authUserTokens.loading = false;
37+
});
38+
});
39+
40+
// as get authenticated user profile
41+
getAuthUserProfile()
42+
.then((profile) => {
43+
// as this promise is not handled by Zone we
44+
// have to manually trigger change detection
45+
this.zone.run(() => {
46+
this.authUserProfile.value = profile;
47+
this.authUserProfile.loading = false;
48+
});
49+
})
50+
.catch((error) => {
51+
// as this promise is not handled by Zone we
52+
// have to manually trigger change detection
53+
this.zone.run(() => {
54+
this.authUserProfile.error = error;
55+
this.authUserProfile.loading = false;
56+
});
57+
});
58+
}
59+
}

src/app/constants/appMenu.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Angular app side menu structure
3+
*/
4+
import angularIcon from '../assets/images/angular-grey.svg';
5+
import angularActiveIcon from '../assets/images/angular-green.svg';
6+
import homeIcon from '../assets/images/home.svg';
7+
import homeActiveIcon from '../assets/images/home-green.svg';
8+
9+
const appMenu = [
10+
{
11+
title: 'Angular App',
12+
path: '/micro-frontends-angular-route',
13+
icon: angularIcon,
14+
activeIcon: angularActiveIcon,
15+
},
16+
{
17+
title: 'Home',
18+
path: '/micro-frontends-angular-route/home',
19+
icon: homeIcon,
20+
activeIcon: homeActiveIcon,
21+
},
22+
];
23+
24+
export default appMenu;

src/typings.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
declare module '@topcoder/micro-frontends-navbar-app' {
2+
export const login: any;
3+
export const logout: any;
4+
export const setAppMenu: any;
5+
export const getAuthUserTokens: any;
6+
export const getAuthUserProfile: any;
7+
}
8+
9+
declare module "*.svg" {
10+
const content: any;
11+
export default content;
12+
}

0 commit comments

Comments
 (0)