CommentContainer.jsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { Container } from 'unstated';
  2. /**
  3. *
  4. * @author Yuki Takei <yuki@weseek.co.jp>
  5. *
  6. * @extends {Container} unstated Container
  7. */
  8. export default class CommentContainer extends Container {
  9. constructor(crowi, pageId, revisionId) {
  10. super();
  11. this.crowi = crowi;
  12. this.pageId = pageId;
  13. this.revisionId = revisionId;
  14. }
  15. init() {
  16. if (!this.props.pageId) {
  17. return;
  18. }
  19. }
  20. /**
  21. * Load data of comments and rerender <PageComments />
  22. */
  23. postComment(comment, isMarkdown, replyTo, isSlackEnabled, slackChannels) {
  24. return this.crowi.apiPost('/comments.add', {
  25. commentForm: {
  26. comment,
  27. _csrf: this.crowi.csrfToken,
  28. page_id: this.pageId,
  29. revision_id: this.revisionId,
  30. is_markdown: isMarkdown,
  31. replyTo,
  32. },
  33. slackNotificationForm: {
  34. isSlackEnabled,
  35. slackChannels,
  36. },
  37. });
  38. }
  39. onUpload(file) {
  40. const endpoint = '/attachments.add';
  41. // // create a FromData instance
  42. // const formData = new FormData();
  43. // formData.append('_csrf', this.props.data.crowi.csrfToken);
  44. // formData.append('file', file);
  45. // formData.append('path', this.props.data.pagePath);
  46. // formData.append('page_id', this.props.data.pageId || 0);
  47. // // post
  48. // this.props.data.crowi.apiPost(endpoint, formData)
  49. // .then((res) => {
  50. // const attachment = res.attachment;
  51. // const fileName = attachment.originalName;
  52. // let insertText = `[${fileName}](${attachment.filePathProxied})`;
  53. // // when image
  54. // if (attachment.fileFormat.startsWith('image/')) {
  55. // // modify to "![fileName](url)" syntax
  56. // insertText = `!${insertText}`;
  57. // }
  58. // this.editor.insertText(insertText);
  59. // })
  60. // .catch(this.apiErrorHandler)
  61. // // finally
  62. // .then(() => {
  63. // this.editor.terminateUploadingState();
  64. // });
  65. }
  66. }