(self["webpackJsonp@lyrio/ui"]=self["webpackJsonp@lyrio/ui"]||[]).push([[100],{1037:function(e,s,t){"use strict";t.r(s);var r=t(10),n=t.n(r),i=t(15),c=t(19),a=t(1),o=t(0),u=t(1804),d=t(1799),l=t(55),b=t(1560),p=t.n(b),f=t(183),j=t(181),m=t(9),O=t(22),h=t(912),w=t(842),x=t(182),v=t(37),k=function(e){var s,t=Object(O.i)("discussion_edit"),r=Object(O.k)();Object(o.useEffect)((function(){m.a.enterNewPage(e.discussion?"".concat(t(".title_update")," #").concat(e.discussion.meta.id):t(".title_new"))}),[m.a.locale,e.discussion]);var d=Object(O.l)(),l=Object(o.useState)(e.discussion?e.discussion.meta.title:""),b=Object(c.a)(l,2),f=b[0],v=b[1],k=Object(o.useState)(e.discussion?e.discussion.content:""),g=Object(c.a)(k,2),D=g[0],y=g[1];function C(){return(C=Object(i.a)(n.a.mark((function s(){var i,c,a,o,u,l;return n.a.wrap((function(s){for(;;)switch(s.prev=s.next){case 0:if(!e.discussion){s.next=6;break}return s.next=3,j.c.discussion.updateDiscussion({discussionId:e.discussion.meta.id,title:f,content:D});case 3:s.t0=s.sent,s.next=9;break;case 6:return s.next=8,j.c.discussion.createDiscussion({problemId:null===(i=e.problem)||void 0===i||null===(c=i.meta)||void 0===c?void 0:c.id,title:f,content:D},d("CreateDiscussion"));case 8:s.t0=s.sent;case 9:if(a=s.t0,o=a.requestError,u=a.response,!o){s.next=16;break}x.a.error(o(t)),s.next=22;break;case 16:if(!u.error){s.next=20;break}x.a.error(t(".errors.".concat(u.error))),s.next=22;break;case 20:return l=e.discussion?e.discussion.meta.id:u.discussionId,s.abrupt("return",(function(){return r.navigate("/d/".concat(l))}));case 22:return s.abrupt("return",!1);case 23:case"end":return s.stop()}}),s)})))).apply(this,arguments)}return Object(a.jsxs)(a.Fragment,{children:[Object(w.getBreadcrumb)(e.discussion?e.discussion.problem:e.problem,t,null,Object(a.jsxs)(a.Fragment,{children:[Object(a.jsx)(u.a.Divider,{icon:"right angle"}),Object(a.jsx)(u.a.Section,{children:e.discussion?"".concat(t(".header.update")," #").concat(e.discussion.meta.id):t(".header.add")})]})),Object(a.jsx)(h.DiscussionEditor,{className:p.a.editor,type:e.discussion?"UpdateDiscussion":"NewDiscussion",publisher:(null===(s=e.discussion)||void 0===s?void 0:s.publisher)||m.a.currentUser,title:f,content:D,onChangeTitle:function(e){return e.length<=80&&v(e)},onChangeContent:y,onCancel:function(){return r.navigate("/d/".concat(e.discussion.meta.id))},onSubmit:function(){return C.apply(this,arguments)},noSubmitPermission:e.discussion&&!e.discussion.permissions.includes("Modify")})]})};k=Object(l.a)(k),s.default={new:Object(f.c)(function(){var e=Object(i.a)(n.a.mark((function e(s){var t;return n.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(m.a.currentUser&&m.a.serverPreference.security.allowEveryoneCreateDiscussion||m.a.currentUserHasPrivilege("ManageDiscussion")){e.next=2;break}throw new f.a(Object(v.c)("discussion_edit.errors.PERMISSION_DENIED"));case 2:return e.next=4,Object(i.a)(n.a.mark((function e(){var t,r,i,c;return n.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=(t=s.params.problemId)){e.next=3;break}return e.abrupt("return",null);case 3:return e.next=5,j.c.problem.getProblem({id:Number(t)||0,localizedContentsOfLocale:m.a.locale,localizedContentsTitleOnly:!0});case 5:if(r=e.sent,i=r.requestError,c=r.response,!i){e.next=12;break}throw new f.a(i,{showRefresh:!0,showBack:!0});case 12:if(!c.error){e.next=14;break}throw new f.a(Object(v.c)("discussion_edit.errors.".concat(c.error)));case 14:return e.abrupt("return",{meta:c.meta,title:c.localizedContentsOfLocale.title});case 15:case"end":return e.stop()}}),e)})))();case 4:return t=e.sent,e.abrupt("return",Object(a.jsx)(k,{problem:t},Object(d.a)()));case 6:case"end":return e.stop()}}),e)})));return function(s){return e.apply(this,arguments)}}()),edit:Object(f.c)(function(){var e=Object(i.a)(n.a.mark((function e(s){var t,r,i;return n.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,j.c.discussion.getDiscussionAndReplies({locale:m.a.locale,discussionId:Number(s.params.id)||0,getDiscussion:!0});case 2:if(t=e.sent,r=t.requestError,i=t.response,!r){e.next=9;break}throw new f.a(r,{showRefresh:!0,showBack:!0});case 9:if(!i.error){e.next=11;break}throw new f.a(Object(v.c)("discussion_edit.errors.".concat(i.error)));case 11:return e.abrupt("return",Object(a.jsx)(k,{discussion:i.discussion},Object(d.a)()));case 12:case"end":return e.stop()}}),e)})));return function(s){return e.apply(this,arguments)}}())}}}]);
//# sourceMappingURL=100.f544c7b0.chunk.js.map