Skip to content
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
4 changes: 2 additions & 2 deletions src/app/core/models/post.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export interface PostADD {
allowComment?: boolean;
postType?: PostType;
fileUrls: string; // CHUẨN THEO BE (lưu ý đánh vần!)
hashtag: string; // nếu muốn gửi dạng mảng
hashtag: string[]; // nếu muốn gửi dạng mảng
fileDocument?: FileDocument | null;
}

Expand All @@ -99,7 +99,7 @@ export interface CreatePostRequest {
isPublic: boolean;
allowComment: boolean;
postType: PostType;
hashtag?: string;
hashtag?: string[]; // nếu muốn gửi dạng mảng

fileDocument?: {
files?: File[];
Expand Down
9 changes: 8 additions & 1 deletion src/app/core/services/api-service/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export class PostService {
const fd: Record<string, any> = {
'fileDocument.category': fileDocument.category,
'fileDocument.description': fileDocument.description,
'fileDocument.tags': fileDocument.tags,
// 'fileDocument.tags': fileDocument.tags, // Xử lý riêng bên dưới

'fileDocument.isLectureVideo': fileDocument.isLectureVideo,
'fileDocument.isTextBook': fileDocument.isTextBook,
'fileDocument.orgId': fileDocument.orgId,
Expand All @@ -123,6 +124,12 @@ export class PostService {
formDataData[key] = value;
}
}
// Nếu cần gửi tags theo dạng array [0], [1]...
if (fileDocument.tags?.length) {
fileDocument.tags.forEach((tag, i) => {
formDataData[`fileDocument.tags[${i}]`] = tag;
});
}
}

// Gọi API
Expand Down
16 changes: 12 additions & 4 deletions src/app/features/post/pages/post-create/post-create.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
></app-input>
</div>
<div class="input-info">
<app-dropdown-button
<app-input
label="Nhập tag (cách nhau bởi dấu ,)"
placeholder="Ví dụ: toán, lý, hoá"
[value]="tagInput"
(valueChange)="handleTagInputChange($event)"
[variant]="'primary'"
[isSvg]="false"
></app-input>
<!-- <app-dropdown-button
[label]="'Chủ đề'"
[options]="topics"
[variant]="'secondary'"
Expand Down Expand Up @@ -51,8 +59,8 @@
[isSearchable]="true"
[minHeight]="true"
[needIndexColor]="true"
></app-dropdown-button>
<app-dropdown-button
></app-dropdown-button> -->
<!-- <app-dropdown-button
[label]="'tag'"
[options]="tag"
[variant]="'secondary'"
Expand All @@ -69,7 +77,7 @@
[isSearchable]="true"
[minHeight]="true"
[needIndexColor]="true"
></app-dropdown-button>
></app-dropdown-button> -->
</div>
<div class="post-options-container">
<div class="option-group">
Expand Down
45 changes: 27 additions & 18 deletions src/app/features/post/pages/post-create/post-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
clearLoading,
setLoading,
} from '../../../../shared/store/loading-state/loading.action';
import { th } from 'date-fns/locale';

export interface Draft {
id: string; // ID duy nhất cho mỗi bản nháp
Expand All @@ -45,7 +46,7 @@ export interface Draft {
imports: [
InputComponent,
TextEditor,
DropdownButtonComponent,
// DropdownButtonComponent,
ButtonComponent,
FormsModule,
CommonModule,
Expand All @@ -64,7 +65,7 @@ export class PostCreatePageComponent {
allowComment: true,
postType: 'Global',
fileUrls: '', // CHUẨN THEO BE (lưu ý đánh vần!)
hashtag: '', // nếu muốn gửi dạng mảng
hashtag: [], // nếu muốn gửi dạng mảng
fileDocument: null,
};

Expand Down Expand Up @@ -114,6 +115,23 @@ export class PostCreatePageComponent {
ngOnInit(): void {
this.loadAllDrafts();
}
tagInput: string = ''; // người dùng nhập tag thô
tags: string[] = []; // danh sách tag đã cắt ra
handleTagInputChange(value: string | number): void {
this.tagInput = value.toString();
this.tags = this.tagInput
.split(',')
.map((t) => t.trim())
.filter((t) => t.length > 0); // loại bỏ tag rỗng
if (this.tags.length > 0) {
if (!this.post.fileDocument) {
this.post.fileDocument = {};
}
this.post.hashtag = this.tags;
this.post.fileDocument.tags = this.tags;
}
console.log('Danh sách tag:', this.tags);
}

onFilesSelected(event: Event) {
const input = event.target as HTMLInputElement;
Expand Down Expand Up @@ -166,15 +184,6 @@ export class PostCreatePageComponent {
this.post.fileDocument.orgId = selected?.value || '';
}

if (dropdownKey === 'tag') {
if (!this.post.fileDocument) this.post.fileDocument = {};
if (Array.isArray(selected)) {
this.post.fileDocument.tags = selected.map((s) => s.label);
} else {
this.post.fileDocument.tags = selected?.label ? [selected.label] : [];
}
}

if (dropdownKey === 'hashtag') {
this.post.hashtag = selected?.value || '';
}
Expand Down Expand Up @@ -262,12 +271,12 @@ export class PostCreatePageComponent {

// Hàm helper để cập nhật UI của dropdowns
updateSelectedOptionsFromDraft(): void {
if (this.post.hashtag) {
const selectedTopic = this.topics.find(
(t) => t.value === this.post.hashtag
);
if (selectedTopic) this.selectedOptions['hashtag'] = selectedTopic;
}
// if (this.post.hashtag) {
// const selectedTopic = this.topics.find(
// (t) => t.value === this.post.hashtag
// );
// if (selectedTopic) this.selectedOptions['hashtag'] = selectedTopic;
// }
if (this.post.orgId) {
const selectedWhere = this.wherepost.find(
(w) => w.value === this.post.orgId
Expand Down Expand Up @@ -378,7 +387,7 @@ export class PostCreatePageComponent {
allowComment: true,
postType: 'Global',
fileUrls: '',
hashtag: '',
hashtag: [],
fileDocument: null,
};
this.editorContent = '';
Expand Down
8 changes: 7 additions & 1 deletion src/app/shared/utils/mapData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export function mapPostInfortoPost(post: PostADD): Post {
};
}
export function mapPostdatatoPostCardInfo(post: PostResponse): PostCardInfo {
let tagInput = post.hashtag || '';
let taglist = tagInput
.split(',')
.map((t) => t.trim())
.filter((t) => t.length > 0); // loại bỏ tag rỗng

return {
id: post.postId,
avatar: post.user?.avatarUrl || avatarUrlDefault,
Expand All @@ -87,7 +93,7 @@ export function mapPostdatatoPostCardInfo(post: PostResponse): PostCardInfo {
title: post.title,
time: post.createdAt,
description: post.content,
tags: [post.hashtag],
tags: taglist,
comment: post.commentCount,
upvote: post.upvoteCount,
downvote: post.downvoteCount,
Expand Down
Loading