{"size": 4347, "ext": "js", "max_stars_repo_path": "build/static/js/main.88669226.chunk.js", "max_stars_repo_name": "fleuronvilik/cart-use-reducer", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "build/static/js/main.88669226.chunk.js", "max_issues_repo_name": "fleuronvilik/cart-use-reducer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "build/static/js/main.88669226.chunk.js", "max_forks_repo_name": "fleuronvilik/cart-use-reducer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 2173.5, "max_line_length": 4299, "alphanum_fraction": 0.6928916494}
(this.webpackJsonpreminder=this.webpackJsonpreminder||[]).push([[0],{10:function(e,t,a){"use strict";a.r(t);var n=a(0),r=a.n(n),c=a(3),l=a.n(c),m=(a(9),a(1));function u(e,t){if("REMOVE_ITEM"===t.type)return e.filter((function(e){return e.id!==t.itemId}));if("INCREASE"===t.type)return e.map((function(e){return e.id===t.itemId&&(e.amount=t.amount),e}));if("DECREASE"===t.type)return e.map((function(e){return e.id===t.itemId&&(e.amount=t.amount),e}));if("CLEAR"===t.type)return[];if("INIT"===t.type)return t.data;throw new Error("no matching type")}var o=r.a.createContext(),i=function(e){var t=e.children,a=Object(n.useReducer)(u,[]),c=Object(m.a)(a,2),l=c[0],i=c[1],s=Object(n.useState)(0),E=Object(m.a)(s,2),d=E[0],p=E[1],h=Object(n.useState)(0),v=Object(m.a)(h,2),f=v[0],b=v[1],g=Object(n.useState)(!0),N=Object(m.a)(g,2),w=N[0],y=N[1];return Object(n.useEffect)((function(){fetch("https://course-api.com/react-useReducer-cart-project").then((function(e){return e.json()})).then((function(e){i({type:"INIT",data:e}),p(e.length),b(e.reduce((function(e,t){return e+Number(t.price)}),0)),y(!1)}))}),[]),r.a.createElement(o.Provider,{value:{cart:l,count:d,setCount:p,dispatch:i,total:f,setTotal:b,loading:w,setLoading:y}},t)},s=function(){return Object(n.useContext)(o)},E=function(){var e=s().count;return r.a.createElement("nav",null,r.a.createElement("div",{className:"nav-center"},r.a.createElement("h3",null,"useReducer"),r.a.createElement("div",{className:"nav-container"},r.a.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20"},r.a.createElement("path",{d:"M16 6v2h2l2 12H0L2 8h2V6a6 6 0 1 1 12 0zm-2 0a4 4 0 1 0-8 0v2h8V6zM4 10v2h2v-2H4zm10 0v2h2v-2h-2z"})),r.a.createElement("div",{className:"amount-container"},r.a.createElement("p",{className:"total-amount"},e)))))},d=function(e){var t=e.id,a=e.img,n=e.title,c=e.price,l=e.amount,m=s(),u=m.dispatch,o=m.count,i=m.setCount,E=m.total,d=m.setTotal;return c=Number(c),r.a.createElement("article",{className:"cart-item"},r.a.createElement("img",{src:a,alt:n}),r.a.createElement("div",null,r.a.createElement("h4",null,n),r.a.createElement("h4",{className:"item-price"},"$",c),r.a.createElement("button",{className:"remove-btn",onClick:function(){u({type:"REMOVE_ITEM",itemId:t}),i(o-l),d(E-l*c)}},"remove")),r.a.createElement("div",null,r.a.createElement("button",{className:"amount-btn",onClick:function(){u({type:"INCREASE",itemId:t,amount:++l}),i(o+1),d(E+c)}},r.a.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20"},r.a.createElement("path",{d:"M10.707 7.05L10 6.343 4.343 12l1.414 1.414L10 9.172l4.243 4.242L15.657 12z"}))),r.a.createElement("p",{className:"amount"},l),r.a.createElement("button",{className:"amount-btn",onClick:function(){if(l>1)return u({type:"DECREASE",itemId:t,amount:--l}),i(o-1),void d(E-c);u({type:"REMOVE_ITEM",itemId:t}),i(o-1),d(E-c)}},r.a.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20"},r.a.createElement("path",{d:"M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"})))))},p=function(){var e=s(),t=e.cart,a=e.dispatch,n=e.setCount,c=e.total;return 0===t.length?r.a.createElement("section",{className:"cart"},r.a.createElement("header",null,r.a.createElement("h2",null,"your bag"),r.a.createElement("h4",{className:"empty-cart"},"is currently empty"))):r.a.createElement("section",{className:"cart"},r.a.createElement("header",null,r.a.createElement("h2",null,"your bag")),r.a.createElement("div",null,t.map((function(e){return r.a.createElement(d,Object.assign({key:e.id},e))}))),r.a.createElement("footer",null,r.a.createElement("hr",null),r.a.createElement("div",{className:"cart-total"},r.a.createElement("h4",null,"total ",r.a.createElement("span",null,"$",c.toFixed(2)))),r.a.createElement("button",{className:"btn clear-btn",onClick:function(){a({type:"CLEAR"}),n(0)}},"clear cart")))};var h=function(){return s().loading?r.a.createElement("div",{className:"loading"},r.a.createElement("h1",null,"Loading...")):r.a.createElement("main",null,r.a.createElement(E,null),r.a.createElement(p,null))};l.a.render(r.a.createElement(r.a.StrictMode,null,r.a.createElement(i,null,r.a.createElement(h,null))),document.getElementById("root"))},4:function(e,t,a){e.exports=a(10)},9:function(e,t,a){}},[[4,1,2]]]);
//# sourceMappingURL=main.88669226.chunk.js.map