(window.webpackJsonp=window.webpackJsonp||[]).push([[0],{169:function(e,t,a){e.exports=a(439)},174:function(e,t,a){},373:function(e,t,a){},408:function(e,t,a){},411:function(e,t,a){},413:function(e,t,a){},415:function(e,t,a){},417:function(e,t,a){},419:function(e,t,a){},421:function(e,t,a){},439:function(e,t,a){"use strict";a.r(t);var n=a(0),r=a.n(n),s=a(57),i=a.n(s),o=(a(174),a(13)),c=a.n(o),l=a(9),u=a.n(l),h=a(15),m=a(29),p=a(30),d=a(32),f=a(31),g=a(33),v=a(52),b=a(449),E=a(447),w=a(448),y=a(90),x=a(162),k=a(161),S=a(91),O=a(40),C=function(e){var t=e.component,a=e.props,n=Object(O.a)(e,["component","props"]);return r.a.createElement(S.a,Object.assign({},n,{render:function(e){return r.a.createElement(t,Object.assign({},e,a))}}))},L=a(160),j=function(e){var t=e.component,a=e.props,n=Object(O.a)(e,["component","props"]);return r.a.createElement(S.a,Object.assign({},n,{render:function(e){return a.isAuthenticated?r.a.createElement(t,Object.assign({},e,a)):r.a.createElement(L.a,{to:"/login?redirect=".concat(e.location.pathname).concat(e.location.search)})}}))};var A=function(e){var t=e.component,a=e.props,n=Object(O.a)(e,["component","props"]),s=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window.location.href;e=e.replace(/[[]]/g,"\\$&");var a=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)","i").exec(t);return a?a[2]?decodeURIComponent(a[2].replace(/\+/g," ")):"":null}("redirect");return r.a.createElement(S.a,Object.assign({},n,{render:function(e){return a.isAuthenticated?r.a.createElement(L.a,{to:""===s||null===s?"/":s}):r.a.createElement(t,Object.assign({},e,a))}}))},I=a(375),N=a(441),T=a(442),P=(a(373),function(e){function t(e){var a;return Object(m.a)(this,t),(a=Object(d.a)(this,Object(f.a)(t).call(this,e))).state={isLoading:!0,notes:[]},a}return Object(g.a)(t,e),Object(p.a)(t,[{key:"componentDidMount",value:function(){var e=Object(h.a)(u.a.mark(function e(){var t;return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.props.isAuthenticated){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,e.next=5,this.notes();case 5:t=e.sent,this.setState({notes:t}),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(2),alert(e.t0);case 12:this.setState({isLoading:!1});case 13:case"end":return e.stop()}},e,this,[[2,9]])}));return function(){return e.apply(this,arguments)}}()},{key:"notes",value:function(){return o.API.get("notes","/notes")}},{key:"renderNotesList",value:function(e){return[{}].concat(e).map(function(e,t){return 0!==t?r.a.createElement(v.LinkContainer,{key:e.noteId,to:"/notes/".concat(e.noteId)},r.a.createElement(I.a,{header:e.content.trim().split("\n")[0]},"Created: "+new Date(e.createdAt).toLocaleString())):r.a.createElement(v.LinkContainer,{key:"new",to:"/notes/new"},r.a.createElement(I.a,null,r.a.createElement("h4",null,r.a.createElement("b",null,"\uff0b")," Create a new note")))})}},{key:"renderLander",value:function(){return r.a.createElement("div",{className:"lander"},r.a.createElement("h1",null,"Scratch"),r.a.createElement("p",null,"A simple note taking app"),r.a.createElement("div",null,r.a.createElement(y.a,{to:"/login",className:"btn btn-info btn-lg"},"Login"),r.a.createElement(y.a,{to:"/signup",className:"btn btn-success btn-lg"},"Signup")))}},{key:"renderNotes",value:function(){return r.a.createElement("div",{className:"notes"},r.a.createElement(N.a,null,"Your Notes"),r.a.createElement(T.a,null,!this.state.isLoading&&this.renderNotesList(this.state.notes)))}},{key:"render",value:function(){return r.a.createElement("div",{className:"Home"},this.props.isAuthenticated?this.renderNotes():this.renderLander())}}]),t}(n.Component)),D=a(39),_=a(444),F=a(445),U=a(450),z=a(443),R=a(410),M=(a(408),function(e){var t=e.isLoading,a=e.text,n=e.loadingText,s=e.className,i=void 0===s?"":s,o=e.disabled,c=void 0!==o&&o,l=Object(O.a)(e,["isLoading","text","loadingText","className","disabled"]);return r.a.createElement(z.a,Object.assign({className:"LoaderButton ".concat(i),disabled:c||t},l),t&&r.a.createElement(R.a,{glyph:"refresh",className:"spinning"}),t?n:a)}),H=(a(411),function(e){function t(e){var a;return Object(m.a)(this,t),(a=Object(d.a)(this,Object(f.a)(t).call(this,e))).handleChange=function(e){a.setState(Object(D.a)({},e.target.id,e.target.value))},a.handleSubmit=function(){var e=Object(h.a)(u.a.mark(function e(t){var n;return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t.preventDefault(),a.setState({isLoading:!0}),n=a.state.email.toLowerCase(),e.prev=3,e.next=6,o.Auth.signIn(n,a.state.password);case 6:a.props.userHasAuthenticated(!0),e.next=13;break;case 9:e.prev=9,e.t0=e.catch(3),"UserNotConfirmedException"===e.t0.name?a.reconfirmUser():alert(e.t0.message),a.setState({isLoading:!1});case 13:case"end":return e.stop()}},e,this,[[3,9]])}));return function(t){return e.apply(this,arguments)}}(),a.reconfirmUser=function(){var e=Object(h.a)(u.a.mark(function e(t){var n,r,s;return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=a.state.email.toLowerCase(),e.prev=1,e.next=4,o.Auth.resendSignUp(n);case 4:r=e.sent,s={pathname:"/signup",state:{isLoading:!1,email:n,password:a.state.password,confirmPassword:a.state.password,confirmationCode:"",newUser:r}},a.props.history.push(s),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(1),alert(e.t0.message);case 12:case"end":return e.stop()}},e,this,[[1,9]])}));return function(t){return e.apply(this,arguments)}}(),a.state={isLoading:!1,email:"",password:""},a}return Object(g.a)(t,e),Object(p.a)(t,[{key:"validateForm",value:function(){return this.state.email.length>0&&this.state.password.length>0}},{key:"render",value:function(){return r.a.createElement("div",{className:"Login"},r.a.createElement("form",{onSubmit:this.handleSubmit},r.a.createElement(_.a,{controlId:"email",bsSize:"large"},r.a.createElement(F.a,null,"Email"),r.a.createElement(U.a,{autoFocus:!0,type:"email",value:this.state.email,onChange:this.handleChange})),r.a.createElement(_.a,{controlId:"password",bsSize:"large"},r.a.createElement(F.a,null,"Password"),r.a.createElement(U.a,{value:this.state.password,onChange:this.handleChange,type:"password"})),r.a.createElement(M,{block:!0,bsSize:"large",disabled:!this.validateForm(),type:"submit",isLoading:this.state.isLoading,text:"Login",loadingText:"Logging in..."})))}}]),t}(n.Component)),G=a(446),B=(a(413),function(e){function t(e){var a;return Object(m.a)(this,t),(a=Object(d.a)(this,Object(f.a)(t).call(this,e))).handleChange=function(e){a.setState(Object(D.a)({},e.target.id,e.target.value))},a.handleSubmit=function(){var e=Object(h.a)(u.a.mark(function e(t){var n,r,s;return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t.preventDefault(),a.setState({isLoading:!0}),n=a.state.email.toLowerCase(),e.prev=3,e.next=6,o.Auth.signUp({username:n,password:a.state.password});case 6:r=e.sent,a.setState({newUser:r}),e.next=20;break;case 10:if(e.prev=10,e.t0=e.catch(3),"UsernameExistsException"!==e.t0.name){e.next=19;break}return e.next=15,o.Auth.resendSignUp(n);case 15:s=e.sent,a.setState({newUser:s}),e.next=20;break;case 19:alert(e.t0.message);case 20:a.setState({isLoading:!1});case 21:case"end":return e.stop()}},e,this,[[3,10]])}));return function(t){return e.apply(this,arguments)}}(),a.handleConfirmationSubmit=function(){var e=Object(h.a)(u.a.mark(function e(t){var n;return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t.preventDefault(),a.setState({isLoading:!0}),n=a.state.email.toLowerCase(),e.prev=3,e.next=6,o.Auth.confirmSignUp(n,a.state.confirmationCode);case 6:return e.next=8,o.Auth.signIn(n,a.state.password);case 8:a.props.userHasAuthenticated(!0),a.props.history.push("/"),e.next=16;break;case 12:e.prev=12,e.t0=e.catch(3),alert(e.t0.message),a.setState({isLoading:!1});case 16:case"end":return e.stop()}},e,this,[[3,12]])}));return function(t){return e.apply(this,arguments)}}(),void 0!==e.history.location.state?a.state=e.history.location.state:a.state={isLoading:!1,email:"",password:"",confirmPassword:"",confirmationCode:"",newUser:null},a}return Object(g.a)(t,e),Object(p.a)(t,[{key:"validateForm",value:function(){return this.state.email.length>0&&this.state.password.length>0&&this.state.password===this.state.confirmPassword}},{key:"validateConfirmationForm",value:function(){return this.state.confirmationCode.length>0}},{key:"renderConfirmationForm",value:function(){return r.a.createElement("form",{onSubmit:this.handleConfirmationSubmit},r.a.createElement(_.a,{controlId:"confirmationCode",bsSize:"large"},r.a.createElement(F.a,null,"Confirmation Code"),r.a.createElement(U.a,{autoFocus:!0,type:"tel",value:this.state.confirmationCode,onChange:this.handleChange}),r.a.createElement(G.a,null,"Please check your email for the code.")),r.a.createElement(M,{block:!0,bsSize:"large",disabled:!this.validateConfirmationForm(),type:"submit",isLoading:this.state.isLoading,text:"Verify",loadingText:"Verifying\u2026"}))}},{key:"renderForm",value:function(){return r.a.createElement("form",{onSubmit:this.handleSubmit},r.a.createElement(_.a,{controlId:"email",bsSize:"large"},r.a.createElement(F.a,null,"Email"),r.a.createElement(U.a,{autoFocus:!0,type:"email",value:this.state.email,onChange:this.handleChange})),r.a.createElement(_.a,{controlId:"password",bsSize:"large"},r.a.createElement(F.a,null,"Password"),r.a.createElement(U.a,{value:this.state.password,onChange:this.handleChange,type:"password"})),r.a.createElement(_.a,{controlId:"confirmPassword",bsSize:"large"},r.a.createElement(F.a,null,"Confirm Password"),r.a.createElement(U.a,{value:this.state.confirmPassword,onChange:this.handleChange,type:"password"})),r.a.createElement(M,{block:!0,bsSize:"large",disabled:!this.validateForm(),type:"submit",isLoading:this.state.isLoading,text:"Signup",loadingText:"Signing up\u2026"}))}},{key:"render",value:function(){return r.a.createElement("div",{className:"Signup"},null===this.state.newUser?this.renderForm():this.renderConfirmationForm())}}]),t}(n.Component));function X(e){return Z.apply(this,arguments)}function Z(){return(Z=Object(h.a)(u.a.mark(function e(t){var a,n;return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return a="".concat(Date.now(),"-").concat(t.name),e.next=3,o.Storage.vault.put(a,t,{contentType:t.type});case 3:return n=e.sent,e.abrupt("return",n.key);case 5:case"end":return e.stop()}},e,this)}))).apply(this,arguments)}function Y(e){return W.apply(this,arguments)}function W(){return(W=Object(h.a)(u.a.mark(function e(t){return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o.Storage.vault.remove(t);case 2:case"end":return e.stop()}},e,this)}))).apply(this,arguments)}var $={MAX_ATTACHMENT_SIZE:5e6,s3:{REGION:"us-west-2",BUCKET:"jnog-notes-app-uploads"},apiGateway:{REGION:"us-west-2",URL:"https://7zzcz33s06.execute-api.us-west-2.amazonaws.com/prod"},cognito:{REGION:"us-west-2",USER_POOL_ID:"us-west-2_mOg1Xjfxf",APP_CLIENT_ID:"3hl1ujg6u1lonslgfhmm1l4v8h",IDENTITY_POOL_ID:"us-west-2:80a850d2-3d90-4258-a779-94608ce7f938"}},J=(a(415),function(e){function t(e){var a;return Object(m.a)(this,t),(a=Object(d.a)(this,Object(f.a)(t).call(this,e))).handleChange=function(e){a.setState(Object(D.a)({},e.target.id,e.target.value))},a.handleFileChange=function(e){a.file=e.target.files[0]},a.handleSubmit=function(){var e=Object(h.a)(u.a.mark(function e(t){var n;return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t.preventDefault(),!(a.file&&a.file.size>$.MAX_ATTACHMENT_SIZE)){e.next=4;break}return alert("Please pick a file smaller than ".concat($.MAX_ATTACHMENT_SIZE/1e6," MB.")),e.abrupt("return");case 4:if(a.setState({isLoading:!0}),e.prev=5,!a.file){e.next=12;break}return e.next=9,X(a.file);case 9:e.t0=e.sent,e.next=13;break;case 12:e.t0=null;case 13:return n=e.t0,e.next=16,a.createNote({attachment:n,content:a.state.content});case 16:a.props.history.push("/"),e.next=23;break;case 19:e.prev=19,e.t1=e.catch(5),alert(e.t1),a.setState({isLoading:!1});case 23:case"end":return e.stop()}},e,this,[[5,19]])}));return function(t){return e.apply(this,arguments)}}(),a.file=null,a.state={isLoading:null,content:""},a}return Object(g.a)(t,e),Object(p.a)(t,[{key:"validateForm",value:function(){return this.state.content.length>0}},{key:"createNote",value:function(e){return o.API.post("notes","/notes",{body:e})}},{key:"render",value:function(){return r.a.createElement("div",{className:"NewNote"},r.a.createElement("form",{onSubmit:this.handleSubmit},r.a.createElement(_.a,{controlId:"content"},r.a.createElement(U.a,{onChange:this.handleChange,value:this.state.content,componentClass:"textarea"})),r.a.createElement(_.a,{controlId:"file"},r.a.createElement(F.a,null,"Attachment"),r.a.createElement(U.a,{onChange:this.handleFileChange,type:"file"})),r.a.createElement(M,{block:!0,bsStyle:"primary",bsSize:"large",disabled:!this.validateForm(),type:"submit",isLoading:this.state.isLoading,text:"Create",loadingText:"Creating\u2026"})))}}]),t}(n.Component)),K=(a(417),function(e){function t(e){var a;return Object(m.a)(this,t),(a=Object(d.a)(this,Object(f.a)(t).call(this,e))).handleChange=function(e){a.setState(Object(D.a)({},e.target.id,e.target.value))},a.handleFileChange=function(e){a.file=e.target.files[0]},a.handleSubmit=function(){var e=Object(h.a)(u.a.mark(function e(t){var n;return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t.preventDefault(),!(a.file&&a.file.size>$.MAX_ATTACHMENT_SIZE)){e.next=4;break}return alert("Please pick a file smaller than ".concat($.MAX_ATTACHMENT_SIZE/1e6," MB.")),e.abrupt("return");case 4:if(a.setState({isLoading:!0}),e.prev=5,!a.file){e.next=12;break}return e.next=9,a.deleteExistingAttachment();case 9:return e.next=11,X(a.file);case 11:n=e.sent;case 12:return e.next=14,a.saveNote({content:a.state.content,attachment:n||a.state.note.attachment});case 14:a.props.history.push("/"),e.next=21;break;case 17:e.prev=17,e.t0=e.catch(5),alert(e.t0),a.setState({isLoading:!1});case 21:case"end":return e.stop()}},e,this,[[5,17]])}));return function(t){return e.apply(this,arguments)}}(),a.handleDelete=function(){var e=Object(h.a)(u.a.mark(function e(t){return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t.preventDefault(),window.confirm("Are you sure you want to delete this note?")){e.next=4;break}return e.abrupt("return");case 4:return a.setState({isDeleting:!0}),e.prev=5,e.next=8,a.deleteExistingAttachment();case 8:return e.next=10,a.deleteNote();case 10:a.props.history.push("/"),e.next=17;break;case 13:e.prev=13,e.t0=e.catch(5),alert(e.t0),a.setState({isDeleting:!1});case 17:case"end":return e.stop()}},e,this,[[5,13]])}));return function(t){return e.apply(this,arguments)}}(),a.file=null,a.state={isLoading:null,isDeleting:null,note:null,content:"",attachmentURL:null},a}return Object(g.a)(t,e),Object(p.a)(t,[{key:"componentDidMount",value:function(){var e=Object(h.a)(u.a.mark(function e(){var t,a,n,r;return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.getNote();case 3:if(a=e.sent,n=a.content,!(r=a.attachment)){e.next=9;break}return e.next=8,o.Storage.vault.get(r);case 8:t=e.sent;case 9:this.setState({note:a,content:n,attachmentURL:t}),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(0),alert(e.t0);case 15:case"end":return e.stop()}},e,this,[[0,12]])}));return function(){return e.apply(this,arguments)}}()},{key:"getNote",value:function(){return o.API.get("notes","/notes/".concat(this.props.match.params.id))}},{key:"validateForm",value:function(){return this.state.content.length>0}},{key:"formatFilename",value:function(e){return e.replace(/^\w+-/,"")}},{key:"deleteExistingAttachment",value:function(){var e=Object(h.a)(u.a.mark(function e(){var t;return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getNote();case 2:(t=e.sent).attachment&&Y(t.attachment);case 4:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"saveNote",value:function(e){return o.API.put("notes","/notes/".concat(this.props.match.params.id),{body:e})}},{key:"deleteNote",value:function(){return o.API.del("notes","/notes/".concat(this.props.match.params.id))}},{key:"render",value:function(){return r.a.createElement("div",{className:"Notes"},this.state.note&&r.a.createElement("form",{onSubmit:this.handleSubmit},r.a.createElement(_.a,{controlId:"content"},r.a.createElement(U.a,{onChange:this.handleChange,value:this.state.content,componentClass:"textarea"})),this.state.note.attachment&&r.a.createElement(_.a,null,r.a.createElement(F.a,null,"Attachment"),r.a.createElement(U.a.Static,null,r.a.createElement("a",{target:"_blank",rel:"noopener noreferrer",href:this.state.attachmentURL},this.formatFilename(this.state.note.attachment)))),r.a.createElement(_.a,{controlId:"file"},!this.state.note.attachment&&r.a.createElement(F.a,null,"Attachment"),r.a.createElement(U.a,{onChange:this.handleFileChange,type:"file"})),r.a.createElement(M,{block:!0,bsStyle:"primary",bsSize:"large",disabled:!this.validateForm(),type:"submit",isLoading:this.state.isLoading,text:"Save",loadingText:"Saving\u2026"}),r.a.createElement(M,{block:!0,bsStyle:"danger",bsSize:"large",isLoading:this.state.isDeleting,onClick:this.handleDelete,text:"Delete",loadingText:"Deleting\u2026"})))}}]),t}(n.Component)),V=(a(419),function(){return r.a.createElement("div",{className:"NotFound"},r.a.createElement("h3",null,"Sorry, page not found!"))}),q=function(e){var t=e.childProps;return r.a.createElement(k.a,null,r.a.createElement(C,{path:"/",exact:!0,component:P,props:t}),r.a.createElement(A,{path:"/login",exact:!0,component:H,props:t}),r.a.createElement(A,{path:"/signup",exact:!0,component:B,props:t}),r.a.createElement(j,{path:"/notes/new",exact:!0,component:J,props:t}),r.a.createElement(j,{path:"/notes/:id",exact:!0,component:K,props:t}),r.a.createElement(S.a,{component:V}))},Q=(a(421),function(e){function t(e){var a;return Object(m.a)(this,t),(a=Object(d.a)(this,Object(f.a)(t).call(this,e))).userHasAuthenticated=function(e){a.setState({isAuthenticated:e})},a.handleLogout=function(){var e=Object(h.a)(u.a.mark(function e(t){return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o.Auth.signOut();case 2:a.userHasAuthenticated(!1),a.props.history.push("/login");case 4:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),a.state={isAuthenticated:!1,isAuthenticating:!0},a}return Object(g.a)(t,e),Object(p.a)(t,[{key:"componentDidMount",value:function(){var e=Object(h.a)(u.a.mark(function e(){return u.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,o.Auth.currentSession();case 3:this.userHasAuthenticated(!0),e.next=9;break;case 6:e.prev=6,e.t0=e.catch(0),"No current user"!==e.t0&&alert(e.t0);case 9:this.setState({isAuthenticating:!1});case 10:case"end":return e.stop()}},e,this,[[0,6]])}));return function(){return e.apply(this,arguments)}}()},{key:"render",value:function(){var e={isAuthenticated:this.state.isAuthenticated,userHasAuthenticated:this.userHasAuthenticated};return!this.state.isAuthenticating&&r.a.createElement("div",{className:"App container"},r.a.createElement(b.a,{fluid:!0,collapseOnSelect:!0},r.a.createElement(b.a.Header,null,r.a.createElement(b.a.Brand,null,r.a.createElement(y.a,{to:"/"},"Scratch")),r.a.createElement(b.a.Toggle,null)),r.a.createElement(b.a.Collapse,null,r.a.createElement(E.a,{pullRight:!0},this.state.isAuthenticated?r.a.createElement(w.a,{onClick:this.handleLogout},"Logout"):r.a.createElement(n.Fragment,null,r.a.createElement(v.LinkContainer,{to:"/signup"},r.a.createElement(w.a,null,"Signup")),r.a.createElement(v.LinkContainer,{to:"/login"},r.a.createElement(w.a,null,"Login")))))),r.a.createElement(q,{childProps:e}))}}]),t}(n.Component)),ee=Object(x.a)(Q);Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));var te=a(145);c.a.configure({Auth:{mandatorySignIn:!0,region:$.cognito.REGION,userPoolId:$.cognito.USER_POOL_ID,identityPoolId:$.cognito.IDENTITY_POOL_ID,userPoolWebClientId:$.cognito.APP_CLIENT_ID},Storage:{region:$.s3.REGION,bucket:$.s3.BUCKET,identityPoolId:$.cognito.IDENTITY_POOL_ID},API:{endpoints:[{name:"notes",endpoint:$.apiGateway.URL,region:$.apiGateway.REGION}]}}),i.a.render(r.a.createElement(te.a,null,r.a.createElement(ee,null)),document.getElementById("root")),"serviceWorker"in navigator&&navigator.serviceWorker.ready.then(function(e){e.unregister()})},78:function(e,t){}},[[169,2,1]]]); //# sourceMappingURL=main.6e901c75.chunk.js.map