Recent Posts
Please connect to internet so we can fetch forums.
`;
}
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 paperCard = document.createElement('paper-card');
var cardContent = document.createElement('div');
var forumAuthor = document.createElement('h4');
var forumSubject = document.createElement('h3');
var forumContent = document.createElement('p');
forumAuthor.innerHTML = this.forumPosts[i].email .replace('@communityschoolnaples.org', '');
forumSubject.innerHTML = this.forumPosts[i].subject;
forumContent.innerHTML = this.forumPosts[i].content;
cardContent.classList.add('card-content');
cardContent.appendChild( forumAuthor);
cardContent.appendChild( forumSubject);
cardContent.appendChild( forumContent);
paperCard.elevation = 0;
paperCard.appendChild( cardContent);
postsGrid.appendChild(paperCard);
}
}
}
}
window.customElements.define('mao-forums', MaoForums);