Skip to content

Commit 0150356

Browse files
committed
improve logic authentication fe
1 parent 2d1a4c1 commit 0150356

File tree

20 files changed

+255
-247
lines changed

20 files changed

+255
-247
lines changed

src/app/core/interceptors/handle/error.interceptor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ export const errorInterceptor: HttpInterceptorFn = (req, next) => {
8080
cancelText: 'Hủy',
8181
onConfirm: () => {
8282
router.navigate(['/auth/identity/login']);
83+
localStorage.removeItem('token');
84+
localStorage.removeItem('refreshToken');
8385
},
8486
},
8587
})

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export function getNavHorizontalItems(roles: string[]): SidebarItem[] {
2323
path: '/resource-learning/list-resource',
2424
label: 'Kho tài liệu',
2525
icon: 'fas fa-book',
26+
isVisible: !(roles.length !== 0),
2627
},
2728
{
2829
id: 'message',
@@ -50,6 +51,7 @@ export function getNavHorizontalItems(roles: string[]): SidebarItem[] {
5051
path: '/service-and-payment/payment',
5152
label: 'Thanh toán',
5253
icon: 'fas fa-credit-card',
54+
isVisible: !(roles.length !== 0),
5355
},
5456
{
5557
id: 'organization ',
@@ -59,6 +61,7 @@ export function getNavHorizontalItems(roles: string[]): SidebarItem[] {
5961
label: 'Tổ chức',
6062
icon: 'fa-solid fa-building-user',
6163
// isVisible: !roles.includes(auth_lv2[0]),
64+
isVisible: !(roles.length !== 0),
6265
},
6366
];
6467
}

src/app/core/services/api-service/exercise.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ export class ExerciseService {
123123
tags,
124124
difficulty,
125125
search
126-
)
126+
),
127+
true
127128
);
128129
}
129130

src/app/core/services/api-service/post.service.ts

Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -25,71 +25,19 @@ export class PostService {
2525
);
2626
}
2727

28+
searchPosts(page: number, size: number, search?: string | null) {
29+
return this.api.get<ApiResponse<IPaginationResponse<PostResponse[]>>>(
30+
API_CONFIG.ENDPOINTS.GET.SEARCH_POST(page, size, search),
31+
true
32+
);
33+
}
34+
2835
getPostDetails(id: string) {
2936
return this.api.get<ApiResponse<PostResponse>>(
3037
API_CONFIG.ENDPOINTS.GET.GET_POST_DETAILS(id)
3138
);
3239
}
3340

34-
//deprecated
35-
// addPost(data: CreatePostRequest) {
36-
// const formData = new FormData();
37-
38-
// // Helper append (chỉ thêm nếu có giá trị thật sự)
39-
// const safeAppend = (key: string, value: any) => {
40-
// if (
41-
// value !== undefined &&
42-
// value !== null &&
43-
// !(typeof value === 'string' && value.trim() === '')
44-
// ) {
45-
// formData.append(key, value);
46-
// }
47-
// };
48-
49-
// // basic fields
50-
// safeAppend('title', data.title);
51-
// safeAppend('orgId', data.orgId);
52-
// safeAppend('content', data.content);
53-
// safeAppend('isPublic', String(data.isPublic));
54-
// safeAppend('allowComment', String(data.allowComment));
55-
// safeAppend('postType', data.postType);
56-
// safeAppend('hashtag', data.hashtag);
57-
58-
// // array fields
59-
// safeAppend(`oldImgesUrls`, data.oldImgesUrls);
60-
61-
// // optional status
62-
// safeAppend('status', data.status);
63-
64-
// // fileDocument
65-
// if (data.fileDocument) {
66-
// const fd = data.fileDocument;
67-
// safeAppend('fileDocument.file', fd.file);
68-
// safeAppend('fileDocument.category', fd.category);
69-
// safeAppend('fileDocument.description', fd.description);
70-
// fd.tags?.forEach((tag, i) => safeAppend(`fileDocument.tags[${i}]`, tag));
71-
// if (typeof fd.isLectureVideo === 'boolean') {
72-
// safeAppend('fileDocument.isLectureVideo', String(fd.isLectureVideo));
73-
// }
74-
// if (typeof fd.isTextBook === 'boolean') {
75-
// safeAppend('fileDocument.isTextBook', String(fd.isTextBook));
76-
// }
77-
// safeAppend('fileDocument.orgId', fd.orgId);
78-
// }
79-
80-
// // Debug log
81-
// for (const [key, val] of formData.entries()) {
82-
// console.log(key, val);
83-
// }
84-
85-
// // Gửi form-data (KHÔNG ép Content-Type)
86-
// return this.api.post<NhatApiResponeNoData>(
87-
// API_CONFIG.ENDPOINTS.POST.ADD_POST,
88-
// formData,
89-
// true
90-
// );
91-
// }
92-
9341
//sử dụng postWithFormData
9442
createPost(data: CreatePostRequest) {
9543
const { fileDocument, ...otherData } = data;

src/app/core/services/config-service/api.enpoints.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ export const API_CONFIG = {
134134
GET_CHAT_MESSAGES: (page: number, size: number, conversationId: string) =>
135135
`/chat/messages?page=${page}&size=${size}&conversationId=${conversationId}`,
136136
GET_POST_DETAILS: (postId: string) => `/post/${postId}`,
137+
SEARCH_POST: (page: number, size: number, search?: string | null) => {
138+
let query = `/search/posts/filter?page=${page}&size=${size}`;
139+
if (search) query += `&q=${encodeURIComponent(search)}`;
140+
141+
return query;
142+
},
137143
GET_SAVED_POSTS: (page: number, size: number) =>
138144
`/profile/posts/saved?page=${page}&size=${size}`,
139145
GET_COMMENT_BY_POST_ID: (

src/app/features/excercise/exercise-layout/exercise-layout.component.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<div class="main-exercise-container-layout">
2-
@if (showSidebar) {
3-
<app-main-sidebar
4-
[sidebarItems]="sidebarData"
5-
[isCollapsed]="isSidebarCollapsed"
6-
>
7-
</app-main-sidebar>
2+
@if (showSidebar && isAuthenticated) {
3+
<app-main-sidebar
4+
[sidebarItems]="sidebarData"
5+
[isCollapsed]="isSidebarCollapsed"
6+
>
7+
</app-main-sidebar>
88
}
99

1010
<div class="content-exercise-container">

src/app/features/excercise/exercise-layout/exercise-layout.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { filter } from 'rxjs/internal/operators/filter';
88
import { sidebarExercises } from '../../../core/router-manager/vetical-menu-dynamic/exercise-vetical-menu';
99
import { decodeJWT } from '../../../shared/utils/stringProcess';
1010
import { SidebarItem } from '../../../core/models/data-handle';
11+
import { checkAuthenticated } from '../../../shared/utils/authenRoleActions';
1112

1213
@Component({
1314
selector: 'app-exercise-layout',
@@ -20,6 +21,7 @@ export class ExerciseLayoutComponent implements OnInit, OnDestroy {
2021
sidebarData: SidebarItem[] = [];
2122

2223
showSidebar = true;
24+
isAuthenticated = false;
2325

2426
// Danh sách các route cần ẩn sidebar
2527
private routesToHideSidebar: string[] = [
@@ -32,6 +34,7 @@ export class ExerciseLayoutComponent implements OnInit, OnDestroy {
3234
constructor(private router: Router) {
3335
const roles = decodeJWT(localStorage.getItem('token') ?? '')?.payload.roles;
3436
this.sidebarData = sidebarExercises(roles);
37+
this.isAuthenticated = checkAuthenticated();
3538
}
3639

3740
ngOnInit() {

src/app/features/post/pages/post-list/post-list.html

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[isSvg]="false"
1313
[icon]="'fa fa-search'"
1414
></app-input>
15-
<app-dropdown-button
15+
<!-- <app-dropdown-button
1616
[label]="'Vai trò'"
1717
[options]="tag"
1818
[variant]="'secondary'"
@@ -47,7 +47,8 @@
4747
[isSearchable]="true"
4848
[minHeight]="true"
4949
[needIndexColor]="true"
50-
></app-dropdown-button>
50+
></app-dropdown-button> -->
51+
@if (authenticated) {
5152
<div class="post-list-button">
5253
<app-btn-type1
5354
thumb="+"
@@ -56,52 +57,48 @@
5657
(click)="handleAdd()"
5758
></app-btn-type1>
5859
</div>
60+
}
5961
</div>
6062
</div>
6163

6264
<div class="list-post-card-container">
6365
<!-- Hiển thị bài viết khi có dữ liệu và không đang tải -->
6466
<!-- Đang để tạm hàm fetchPostList(), khi nào có loadnextpage sẽ thay thế -->
65-
@if (posts && posts.length > 0) {
66-
<div
67-
class="list-post-card"
68-
appScrollEnd
69-
(appScrollEnd)="loadNextPage()"
70-
>
71-
@for (post of posts; track trackByPostId($index, post)) {
72-
<div>
73-
<app-post-card
74-
[post]="post"
75-
(delete)="openModalDelete(post.id)"
76-
(upvote)="handleUpVote(post.id)"
77-
(downvote)="handleDownVote(post.id)"
78-
(mainClick)="goToDetail($event)"
79-
(save)="handleToggleSave(post.id)"
80-
></app-post-card>
81-
</div>
82-
}
67+
@if (posts && posts.length > 0 && !(isLoadingInitial || isLoadingMore ||
68+
isLoading)) {
69+
<div class="list-post-card" appScrollEnd (appScrollEnd)="loadNextPage()">
70+
@for (post of posts; track trackByPostId($index, post)) {
71+
<div>
72+
<app-post-card
73+
[post]="post"
74+
(delete)="openModalDelete(post.id)"
75+
(upvote)="handleUpVote(post.id)"
76+
(downvote)="handleDownVote(post.id)"
77+
(mainClick)="goToDetail($event)"
78+
(save)="handleToggleSave(post.id)"
79+
></app-post-card>
8380
</div>
81+
}
82+
</div>
8483
}
8584

8685
<!-- Hiển thị skeleton loading khi đang tải -->
87-
@if (isLoadingInitial || isLoadingMore) {
88-
<div class="list-post-card">
89-
<app-skeleton-loading type="card" [count]="8"></app-skeleton-loading>
90-
</div>
86+
@if (isLoadingInitial || isLoadingMore || isLoading) {
87+
<div class="list-post-card">
88+
<app-skeleton-loading type="card" [count]="8"></app-skeleton-loading>
89+
</div>
9190
}
9291

9392
<!-- Hiển thị thông báo "Không có dữ liệu" với hình ảnh động khi không có bài viết -->
9493
@if (!isLoading && (!posts || posts.length === 0)) {
95-
<div
96-
class="no-data-container"
97-
>
98-
<ng-lottie
99-
[options]="lottieOptions"
100-
style="width: 200px; height: 200px"
101-
>
102-
</ng-lottie>
103-
<p>Không có dữ liệu</p>
104-
</div>
94+
<div class="no-data-container">
95+
<ng-lottie
96+
[options]="lottieOptions"
97+
style="width: 200px; height: 200px"
98+
>
99+
</ng-lottie>
100+
<p>Không có dữ liệu</p>
101+
</div>
105102
}
106103
</div>
107104
</div>
@@ -112,7 +109,7 @@
112109
[items]="trendingData"
113110
title="Popular Technologies"
114111
[maxItems]="15"
115-
>
112+
>
116113
</app-trending>
117114
</div>
118115
<div class="popular-post">

0 commit comments

Comments
 (0)