text: (window.webpackJsonp=window.webpackJsonp||[]).push([[3],{1:function(e,t,n){"use strict";n.d(t,"g",function(){return r}),n.d(t,"q",function(){return a}),n.d(t,"k",function(){return c}),n.d(t,"l",function(){return o}),n.d(t,"j",function(){return u}),n.d(t,"n",function(){return s}),n.d(t,"p",function(){return i}),n.d(t,"o",function(){return l}),n.d(t,"i",function(){return p}),n.d(t,"h",function(){return d}),n.d(t,"r",function(){return m}),n.d(t,"u",function(){return f}),n.d(t,"m",function(){return E}),n.d(t,"b",function(){return v}),n.d(t,"c",function(){return h}),n.d(t,"a",function(){return b}),n.d(t,"s",function(){return y}),n.d(t,"e",function(){return O}),n.d(t,"f",function(){return g}),n.d(t,"d",function(){return j}),n.d(t,"t",function(){return A});var r="APP_LOAD",a="REDIRECT",c="HOME_PAGE_LOADED",o="HOME_PAGE_UNLOADED",u="CHANGE_TAB",s="LOGIN",i="LOGOUT",l="LOGIN_PAGE_UNLOADED",p="ASYNC_START",d="ASYNC_END",m="UPDATE_FIELD_AUTH",f="VESSEL_PAGE_LOADED",E="LOAD_CERTIFICATES",v="ADD_CERTIFICATE_PAGE_LOADED",h="ADD_CERTIFICATE_PAGE_UNLOADED",b="ADD_CERTIFICATE",y="UPDATE_FIELD_CERTIFICATE",O="ADD_VESSEL_PAGE_LOADED",g="ADD_VESSEL_PAGE_UNLOADED",j="ADD_VESSEL",A="UPDATE_FIELD_VESSEL"},15:function(e,t,n){"use strict";(function(e){var r=n(35),a=n.n(r),c=n(36),o=n.n(c),u=a()(o.a,e.Promise),s="https://captain.moovelogic.com/api",i="https://captain.moovelogic.com/api",l=function(e){return e.body},p=null,d=function(e){p&&e.set("Authorization","Bearer ".concat(p))},m=function(e){return u.get("".concat(s).concat(e)).use(d).then(l)},f=function(e,t){return u.put("".concat(s).concat(e),t).use(d).then(l)},E=function(e,t){return u.post("".concat(s).concat(e),t).use(d).then(l)},v=function(e){return u.get("".concat(i).concat(e)).use(d).then(l)},h={current:function(){return m("/v1/user")},login:function(e){return E("/v1/auth",{token:e})},register:function(e,t,n){return E("/users",{user:{username:e,email:t,password:n}})},save:function(e){return f("/user",{user:e})}},b={all:function(){return v("/vessels")},get:function(e){return v("/vessels/".concat(e))},save:function(e){return E("/vessels",e)}},y={byVessel:function(e){return v("/vessels/".concat(e,"/certificates"))},save:function(e){return E("/vessels/".concat(e.vessel_id,"/certificates"),e)}};t.a={Auth:h,Vessels:b,Certificates:y,setToken:function(e){p=e}}}).call(this,n(17))},38:function(e,t,n){e.exports=n(58)},58:function(e,t,n){"use strict";n.r(t);var r=n(25),a=n.n(r),c=n(14),o=n(0),u=n.n(o),s=n(12),i=(n(47),n(34)),l=n(15),p=n(1),d=function(e){return function(t){return function(n){if((c=n.payload)&&"function"===typeof c.then){e.dispatch({type:p.i,subtype:n.type});var r=e.getState().viewChangeCounter,a=n.skipTracking;n.payload.then(function(t){var c=e.getState();(a||c.viewChangeCounter===r)&&(console.log("RESULT",t),n.payload=t,e.dispatch({type:p.h,promise:n.payload}),e.dispatch(n))},function(t){var c=e.getState();(a||c.viewChangeCounter===r)&&(console.log("ERROR",t),n.error=!0,n.payload=t.response.body,n.skipTracking||e.dispatch({type:p.h,promise:n.payload}),e.dispatch(n))})}else{var c;t(n)}}}},m=function(e){return function(e){return function(t){t.type===p.n?t.error||(window.localStorage.setItem("jwt",t.payload.user.token),l.a.setToken(t.payload.user.token)):t.type===p.p&&(window.localStorage.setItem("jwt",""),l.a.setToken(null)),e(t)}}};var f,E=n(4),v={appName:"Captain",token:null},h=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:v,t=arguments.length>1?arguments[1]:void 0;switch(t.type){case p.g:return Object(E.a)({},e,{token:t.token||null,appLoaded:!0,currentUser:t.payload?t.payload.user:null,redirectTo:t.token?null:"/login"});case p.q:return Object(E.a)({},e,{redirectTo:null});case p.n:return Object(E.a)({},e,{redirectTo:t.error?null:"/",token:t.error?null:t.payload.user.token,currentUser:t.error?null:t.payload.user});case p.k:return Object(E.a)({},e,{vessels:t.payload[0]});case p.a||p.d:return Object(E.a)({},e,{redirectTo:t.error?null:"/"});case p.p:return Object(E.a)({},e,{redirectTo:"/",token:null,currentUser:null});default:return e}},b=n(13),y={password:""},O=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:y,t=arguments.length>1?arguments[1]:void 0;switch(t.type){case p.o:return{};case p.n:return Object(E.a)({},e,{inProgress:!1,errors:t.error?t.payload.errors:null});case p.i:if(t.subtype===p.n)return Object(E.a)({},e,{inProgress:!0});break;case p.r:return Object(E.a)({},e,Object(b.a)({},t.key,t.value));default:return e}return e},g=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;switch(t.type){case p.m:return Object(E.a)({},e,{vessel:t.payload[0],certificates:t.payload[1]});case p.l:return{};default:return e}},j=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;switch(t.type){case p.u:return Object(E.a)({},e);case p.t:return Object(E.a)({},e,Object(b.a)({},t.key,t.value));case p.d:return{inProgress:!1,errors:t.error?t.payload.errors:null};case p.i:return t.subtype===p.d?Object(E.a)({},e,{inProgress:!0}):e;case p.f:return{};default:return e}},A=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(arguments.length>1?arguments[1]:void 0).type,e},D={},k=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:D,t=arguments.length>1?arguments[1]:void 0;switch(t.type){case p.b:return Object(E.a)({},e,{vessels:t.payload[0]});case p.s:return Object(E.a)({},e,Object(b.a)({},t.key,t.value));case p.a:return{inProgress:!1,errors:t.error?t.payload.errors:null};case p.i:return t.subtype===p.a?Object(E.a)({},e,{inProgress:!0}):e;case p.c:return{};default:return e}},T=n(16),N=n(32),_=n(8),L=Object(_.a)(),U=Object(N.a)(L),w=Object(s.createStore)((f=L,Object(s.combineReducers)({common:h,auth:O,home:g,vessel:j,vessels:A,certificate:k,router:Object(T.b)(f)})),Object(i.composeWithDevTools)(Object(s.applyMiddleware)(U,d,m))),C=n(9),S=n(20),P=n(21),I=n(23),R=n(22),G=n(24),F=n(11),V=u.a.memo(function(e){return e.currentUser?null:u.a.createElement("ul",{className:"nav navbar-nav pull-xs-right"},u.a.createElement("li",{className:"nav-item"},u.a.createElement(F.a,{to:"/",className:"nav-link"},"Home")),u.a.createElement("li",{className:"nav-item"},u.a.createElement(F.a,{to:"/login",className:"nav-link"},"Sign in")))}),z=u.a.memo(function(e){return e.currentUser?u.a.createElement("ul",{className:"nav navbar-nav pull-xs-right"},u.a.createElement("li",{className:"nav-item"},u.a.createElement(F.a,{to:"/",className:"nav-link"},"Home")),u.a.createElement("li",{className:"nav-item"},u.a.createElement(F.a,{to:"/certificate/add",className:"nav-link"},u.a.createElement("i",{className:"ion-gear-a"}),"\xa0Add Certificate")),u.a.createElement("li",{className:"nav-item"},u.a.createElement(F.a,{to:"/vessel/add",className:"nav-link"},u.a.createElement("i",{className:"ion-gear-a"}),"\xa0Add Vessel")),u.a.createElement("li",{className:"nav-item"},u.a.createElement(F.a,{to:"/@".concat(e.currentUser.username),className:"nav-link"},u.a.createElement("img",{src:e.currentUser.image,className:"user-pic",alt:e.currentUser.username}),"Welcome, ",e.currentUser.display_name))):null}),H=function(e){function t(){return Object(S.a)(this,t),Object(I.a)(this,Object(R.a)(t).apply(this,arguments))}return Object(G.a)(t,e),Object(P.a)(t,[{key:"render",value:function(){return u.a.createElement("nav",{className:"navbar navbar-light"},u.a.createElement("div",{className:"container"},u.a.createElement(F.a,{to:"/",className:"navbar-brand"},this.props.appName.toLowerCase()),u.a.createElement(V,{currentUser:this.props.currentUser}),u.a.createElement(z,{currentUser:this.props.currentUser})))}}]),t}(u.a.PureComponent),x=n(5),M=Object(o.lazy)(function(){return n.e(0).then(n.bind(null,63))}),q=Object(o.lazy)(function(){return n.e(1).then(n.bind(null,64))}),B=Object(o.lazy)(function(){return n.e(2).then(n.bind(null,65))}),J=Object(o.lazy)(function(){return n.e(2).then(n.bind(null,66))}),W=Object(o.lazy)(function(){return n.e(6).then(n.bind(null,67))}),Y=function(e){function t(){return Object(S.a)(this,t),Object(I.a)(this,Object(R.a)(t).apply(this,arguments))}return Object(G.a)(t,e),Object(P.a)(t,[{key:"componentDidUpdate",value:function(e){this.props.redirectTo&&this.props.redirectTo!==e.redirectTo&&(w.dispatch(Object(x.d)(this.props.redirectTo)),this.props.onRedirect())}},{key:"componentDidMount",value:function(){var e=window.localStorage.getItem("jwt");e&&l.a.setToken(e),this.props.onLoad(e?l.a.Auth.current():null,e)}},{key:"render",value:function(){return this.props.appLoaded?u.a.createElement("div",null,u.a.createElement(H,{appName:this.props.appName,currentUser:this.props.currentUser}),u.a.createElement(o.Suspense,{fallback:u.a.createElement("p",null,"Loading...")},u.a.createElement(C.c,null,u.a.createElement(C.a,{exact:!0,path:"/",component:M}),u.a.createElement(C.a,{path:"/login",component:q}),u.a.createElement(C.a,{path:"/vessel",component:B}),u.a.createElement(C.a,{path:"/vessel/:id",component:J}),u.a.createElement(C.a,{path:"/certificate/add",component:W})))):u.a.createElement("div",null,u.a.createElement(H,{appName:this.props.appName,currentUser:this.props.currentUser}))}}]),t}(u.a.PureComponent),K=Object(c.c)(function(e){return{appLoaded:e.common.appLoaded,appName:e.common.appName,currentUser:e.common.currentUser,redirectTo:e.common.redirectTo}},function(e){return{onLoad:function(t,n){return e({type:p.g,payload:t,token:n,skipTracking:!0})},onRedirect:function(){return e({type:p.q})}}})(Y);a.a.render(u.a.createElement(c.a,{store:w},u.a.createElement(T.a,{history:L},u.a.createElement(C.c,null,u.a.createElement(C.a,{path:"/",component:K})))),document.getElementById("root"))}},[[38,4,5]],[1,2]]);
  //# sourceMappingURL=main.a5789d06.chunk.js.map