From b7cc4f1d2e9c55ad78f8c6a27724f1f8a6393d65 Mon Sep 17 00:00:00 2001 From: Michael Foiani Date: Mon, 17 Sep 2018 19:33:42 -0400 Subject: Stil working on comment feature. Successfully connected the comments on posts to forum-elements. Just need to create html to show comments. --- src/components/forum-element.js | 37 +++++++++++++++++++++++++++++++------ src/components/mao-forums.js | 2 ++ 2 files changed, 33 insertions(+), 6 deletions(-) (limited to 'src/components') diff --git a/src/components/forum-element.js b/src/components/forum-element.js index 138cc6a..1c2585b 100644 --- a/src/components/forum-element.js +++ b/src/components/forum-element.js @@ -15,7 +15,7 @@ import { connect } from 'pwa-helpers/connect-mixin.js'; import { store } from '../store.js'; //These are the actions needed by this element. -import { adminApproveHours, adminRejectHours } from '../actions/firebaseAdmin.js'; +import { createComment } from '../actions/firebaseFirestore'; // Import button styles import { ButtonSharedStyles } from './button-shared-styles.js'; @@ -82,21 +82,21 @@ class ForumElement extends connect(store)(LitElement) {
- Show Comments - ${this.postComment? "Hide Draft" : "Post Comment"} + Show Comments + ${this.postComment? "Hide Draft" : "Post Comment"}
@@ -110,6 +110,9 @@ class ForumElement extends connect(store)(LitElement) { author: String, subject: String, content: String, + postId: String, + + comments: Array, showComments: Boolean, postComment: Boolean @@ -127,11 +130,33 @@ class ForumElement extends connect(store)(LitElement) { this.author = ""; this.subject = ""; this.content = ""; + this.postId = ""; + + this.comments = []; this.showComments = false; this.postComment = false; } - + + submitComment() { + var commentSubject = this.shadowRoot.getElementById('comment-subject-field'); + var commentContent = this.shadowRoot.getElementById('comment-content-field'); + //commentContent.value.replace('\n','
') + if( commentSubject && + commentSubject.value.trim().length > 0 && + commentContent.value.trim().length > 0) { + if(confirm('Are you sure you want to submit this comment on ' + this.author + "'s post about " + this.subject + '?')) { + store.dispatch(createComment(this.postId, commentSubject.value, commentContent.value)); + + commentSubject.value = ""; + commentContent.value = ""; + } + } else { + console.log(this.comments); + alert('Please fill out comment subject and content fields.'); + } + + } } window.customElements.define('forum-element', ForumElement); diff --git a/src/components/mao-forums.js b/src/components/mao-forums.js index b85fa26..1d1b5f6 100644 --- a/src/components/mao-forums.js +++ b/src/components/mao-forums.js @@ -153,6 +153,8 @@ class MaoForums extends connect(store)(PageViewElement) { forumElement.author = this.forumPosts[i].email .replace('@communityschoolnaples.org', ''); forumElement.subject = this.forumPosts[i].subject; forumElement.content = this.forumPosts[i].content; + forumElement.postId = this.forumPosts[i].postId; + forumElement.comments = this.forumPosts[i].comments; postsGrid.appendChild(forumElement); } -- cgit v1.2.3-70-g09d2