|
@@ -1,21 +1,29 @@
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
+import { FormsModule } from '@angular/forms';
|
|
|
import { Router } from '@angular/router';
|
|
|
-import { IonButton, IonContent, IonIcon } from '@ionic/angular/standalone';
|
|
|
+import { IonModal } from '@ionic/angular/standalone';
|
|
|
+import { IonButton, IonContent, IonFooter, IonIcon, IonTextarea } from '@ionic/angular/standalone';
|
|
|
import { addIcons } from 'ionicons';
|
|
|
-import { bookmarkOutline, ellipsisHorizontal, heartOutline } from 'ionicons/icons';
|
|
|
+import { bookmarkOutline, ellipsisHorizontal, happyOutline, heartOutline, shareSocialOutline } from 'ionicons/icons';
|
|
|
+import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
|
|
|
|
|
|
-addIcons({ellipsisHorizontal,bookmarkOutline,heartOutline,})
|
|
|
+addIcons({ellipsisHorizontal,bookmarkOutline,heartOutline,shareSocialOutline,happyOutline,})
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-post-detail',
|
|
|
templateUrl: './post-detail.component.html',
|
|
|
styleUrls: ['./post-detail.component.scss'],
|
|
|
standalone: true,
|
|
|
- imports: [IonContent, IonIcon, IonButton, CommonModule]
|
|
|
+ imports: [IonContent, IonIcon, IonButton, CommonModule,IonTextarea,IonFooter,FormsModule,IonModal]
|
|
|
})
|
|
|
export class PostDetailComponent implements OnInit {
|
|
|
post: any;
|
|
|
+newComment: string = '';
|
|
|
+isfooter: boolean = true;
|
|
|
+comments: CloudObject[] = [];
|
|
|
+isFollowed: boolean = false;
|
|
|
+
|
|
|
constructor(private router: Router,) {
|
|
|
const navigation = this.router.getCurrentNavigation();
|
|
|
if (navigation && navigation.extras.state) {
|
|
@@ -25,12 +33,106 @@ post: any;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- ngOnInit() {}
|
|
|
+ ngOnInit() {
|
|
|
+ this.loadComments();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ async loadComments() {
|
|
|
+ const query = new CloudQuery("comment");
|
|
|
+ query.equalTo("post", { "__type": "Pointer", "className": "post", "objectId": this.post.id });
|
|
|
+ query.include('user');
|
|
|
+ this.comments = await query.find();
|
|
|
+ console.log('加载的评论:', this.comments);
|
|
|
|
|
|
- isFollowed: boolean = false;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
toggleFollow() {
|
|
|
this.isFollowed = !this.isFollowed;
|
|
|
}
|
|
|
|
|
|
+ tocomment(){
|
|
|
+ this.isfooter = false;
|
|
|
+ console.log(this.isfooter);
|
|
|
+ }
|
|
|
+
|
|
|
+ notcomment(){
|
|
|
+ this.isfooter = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ async submitComment() {
|
|
|
+ if (this.newComment.trim()) {
|
|
|
+
|
|
|
+ const comment = new CloudObject("comment");
|
|
|
+ const user = new CloudUser();
|
|
|
+ const currentUser = await user.current();
|
|
|
+ if (currentUser) {
|
|
|
+
|
|
|
+ comment.set({
|
|
|
+ user: new CloudUser().toPointer(),
|
|
|
+ post: { "__type": "Pointer", "className": "post", "objectId": this.post.id },
|
|
|
+ content: this.newComment.trim(),
|
|
|
+ heart: 0
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ comment.save().then(() => {
|
|
|
+ console.log('评论已保存:', this.newComment);
|
|
|
+ this.newComment = '';
|
|
|
+ })
|
|
|
+ this.loadComments();
|
|
|
+}
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ formatTimeAgo(date: any): string {
|
|
|
+ const date1 = new Date(date);
|
|
|
+ const now = new Date();
|
|
|
+ const seconds = Math.floor((now.getTime() - date1.getTime()) / 1000);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ let interval = Math.floor(seconds / 31536000);
|
|
|
+ if (interval >= 1) return interval + " 年前";
|
|
|
+ interval = Math.floor(seconds / 2592000);
|
|
|
+ if (interval >= 1) return interval + " 个月前";
|
|
|
+ interval = Math.floor(seconds / 86400);
|
|
|
+ if (interval >= 1) return interval + " 天前";
|
|
|
+ interval = Math.floor(seconds / 3600);
|
|
|
+ if (interval >= 1) return interval + " 小时前";
|
|
|
+ interval = Math.floor(seconds / 60);
|
|
|
+ if (interval >= 1) return interval + " 分钟前";
|
|
|
+ return "刚刚";
|
|
|
+}
|
|
|
+
|
|
|
+isEmojiPickerOpen: boolean = false;
|
|
|
+emojis: string[] = ['😀', '😃', '😄', '😁', '😆', '😅', '🤣', '😂', '🙂', '🙃', '🫠', '😉', '😊', '😇', '🥰', '😍', '🤩', '😘',
|
|
|
+ '😗', '☺️', '😚', '😙', '🥲', '😋', '😛', '😜', '🤪', '😝', '🤑', '🤗', '🤭', '🫢', '🫣', '🤫', '🤔', '🫡', '🤐', '🤨', '😐',
|
|
|
+ '😑', '😶', '🫥', '😶🌫️', '😏', '😒', '🙄', '😬', '😮💨', '🤥', '🫨', '🙂↔️', '🙂↕️', '😌', '😔', '😪', '🤤', '😴', '', '😷',
|
|
|
+ '🤒', '🤕', '🤢', '🤮', '🤧', '🥵', '🥶', '🥴', '😵', '😵💫', '🤯', '🤠', '🥳', '🥸', '😎', '🤓', '🧐', '😕', '🫤', '😟',
|
|
|
+ '🙁', '☹️', '😮', '😯', '😲', '😳', '🥺', '🥹', '😦', '😧', '😨', '😰', '😥', '😢', '😭', '😱', '😖', '😣', '😞', '😓',
|
|
|
+ '😩', '😫', '🥱', '😤', '😡', '😠', '🤬', '😈', '👿', '💀', '☠️', '💩', '🤡', '👹', '👺', '👻', '👽', '👾', '🤖', '😺',
|
|
|
+ '😸', '😹', '😻', '😼', '😽', '🙀', '😿', '😾', '🙈', '🙉', '🙊', '💌', '💘', '❤️', '🖤', '💋', '💯', '💢', '💥', '💫',
|
|
|
+ '💦', '💤'];
|
|
|
+
|
|
|
+openEmojiPicker() {
|
|
|
+this.isEmojiPickerOpen = true;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+closeEmojiPicker() {
|
|
|
+this.isEmojiPickerOpen = false;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+addEmoji(emoji: string) {
|
|
|
+this.newComment += emoji;
|
|
|
+this.closeEmojiPicker();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
}
|