text: (self.webpackChunkfavoriteblogs_fe=self.webpackChunkfavoriteblogs_fe||[]).push([[352],{8352:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return T}});var r=n(2137),l=n(7757),a=n.n(l),u=n(7294),o=n(5697),i=n(4494),c=n(332),s=n(8430),p=n(8004),m=n(9453),d=function(e){var t=e.handleSubmit,n=e.title,r=e.author,l=e.url,a=e.hide;return u.createElement("div",null,u.createElement("h2",null,"Add a new blog"),u.createElement(m.Z,{onSubmit:function(e){t(e),a&&a()}},u.createElement(m.Z.Input,{required:!0,label:"Title",id:"title",type:n.type,name:n.name,value:n.value,onChange:n.onChange}),u.createElement(m.Z.Input,{required:!0,label:"Author",id:"author",type:r.type,name:r.name,value:r.value,onChange:r.onChange}),u.createElement(m.Z.Input,{required:!0,label:"URL",id:"url",type:l.type,name:l.name,value:l.value,onChange:l.onChange}),u.createElement(m.Z.Button,{type:"submit"},"Save")))};d.propTypes={handleSubmit:o.PropTypes.func.isRequired,title:o.PropTypes.object.isRequired,author:o.PropTypes.object.isRequired,url:o.PropTypes.object.isRequired,hide:o.PropTypes.func};var g=d,f=n(3727),b=n(1300),h=n(1479),v=function(e){var t=e.blogs,n=e.login;return u.createElement(u.Fragment,null,u.createElement("h2",null,"Your blogs"),u.createElement("div",null,(0,h.Cz)(t,n).length?u.createElement(b.Z,{striped:!0,celled:!0},u.createElement(b.Z.Body,null,(0,h.Cz)(t,n).sort((function(e,t){return e.likes-t.likes})).map((function(e,t){return u.createElement(b.Z.Row,{key:t},u.createElement(b.Z.Cell,null,u.createElement(f.rU,{to:"/blogs/".concat(e.id)},e.title)))})))):u.createElement("p",null,"You don't have any blogs yet")),u.createElement("h2",null,"All blogs"),t.length?u.createElement(b.Z,{striped:!0,celled:!0},u.createElement(b.Z.Body,null,t.sort((function(e,t){return e.likes-t.likes})).map((function(e,t){return u.createElement(b.Z.Row,{key:t},u.createElement(b.Z.Cell,null,u.createElement(f.rU,{to:"/blogs/".concat(e.id)},e.title)))})))):u.createElement("p",null,"There are no blogs yet"))};v.propTypes={login:o.PropTypes.object.isRequired,blogs:o.PropTypes.array.isRequired};var E=(0,i.$j)((function(e){return{blogs:e.blogs,login:e.login}}),null)(v),y=n(2086),Z=function(e){var t=(0,y.U)("text","title"),n=(0,y.U)("text","author"),l=(0,y.U)("text","url"),o=e.login,i=e.setNotification,c=e.createBlog,s=function(){var e=(0,r.Z)(a().mark((function e(r){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r.preventDefault(),(0,h.ww)(l.value)){e.next=4;break}return i({error:'Please use a valid URL as "https://" or "http://"'}),e.abrupt("return",null);case 4:return e.prev=4,e.next=7,c(o.token,(0,h.gU)(t,n,l));case 7:i({message:'A new blog "'.concat(t.value," by ").concat(n.value,'" added')}),t.setValue(""),n.setValue(""),l.setValue(""),e.next=16;break;case 13:e.prev=13,e.t0=e.catch(4),i({error:"Could not add the blog: ".concat(e.t0.message)});case 16:case"end":return e.stop()}}),e,null,[[4,13]])})));return function(t){return e.apply(this,arguments)}}();return u.createElement(u.Fragment,null,u.createElement("h1",{"aria-live":"polite"},"Blogs"),u.createElement("main",null,u.createElement(E,null),u.createElement(p.Z,{buttonLabel:"New blog"},u.createElement(g,{handleSubmit:s,title:t,author:n,url:l}))))},C={createBlog:s.Vh,setNotification:c.s};Z.propTypes={login:o.PropTypes.object.isRequired,setNotification:o.PropTypes.func.isRequired,createBlog:o.PropTypes.func.isRequired};var T=(0,i.$j)((function(e){return{login:e.login}}),C)(Z)},8004:function(e,t,n){"use strict";var r=n(3391),l=n(7294),a=n(5697),u=n(8237),o=function(e){var t=e.buttonLabel,n=e.children,a=(0,l.useState)(!1),o=(0,r.Z)(a,2),i=o[0],c=o[1],s=function(){return c(!1)},p=l.Children.map(n,(function(e){return l.cloneElement(e,{hide:s})}));return l.createElement("div",null,i?l.createElement(l.Fragment,null,p,l.createElement(u.Z,{onClick:function(){return c(!i)}},"Cancel")):l.createElement(u.Z,{onClick:function(){return c(!i)}},t))};o.propTypes={buttonLabel:a.PropTypes.string.isRequired},t.Z=o},2086:function(e,t,n){"use strict";n.d(t,{U:function(){return a}});var r=n(3391),l=n(7294),a=function(e,t){var n=(0,l.useState)(""),a=(0,r.Z)(n,2),u=a[0],o=a[1];return{name:t,type:e,value:u,onChange:function(e){o(e.target.value)},setValue:o}}}}]);