From ff0065ac87ed3704dd4c501a0dcb7416db757742 Mon Sep 17 00:00:00 2001 From: Michael Foiani Date: Mon, 24 Sep 2018 17:30:26 -0400 Subject: Fixed issues with comment system. Now works but is unstable. --- src/components/forum-element.js | 88 +++++++++++++++++++++++++++++------------ src/components/mao-admin.js | 2 +- src/components/mao-forums.js | 71 +++++++++++++++++++++++++-------- 3 files changed, 117 insertions(+), 44 deletions(-) (limited to 'src/components') diff --git a/src/components/forum-element.js b/src/components/forum-element.js index 1c2585b..3177892 100644 --- a/src/components/forum-element.js +++ b/src/components/forum-element.js @@ -38,7 +38,8 @@ class ForumElement extends connect(store)(LitElement) { } .card-content > h4 { - text-align: right; + display: grid; + grid-template-columns: 1fr 1fr; font-weight: lighter; font-style: italic; word-break: break-all; @@ -57,6 +58,25 @@ class ForumElement extends connect(store)(LitElement) { margin-top: 5px; } + .comment-title { + text-align: center; + } + + .comment-author { + text-align: center; + font-weight: lighter; + font-style: italic; + word-break: break-all; + } + + .forum-date { + text-align: left; + } + + .forum-author { + text-align: right; + } + @media (min-width: 460px) { .button-grid { grid-template-columns: 1fr 1fr; @@ -76,28 +96,26 @@ class ForumElement extends connect(store)(LitElement) {
-

${props.author}

+

${props.day ? props.day.toDate().toLocaleDateString("en-US"): ""}${props.author}

${props.subject}

${props.content}

- Show Comments - ${this.postComment? "Hide Draft" : "Post Comment"} + +
+

Comments

+
@@ -110,6 +128,7 @@ class ForumElement extends connect(store)(LitElement) { author: String, subject: String, content: String, + day: Date, postId: String, comments: Array, @@ -122,13 +141,16 @@ class ForumElement extends connect(store)(LitElement) { this.signedIn = state.firebaseAuth.signedIn; } + _firstRendered() { + this.updateComments(); + } + constructor() { super(); this.signedIn = false; this.author = ""; - this.subject = ""; this.content = ""; this.postId = ""; @@ -139,23 +161,37 @@ class ForumElement extends connect(store)(LitElement) { } 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.'); - } - + var commentContent = this.shadowRoot.getElementById('comment-content-field'); + if( commentContent && + 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, commentContent.value.replace('\n','
'))); + commentContent.value = ""; + } + } else { + alert('Please fill out comment subject and content fields.'); + } + } + + updateComments() { + var commentArea = this.shadowRoot.getElementById('comment-area'); + commentArea.innerHTML = ""; + + for(var i = this.comments.length-1; i >= 0; i--) { + var commentElement = document.createElement('div'); + + var authorElement = document.createElement('h4'); + authorElement.classList.add('comment-author'); + authorElement.innerHTML = this.comments[i].user; + + var contentElement = document.createElement('p'); + contentElement.innerHTML = this.comments[i].content; + + commentElement.appendChild(authorElement); + commentElement.appendChild(contentElement); + + commentArea.appendChild(commentElement); + } } } diff --git a/src/components/mao-admin.js b/src/components/mao-admin.js index 0e8825e..a8e7435 100644 --- a/src/components/mao-admin.js +++ b/src/components/mao-admin.js @@ -73,7 +73,7 @@ class MaoAdmin extends connect(store)(PageViewElement) {
Show Hours Requests Show Competitions And Registry - Show User Data + ${props.usersHidden ? 'Show User Data' : 'Hide User Data'}

diff --git a/src/components/mao-forums.js b/src/components/mao-forums.js index 1d1b5f6..b7631d2 100644 --- a/src/components/mao-forums.js +++ b/src/components/mao-forums.js @@ -16,7 +16,7 @@ import { connect } from 'pwa-helpers/connect-mixin.js'; import { store } from '../store.js'; //These are the actions needed by this element. -import { createForumPost } from '../actions/firebaseFirestore.js'; +import { createForumPost, snapshotForums } from '../actions/firebaseFirestore.js'; // These are the shared styles needed by this element. import { SharedStyles } from './shared-styles.js'; @@ -34,7 +34,7 @@ import '@polymer/paper-button/paper-button.js'; import '@vaadin/vaadin-date-picker/vaadin-date-picker.js'; //import local customElements -import './forum-element.js' +import './forum-element.js'; class MaoForums extends connect(store)(PageViewElement) { _render(props) { @@ -44,6 +44,37 @@ class MaoForums extends connect(store)(PageViewElement) {