misuzu/assets/misuzu.js/comments/section.jsx
2025-02-16 00:19:42 +00:00

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;
},
};
};