/** @license Copyright (c) 2018 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt */ import { html } from '@polymer/lit-element'; import { PageViewElement } from './page-view-element.js'; import { connect } from 'pwa-helpers/connect-mixin.js'; // This element is connected to the Redux store. import { store } from '../store.js'; //These are the actions needed by this element. import { createForumPost } from '../actions/firebaseFirestore.js'; // These are the shared styles needed by this element. import { SharedStyles } from './shared-styles.js'; import { ButtonSharedStyles } from './button-shared-styles.js' // Import paper elements import '@polymer/paper-input/paper-input.js'; import '@polymer/paper-input/paper-textarea.js'; import '@polymer/paper-card/paper-card.js'; import '@polymer/paper-dropdown-menu/paper-dropdown-menu.js'; import '@polymer/paper-item/paper-item.js'; import '@polymer/paper-button/paper-button.js'; // Import other customElements import '@vaadin/vaadin-date-picker/vaadin-date-picker.js'; //import local customElements import './forum-element.js' class MaoForums extends connect(store)(PageViewElement) { _render(props) { return html` ${SharedStyles} ${ButtonSharedStyles}

Recent Posts

`; } static get properties() { return { // This is the data from the store. signedIn: Boolean, forumPosts: Array, onceOnline: Boolean }} constructor() { super(); this.onceOnline = false; } _stateChanged(state) { this.signedIn = state.firebaseAuth .signedIn; this.forumPosts = state.firebaseFirestore .forumPosts; this.updateSection(); if(!state.app.offline) { this.onceOnline = true; } } submitForum() { if(this.shadowRoot) { var subjectElement = this.shadowRoot.getElementById('subject-field'); var contentElement = this.shadowRoot.getElementById('content-field'); if(!contentElement.value) { contentElement.value = ""; } if( subjectElement.value.trim() === "" || contentElement.value.trim() === "" ) { alert("Please fill out all fields when creating a form post."); } else { if(confirm('Are you sure you want to submit this to the forum page? It will be public to everyone.')) { store.dispatch(createForumPost(subjectElement.value, contentElement.value)); subjectElement.value = ""; contentElement.value = ""; } } } } updateSection() { if(this.shadowRoot) { var postsGrid = this.shadowRoot.getElementById('posts-grid'); postsGrid.innerHTML = ""; for(var i = this.forumPosts.length-1; i >=0; i--) { var forumElement = document.createElement('forum-element'); forumElement.author = this.forumPosts[i].email .replace('@communityschoolnaples.org', ''); forumElement.subject = this.forumPosts[i].subject; forumElement.content = this.forumPosts[i].content; postsGrid.appendChild(forumElement); } } } } window.customElements.define('mao-forums', MaoForums);