text: (self.webpackChunkfavoriteblogs_fe=self.webpackChunkfavoriteblogs_fe||[]).push([[970],{970:function(e,t,r){"use strict";r.r(t),r.d(t,{default:function(){return P}});var n=r(2137),o=r(7757),u=r.n(o),a=r(7294),c=r(5697),s=r(4494),i=r(332),p=r(1798),l=r(6156),f=r(9453);function g(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}var m=function(e){var t=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?g(Object(r),!0).forEach((function(t){(0,l.Z)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):g(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},e),r=t.handleLogin,n=t.username,o=t.password;return(0,a.useEffect)((function(){document.querySelector("input").focus()}),[]),a.createElement(a.Fragment,null,a.createElement("h2",null,"Login"),a.createElement(f.Z,{onSubmit:r,className:"login-form"},a.createElement(f.Z.Group,null,a.createElement(f.Z.Input,{required:!0,label:"Username",id:"username",name:n.name,type:n.type,value:n.value,onChange:n.onChange})),a.createElement(f.Z.Group,null,a.createElement(f.Z.Input,{required:!0,label:"Password",id:"password",name:o.name,type:o.type,value:o.value,onChange:o.onChange})),a.createElement(f.Z.Button,{type:"submit"},"Login")))};m.propTypes={handleLogin:c.PropTypes.func.isRequired,username:c.PropTypes.object.isRequired,password:c.PropTypes.object.isRequired};var b=m,y=r(8999),v="".concat("https://favoriteblogs.herokuapp.com","/api/login"),d={login:function(){var e=(0,n.Z)(u().mark((function e(t){var r,n;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=(0,y.qu)(v,t),e.next=3,fetch(r);case 3:return n=e.sent,e.next=6,(0,y.UI)(n);case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()},O=r(2086),h=r(1479),w=function(e){var t=(0,O.U)("text","username"),r=(0,O.U)("password","password"),o=e.setToken,c=e.setUser,s=e.setNotification,i=function(){var e=(0,n.Z)(u().mark((function e(n){var a;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n.preventDefault(),e.prev=1,e.next=4,d.login((0,h.gU)(t,r));case 4:a=e.sent,window.localStorage.setItem("loggedBlogAppUser",JSON.stringify(a)),o(a.token),c(a),window.location.href=window.location.origin,e.next=16;break;case 11:e.prev=11,e.t0=e.catch(1),t.setValue(""),r.setValue(""),s({error:"Login failed: ".concat(e.t0.message)});case 16:case"end":return e.stop()}}),e,null,[[1,11]])})));return function(t){return e.apply(this,arguments)}}();return a.createElement(a.Fragment,null,a.createElement("main",null,a.createElement("div",{className:"card"},a.createElement(b,{handleLogin:i,username:t,password:r}))))},j={setNotification:i.s,setToken:p.o4,setUser:p.av};w.propTypes={setToken:c.PropTypes.func.isRequired,setUser:c.PropTypes.func.isRequired,setNotification:c.PropTypes.func.isRequired};var P=(0,s.$j)(null,j)(w)},2086:function(e,t,r){"use strict";r.d(t,{U:function(){return u}});var n=r(3391),o=r(7294),u=function(e,t){var r=(0,o.useState)(""),u=(0,n.Z)(r,2),a=u[0],c=u[1];return{name:t,type:e,value:a,onChange:function(e){c(e.target.value)},setValue:c}}},1479:function(e,t,r){"use strict";r.d(t,{Cz:function(){return a},gU:function(){return c},ww:function(){return s},R$:function(){return i},CV:function(){return p}});var n=r(6156);function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function u(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){(0,n.Z)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var a=function(e,t){return e.filter((function(e){return e.user.username===t.username}))},c=function(){for(var e={},t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return r.forEach((function(t){e[t.name]=t.value})),e},s=function(e){return!!("http://"===e.substring(0,7)|"https://"===e.substring(0,8))},i=function(e,t){return e.map((function(e){var r=t.filter((function(t){return t.user.id===e.id}));return u(u({},e),{},{blogs:r})}))},p=function(e){return 0===Object.keys(e).length}}}]);