Skip to content

Commit 8bf09d0

Browse files
committed
fix resource details
1 parent 4c5593a commit 8bf09d0

File tree

5 files changed

+109
-12
lines changed

5 files changed

+109
-12
lines changed

public/assets/lottie-animation/505.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/app/core/constants/value.constant.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,10 @@ export const lottieOptionsLoading1 = {
114114
loop: true,
115115
};
116116

117+
export const lottieOptionsServerError = {
118+
path: 'assets/lottie-animation/505.json',
119+
autoplay: true,
120+
loop: true,
121+
};
122+
117123
export const avatarUrlDefault: string = 'auth-assets/avatar_placeholder.png';

src/app/features/resource-learning/pages/resource-detail/resource-detail.html

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,17 @@
3535

3636
<div class="resource-content">
3737
<!-- Nếu là video -->
38-
@if (!isDocument && !isImage && resource.hlsUrl) {
39-
<app-video-player [videoSrc]="resource.hlsUrl || ''"></app-video-player>
38+
@if (!isDocument && !isImage) { @if( resource.hlsUrl){<app-video-player
39+
[videoSrc]="resource.hlsUrl || ''"
40+
></app-video-player
41+
>} @else {
42+
<div class="no-data-container">
43+
<ng-lottie [options]="lottieOption" style="width: 200px; height: 200px">
44+
</ng-lottie>
45+
<div class="no-available-video">Video hiện không khả dụng</div>
46+
</div>
47+
48+
}
4049
<div class="resource-detail-content">
4150
<markdown [data]="resource.description"></markdown>
4251
</div>
@@ -112,7 +121,13 @@
112121
</div>
113122
}
114123
</div>
115-
} @if (isLoading) {
124+
@if(hasMore && !isLoadingMore){
125+
<div class="load-more-container">
126+
<button class="load-more-btn" (click)="loadOtherResource()">
127+
Xem thêm
128+
</button>
129+
</div>
130+
} } @if (isLoading) {
116131
<div class="list-resource-card">
117132
<app-skeleton-loading type="card" [count]="8"></app-skeleton-loading>
118133
</div>

src/app/features/resource-learning/pages/resource-detail/resource-detail.scss

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@
7272
background-color: #fff;
7373
}
7474
}
75+
76+
.no-data-container {
77+
display: flex;
78+
flex-direction: column;
79+
align-items: center;
80+
justify-content: center;
81+
height: 100%;
82+
text-align: center;
83+
padding: 20px;
84+
background-color: oklch(from var(--hover-color) calc(l * 1.2) c h);
85+
.no-available-video {
86+
color: var(--reverse-color-text);
87+
}
88+
}
7589
}
7690

7791
.resource-video-info {
@@ -212,5 +226,29 @@
212226
width: 100%;
213227
}
214228
}
229+
230+
.load-more-container {
231+
text-align: center;
232+
margin: 16px 0;
233+
234+
.load-more-btn {
235+
padding: 10px 20px;
236+
border: none;
237+
border-radius: 6px;
238+
background: #007bff;
239+
color: #fff;
240+
font-size: 14px;
241+
cursor: pointer;
242+
transition: background 0.2s ease;
243+
244+
&:hover {
245+
background: #0056b3;
246+
}
247+
}
248+
}
249+
250+
.loading-more {
251+
margin: 16px 0;
252+
}
215253
}
216254
}

src/app/features/resource-learning/pages/resource-detail/resource-detail.ts

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import {
1919
import { sendNotification } from '../../../../shared/utils/notification';
2020
import { MarkdownModule } from 'ngx-markdown';
2121
import { DEFAULT_AVATAR } from '../../../../core/models/user.models';
22+
import { forkJoin } from 'rxjs';
23+
import { map } from 'rxjs/operators';
24+
import { lottieOptionsServerError } from '../../../../core/constants/value.constant';
25+
import { LottieComponent } from 'ngx-lottie';
2226

2327
@Component({
2428
selector: 'app-resource-detail',
@@ -32,16 +36,19 @@ import { DEFAULT_AVATAR } from '../../../../core/models/user.models';
3236
SkeletonLoadingComponent,
3337
InputComponent,
3438
MarkdownModule,
39+
LottieComponent,
3540
],
3641
standalone: true,
3742
})
3843
export class ResourceDetail implements OnInit {
3944
avatarDefault = DEFAULT_AVATAR;
45+
lottieOption = lottieOptionsServerError;
4046
[x: string]: any;
4147
resourceId: string | null = null;
4248
resource!: MediaResource;
4349

4450
listResource: MediaResource[] = [];
51+
searchAbleList: MediaResource[] = [];
4552
searchTerm: string = '';
4653
searchTermError: string | null = null;
4754
avatarAuthor = '';
@@ -166,21 +173,37 @@ export class ResourceDetail implements OnInit {
166173

167174
this.isLoadingMore = true;
168175

169-
this.resourceService
170-
.getAllResourceLearning(this.pageSize, this.currentPage)
176+
forkJoin([
177+
this.resourceService.getVideoResources(),
178+
this.resourceService.getDocumentResources(),
179+
])
180+
.pipe(
181+
map(([videosRes, docsRes]) => {
182+
const videos = videosRes.result ?? [];
183+
const docs = docsRes.result ?? [];
184+
return [...videos, ...docs]; // gộp
185+
})
186+
)
171187
.subscribe({
172-
next: (res) => {
173-
const pagination = res.result;
174-
this.listResource.push(...pagination.data);
175-
this.hasMore = pagination.hasNextPage;
188+
next: (allResources) => {
189+
// tổng dữ liệu từ cả video + document
190+
const start = (this.currentPage - 1) * this.pageSize;
191+
const end = this.currentPage * this.pageSize;
192+
193+
// cắt dữ liệu theo trang
194+
const pageData = allResources.slice(start, end);
195+
196+
this.listResource.push(...pageData);
197+
this.searchAbleList = this.listResource;
198+
this.hasMore = end < allResources.length;
176199
this.currentPage++;
177200
this.isLoadingMore = false;
178201
},
179202
error: (err) => {
180203
console.error(err);
181204
sendNotification(
182205
this.store,
183-
'Lỗi lấy danh sách video',
206+
'Lỗi lấy danh sách tài nguyên',
184207
err.message,
185208
'error'
186209
);
@@ -190,13 +213,27 @@ export class ResourceDetail implements OnInit {
190213
}
191214

192215
goToDetail = (resourceId: string) => {
193-
this.router.navigate(['/resource-management/resource', resourceId]);
216+
this.router.navigate(['/resource-learning/resource', resourceId]);
194217
this.resourceId = resourceId;
195218
this.loadResource();
196219
};
197220

198221
handleInputChange(value: string | number): void {
199-
this.searchTerm = value.toString();
222+
this.searchTerm = value.toString().trim().toLowerCase();
223+
224+
if (this.searchTerm) {
225+
this.listResource = this.searchAbleList.filter(
226+
(data) =>
227+
(data.description ?? '').toLowerCase().includes(this.searchTerm) ||
228+
(data.fileName ?? '').toLowerCase().includes(this.searchTerm) ||
229+
(data.userProfile?.displayName ?? '')
230+
.toLowerCase()
231+
.includes(this.searchTerm)
232+
);
233+
} else {
234+
// Nếu clear ô tìm kiếm thì reset về danh sách gốc
235+
this.listResource = [...this.searchAbleList];
236+
}
200237
}
201238

202239
downloadDocument() {

0 commit comments

Comments
 (0)