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 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);