@@ -30,6 +30,7 @@ import {
3030 clearLoading ,
3131 setLoading ,
3232} from '../../../../shared/store/loading-state/loading.action' ;
33+ import { th } from 'date-fns/locale' ;
3334
3435export interface Draft {
3536 id : string ; // ID duy nhất cho mỗi bản nháp
@@ -45,7 +46,7 @@ export interface Draft {
4546 imports : [
4647 InputComponent ,
4748 TextEditor ,
48- DropdownButtonComponent ,
49+ // DropdownButtonComponent,
4950 ButtonComponent ,
5051 FormsModule ,
5152 CommonModule ,
@@ -64,7 +65,7 @@ export class PostCreatePageComponent {
6465 allowComment : true ,
6566 postType : 'Global' ,
6667 fileUrls : '' , // CHUẨN THEO BE (lưu ý đánh vần!)
67- hashtag : '' , // nếu muốn gửi dạng mảng
68+ hashtag : [ ] , // nếu muốn gửi dạng mảng
6869 fileDocument : null ,
6970 } ;
7071
@@ -114,6 +115,23 @@ export class PostCreatePageComponent {
114115 ngOnInit ( ) : void {
115116 this . loadAllDrafts ( ) ;
116117 }
118+ tagInput : string = '' ; // người dùng nhập tag thô
119+ tags : string [ ] = [ ] ; // danh sách tag đã cắt ra
120+ handleTagInputChange ( value : string | number ) : void {
121+ this . tagInput = value . toString ( ) ;
122+ this . tags = this . tagInput
123+ . split ( ',' )
124+ . map ( ( t ) => t . trim ( ) )
125+ . filter ( ( t ) => t . length > 0 ) ; // loại bỏ tag rỗng
126+ if ( this . tags . length > 0 ) {
127+ if ( ! this . post . fileDocument ) {
128+ this . post . fileDocument = { } ;
129+ }
130+ this . post . hashtag = this . tags ;
131+ this . post . fileDocument . tags = this . tags ;
132+ }
133+ console . log ( 'Danh sách tag:' , this . tags ) ;
134+ }
117135
118136 onFilesSelected ( event : Event ) {
119137 const input = event . target as HTMLInputElement ;
@@ -166,15 +184,6 @@ export class PostCreatePageComponent {
166184 this . post . fileDocument . orgId = selected ?. value || '' ;
167185 }
168186
169- if ( dropdownKey === 'tag' ) {
170- if ( ! this . post . fileDocument ) this . post . fileDocument = { } ;
171- if ( Array . isArray ( selected ) ) {
172- this . post . fileDocument . tags = selected . map ( ( s ) => s . label ) ;
173- } else {
174- this . post . fileDocument . tags = selected ?. label ? [ selected . label ] : [ ] ;
175- }
176- }
177-
178187 if ( dropdownKey === 'hashtag' ) {
179188 this . post . hashtag = selected ?. value || '' ;
180189 }
@@ -262,12 +271,12 @@ export class PostCreatePageComponent {
262271
263272 // Hàm helper để cập nhật UI của dropdowns
264273 updateSelectedOptionsFromDraft ( ) : void {
265- if ( this . post . hashtag ) {
266- const selectedTopic = this . topics . find (
267- ( t ) => t . value === this . post . hashtag
268- ) ;
269- if ( selectedTopic ) this . selectedOptions [ 'hashtag' ] = selectedTopic ;
270- }
274+ // if (this.post.hashtag) {
275+ // const selectedTopic = this.topics.find(
276+ // (t) => t.value === this.post.hashtag
277+ // );
278+ // if (selectedTopic) this.selectedOptions['hashtag'] = selectedTopic;
279+ // }
271280 if ( this . post . orgId ) {
272281 const selectedWhere = this . wherepost . find (
273282 ( w ) => w . value === this . post . orgId
@@ -378,7 +387,7 @@ export class PostCreatePageComponent {
378387 allowComment : true ,
379388 postType : 'Global' ,
380389 fileUrls : '' ,
381- hashtag : '' ,
390+ hashtag : [ ] ,
382391 fileDocument : null ,
383392 } ;
384393 this . editorContent = '' ;
0 commit comments