1- import { Component , ViewChild } from '@angular/core' ;
2- import { FormBuilder , FormControl , FormsModule , UntypedFormGroup , Validators } from '@angular/forms' ;
1+ import { ChangeDetectionStrategy , ChangeDetectorRef , Component , ViewChild } from '@angular/core' ;
2+ import { FormBuilder , FormControl , FormsModule , Validators } from '@angular/forms' ;
33import { NavigationService } from '../../services/navigation' ;
44import { Location , CommonModule } from '@angular/common' ;
55import { ApplicationState } from '../../services/applicationstate' ;
66import { BlogEvent , NostrEvent } from '../../services/interfaces' ;
7- import { Event , kinds } from 'nostr-tools' ;
7+ import { kinds } from 'nostr-tools' ;
88import { Subscription } from 'rxjs' ;
99import { now , Utilities } from '../../services/utilities' ;
10+ import { TranslateModule } from '@ngx-translate/core' ;
1011import { QueueService } from '../../services/queue.service' ;
1112import { ArticleService } from '../../services/article' ;
1213import { MatSnackBar , MatSnackBarModule } from '@angular/material/snack-bar' ;
@@ -23,6 +24,7 @@ import { ContentEditorDirective } from '../../shared/content-input-directive/con
2324import { MentionModule } from 'angular-mentions' ;
2425import { MatInputModule } from '@angular/material/input' ;
2526import { MatButtonModule } from '@angular/material/button' ;
27+ import { DateTimeComponent } from "../../shared/date-time/date-time.component" ;
2628
2729export interface NoteDialogData {
2830 note : string ;
@@ -32,23 +34,39 @@ export interface NoteDialogData {
3234 selector : 'app-editor' ,
3335 standalone : true ,
3436 imports : [
37+ TranslateModule ,
3538 MentionModule ,
3639 MatButtonModule ,
37- CommonModule , MatSnackBarModule , PickerModule , EventComponent , ContentEditorDirective , ReactiveFormsModule , FormsModule , MatButtonToggleModule , MatFormFieldModule , MatInputModule , MatSelectModule , MatIconModule ] ,
40+ CommonModule , MatSnackBarModule , PickerModule , EventComponent , ContentEditorDirective , ReactiveFormsModule , FormsModule , MatButtonToggleModule , MatFormFieldModule , MatInputModule , MatSelectModule , MatIconModule ,
41+ DateTimeComponent
42+ ] ,
3843 templateUrl : 'editor.html' ,
3944 styleUrls : [ 'editor.css' ] ,
45+ changeDetection : ChangeDetectionStrategy . OnPush ,
4046} )
4147export class EditorComponent {
42- @ViewChild ( 'picker' ) picker : unknown ;
4348 @ViewChild ( 'noteContent' ) noteContent ?: FormControl ;
4449 @ViewChild ( 'articleContent' ) articleContent ?: FormControl ;
4550
46- isEmojiPickerVisible : boolean | undefined ;
51+ eventType = new FormControl ( 'text' ) ;
52+
53+ isEmojiPickerVisible : boolean = false ;
54+ isArticleEmojiPickerVisible : boolean = false ;
55+
56+ ArticleDateTimeValue : Date = new Date ( ) ;
57+ NoteDateTimeValue : Date = new Date ( ) ;
58+
59+ minNoteDateValue : Date = new Date ( ) ;
60+ minArticleDateValue : Date = new Date ( ) ;
61+
62+ ArticleLabel : string = 'DateTimeComponent.Label.Article' ;
63+ NoteLabel : string = 'DateTimeComponent.Label.Note' ;
64+ DateLabel : string = 'DateTimeComponent.DateLabel' ;
65+ TimeLabel : string = 'DateTimeComponent.TimeLabel' ;
4766
4867 noteForm = this . fb . group ( {
4968 content : [ '' , Validators . required ] ,
5069 expiration : [ '' ] ,
51- dateControl : [ ] ,
5270 } ) ;
5371
5472 articleForm = this . fb . group ( {
@@ -71,14 +89,10 @@ export class EditorComponent {
7189
7290 minDate ?: number ;
7391
74- eventType : string = 'text' ;
75-
76- public dateControl = new FormControl ( null ) ;
92+ followingUsers : string [ ] = this . profileService . following . map ( follower => follower . name ) ;
7793
7894 subscriptions : Subscription [ ] = [ ] ;
7995
80- followingUsers : string [ ] = this . profileService . following . map ( follower => follower . name ) ;
81-
8296 constructor (
8397 private snackBar : MatSnackBar ,
8498 public articleService : ArticleService ,
@@ -89,7 +103,8 @@ export class EditorComponent {
89103 private fb : FormBuilder ,
90104 public navigation : NavigationService ,
91105 public profileService : ProfileService ,
92- private eventService : EventService
106+ private eventService : EventService ,
107+ private cdr : ChangeDetectorRef
93108 ) { }
94109
95110 ngOnInit ( ) {
@@ -115,6 +130,16 @@ export class EditorComponent {
115130 ) ;
116131 }
117132
133+ handleNoteDateTimeChange ( dateTime : Date | null ) : void {
134+ this . noteForm . patchValue ( { expiration : dateTime ?. toDateString ( ) } ) ;
135+ this . cdr . detectChanges ( ) ;
136+ }
137+
138+ handleArticleDateTimeChange ( dateTime : Date | null ) : void {
139+ this . articleForm . patchValue ( { published_at : dateTime ?. toDateString ( ) } ) ;
140+ this . cdr . detectChanges ( ) ;
141+ }
142+
118143 updateEvent ( content : string | null ) {
119144 if ( ! content ) {
120145 this . event = undefined ;
@@ -177,7 +202,7 @@ export class EditorComponent {
177202
178203 noteTypeChanged ( ) {
179204 // Load all articles for the user when toggling.
180- if ( this . eventType == 'article' ) {
205+ if ( this . eventType . value == 'article' ) {
181206 this . queueService . enque ( this . appState . getPublicKey ( ) , 'Article' ) ;
182207 }
183208 }
0 commit comments