44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
#include msgbox.jsx
|
|
#include comments/api.js
|
|
#include comments/form.jsx
|
|
#include comments/listing.jsx
|
|
|
|
const MszCommentsSection = function(options) {
|
|
let { category: catName } = options ?? {};
|
|
|
|
const listing = new MszCommentsListing({ root: true });
|
|
const element = <div class="comments">
|
|
{listing}
|
|
</div>;
|
|
|
|
let form;
|
|
|
|
MszCommentsApi.getCategory(catName)
|
|
.then(catInfo => {
|
|
console.log(catInfo);
|
|
|
|
let formElement;
|
|
if(catInfo.user?.can_create) {
|
|
form = new MszCommentsForm(catInfo.user, true);
|
|
formElement = form.element;
|
|
} else
|
|
formElement = (new MszCommentsFormNotice).element;
|
|
|
|
$insertBefore(listing.element, formElement);
|
|
|
|
listing.addPosts(catInfo.user, catInfo.posts);
|
|
})
|
|
.catch(message => {
|
|
console.error(message);
|
|
|
|
// THIS IS NOT FINAL DO NOT PUSH THIS TO PUBLIC THIS WOULD BE HORRIBLE
|
|
if(typeof message === 'string')
|
|
MszShowMessageBox(message);
|
|
});
|
|
|
|
return {
|
|
get element() {
|
|
return element;
|
|
},
|
|
};
|
|
};
|