Skip to content

Commit 147e322

Browse files
committed
improve performance
1 parent 868eb45 commit 147e322

File tree

7 files changed

+39
-9
lines changed

7 files changed

+39
-9
lines changed

src/app/app.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { modalNoticeReducer } from './shared/store/modal-notice-state/modal-noti
2121
import { MarkdownModule, provideMarkdown } from 'ngx-markdown';
2222
import { provideLottieOptions } from 'ngx-lottie';
2323
import { variableReducer } from './shared/store/variable-state/variable.reducer';
24+
import { CustomPreloadStrategy } from './core/strategies/custom-preload.strategy';
2425

2526
export const appConfig: ApplicationConfig = {
2627
providers: [
@@ -39,7 +40,7 @@ export const appConfig: ApplicationConfig = {
3940
}),
4041
provideAnimations(),
4142
provideMarkdown(),
42-
provideRouter(routes, withPreloading(PreloadAllModules)),
43+
provideRouter(routes, withPreloading(CustomPreloadStrategy)),
4344
importProvidersFrom(MarkdownModule.forRoot()),
4445
],
4546
};

src/app/app.routes.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AppLayoutComponent } from './layouts/layout-pages/app-layout/app-layout
66
import { AdminLayoutComponent } from './layouts/layout-pages/admin-layout/admin-layout';
77
// import { RoleGuard } from './core/guards/router-protected/role.guard';
88
import { PostModule } from './features/post/post.module';
9+
import { LandingModule } from './features/landing/landing.module';
910

1011
export const routes: Routes = [
1112
//Để test
@@ -76,7 +77,7 @@ export const routes: Routes = [
7677
{
7778
path: 'auth',
7879
component: AuthLayoutComponent,
79-
data: { skipBreadcrumb: true },
80+
data: { skipBreadcrumb: true, preload: true },
8081
children: [
8182
{
8283
path: 'identity',
@@ -93,10 +94,10 @@ export const routes: Routes = [
9394
children: [
9495
{
9596
path: '',
96-
loadChildren: () =>
97-
import('./features/landing/landing.module').then(
98-
(m) => m.LandingModule
99-
),
97+
loadChildren: () => LandingModule,
98+
// import('./features/landing/landing.module').then(
99+
// (m) => m.LandingModule
100+
// ),
100101
title: 'CodeCampus',
101102
},
102103
{
@@ -115,7 +116,8 @@ export const routes: Routes = [
115116
},
116117
{
117118
path: 'post-features',
118-
loadChildren: () => PostModule, //Load đầu tiên k dùng lazyload
119+
loadChildren: () =>
120+
import('./features/post/post.module').then((m) => m.PostModule), //Load đầu tiên k dùng lazyload
119121
},
120122
{
121123
path: 'resource-learning',
@@ -153,6 +155,7 @@ export const routes: Routes = [
153155
),
154156
},
155157
],
158+
data: { preload: true },
156159
},
157160

158161
{
@@ -200,6 +203,7 @@ export const routes: Routes = [
200203
data: { breadcrumb: 'Quản lý tài nguyên' },
201204
},
202205
],
206+
data: { preload: false },
203207
},
204208

205209
{

src/app/core/router-manager/horizontal-menu.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export function getNavHorizontalItems(roles: string[]): SidebarItem[] {
3636
path: '/codecampus-statistics/admin-exercise-statistics',
3737
label: 'Thống kê',
3838
icon: 'fas fa-chart-bar',
39+
needHidden: !(roles.length !== 0),
3940
},
4041
{
4142
id: 'management',
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { PreloadingStrategy, Route } from '@angular/router';
2+
import { Observable, of } from 'rxjs';
3+
4+
export class CustomPreloadStrategy implements PreloadingStrategy {
5+
preload(route: Route, load: () => Observable<any>): Observable<any> {
6+
if (route.data && route.data['preload']) {
7+
return load();
8+
}
9+
return of(null);
10+
}
11+
}

src/app/features/organization/pages/organization-management/organization-management.component.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ <h2>Quản lý Tổ chức</h2>
3434
</div>
3535

3636
@if (loading) {
37-
<div class="loading">Đang tải dữ liệu...</div>
37+
<div class="no-data">
38+
<ng-lottie
39+
[options]="lottieOptionsLoading"
40+
style="width: 200px; height: 200px"
41+
>
42+
</ng-lottie>
43+
<p>Đang load nội dung, xin chờ...</p>
44+
</div>
3845
} @if (!loading && !orgs.length) {
3946
<div class="no-data">
4047
<ng-lottie [options]="lottieOptions" style="width: 200px; height: 200px">

src/app/features/organization/pages/organization-management/organization-management.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import {
1818
OrganizationResponse,
1919
} from '../../../../core/models/organization.model';
2020
import { PaginationComponent } from '../../../../shared/components/fxdonad-shared/pagination/pagination.component';
21-
import { lottieOptions2 } from '../../../../core/constants/value.constant';
21+
import {
22+
lottieOptions2,
23+
lottieOptionsLoading1,
24+
} from '../../../../core/constants/value.constant';
2225
import { LottieComponent } from 'ngx-lottie';
2326
import { OrganizationCreateModalComponent } from '../../organization-component/organization-create-modal/organization-create-modal.component';
2427
import { Router } from '@angular/router';
@@ -51,6 +54,7 @@ export class OrganizationManagementComponent implements OnInit, OnDestroy {
5154
selectedOrgId: string | null = null;
5255

5356
lottieOptions = lottieOptions2;
57+
lottieOptionsLoading = lottieOptionsLoading1;
5458

5559
// Pagination state
5660
page = 1;

src/app/features/statistics/statistics-routing.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const routes: Routes = [
3636
},
3737
//thêm vào đây
3838
],
39+
data: { roles: ['STUDENT', 'TEACHER', 'ADMIN'] },
40+
canActivate: [RoleGuard],
3941
},
4042
];
4143

0 commit comments

Comments
 (0)