spoti-search/static/js/main.29d93776.chunk.js

2 lines
5.6 KiB
JavaScript

(this["webpackJsonpspoti-search"]=this["webpackJsonpspoti-search"]||[]).push([[0],{115:function(e,t,a){e.exports=a(131)},131:function(e,t,a){"use strict";a.r(t);var n=a(0),r=a.n(n),i=a(33),l=a.n(i),c=a(58),o=a(59),m=a(89),u=a(56),s=a(52),g=a(92),p=a(144),h=a(93),d=a(78),b=a(90),f=a(145),E=a(146),v=a(147),x=function(){return r.a.createElement(f.a,{as:"header",direction:"row",align:"center",justify:"between",background:"brand",pad:{left:"medium",right:"small",vertical:"small"},style:{zIndex:1}},r.a.createElement(E.a,{margin:{vertical:"small"},color:"light-1",size:"xxlarge",weight:"bold"},"Spoti Search"),r.a.createElement(v.a,{href:"https://github.com/ruihildt/spoti-search",label:"Github",color:"white"}))},w=a(142),y=a(143),j=function(e){var t=e.inputValue,a=e.handleChange,n=e.suggestions,i=e.handleSelect;return r.a.createElement(f.a,{as:"section",direction:"row",justify:"center",margin:{top:"large"}},r.a.createElement(f.a,{as:"div",margin:{vertical:"none"},width:"500px"},r.a.createElement(w.a,{type:"search",name:"q",value:t,suggestions:n,onChange:function(e){return a(e.target.value)},onSelect:function(e){return i(e.suggestion)},icon:r.a.createElement(y.a,{color:"plain"}),dropHeight:"large",placeholder:"Type an artist name",autoFocus:!0,"aria-label":"Search by artist name"})))},O=a(148),k=a(49),S=a.n(k),z=function(e){var t=e.image,a=e.name;return t||(t=S.a),r.a.createElement(f.a,{width:"255px",margin:{right:"20px"}},r.a.createElement(f.a,{height:"255px",width:"255px",background:{repeat:"no-repeat",size:"cover",image:"url(".concat(t,")")}}),r.a.createElement(O.a,{level:"4",margin:{bottom:"small",top:"small",left:"small"}},a))},q=function(e){var t=e.image,a=e.name,n=e.handleClick;return t||(t=S.a),r.a.createElement(f.a,{round:"xxsmall",pad:"xsmall",onClick:function(){return n(a)},width:"130px"},r.a.createElement(f.a,{height:"120px",width:"120px",round:"full",background:{repeat:"no-repeat",size:"cover",image:"url(".concat(t,")")}}),r.a.createElement(E.a,{margin:{bottom:"small",top:"small",left:"small"},textAlign:"center",weight:"bold",wordBreak:"break-word"},a))},C=function(e){var t=e.artists,a=e.handleClick,n=t[0],i=n.name,l=n.image,c=n.albums,o=t.slice(1,t.length),m=[],u=l;l||(u=S.a);var s=new Set;return c.forEach((function(e){s.has(e.name)||(s.add(e.name),m.push(e))})),r.a.createElement(r.a.Fragment,null,r.a.createElement(f.a,{width:"xxlarge",margin:{vertical:"0",horizontal:"auto"}},r.a.createElement(O.a,{level:"1",size:"medium"},i)),r.a.createElement(f.a,{as:"section",direction:"row",width:"xxlarge",margin:{vertical:"0",horizontal:"auto"}},r.a.createElement(f.a,{direction:"column",align:"center",width:{min:"320px",max:"320px"},margin:{top:"0",bottom:"0",left:"20px",right:"80px"}},r.a.createElement(f.a,null,r.a.createElement(f.a,{round:"full",background:{repeat:"no-repeat",size:"cover",image:"url(".concat(u,")")},height:"270px",width:"270px",margin:{top:"0",bottom:"15px",left:"0",right:"0"}})),r.a.createElement(f.a,null,r.a.createElement(O.a,{level:"2",size:"small"},"Other results"),r.a.createElement(f.a,{direction:"row-reverse",justify:"around",wrap:!0},o.map((function(e){return r.a.createElement(q,{key:e.id,image:e.image,name:e.name,handleClick:a})}))))),r.a.createElement(f.a,{direction:"column",width:{min:"320px"},margin:{top:"-52px"}},r.a.createElement(O.a,{level:"2",size:"medium"},"Discography"),r.a.createElement(f.a,{direction:"row",justify:"start",wrap:!0},m.map((function(e){return r.a.createElement(z,{key:e.id,image:e.image,name:e.name})}))))))};function A(){var e=Object(g.a)(["\n\tquery Artist($byName: String!) {\n\t\tqueryArtists(byName: $byName) {\n\t\t\tname\n\t\t\timage\n\t\t\tid\n\t\t\talbums {\n\t\t\t\tname\n\t\t\t\timage\n\t\t\t\tid\n\t\t\t}\n\t\t}\n\t}\n"]);return A=function(){return e},e}var N=Object(d.a)(A());function L(){var e=Object(n.useState)(""),t=Object(s.a)(e,2),a=t[0],i=t[1],l=Object(b.a)(N),c=Object(s.a)(l,2),o=c[0],m=c[1],g=m.data,d=m.error,f=Object(n.useState)([]),E=Object(s.a)(f,2),v=E[0],w=E[1],y=Object(n.useState)([]),O=Object(s.a)(y,2),k=O[0],S=O[1],z=Object(n.useState)(!1),q=Object(s.a)(z,2),A=q[0],L=q[1],B=Object(n.useCallback)(Object(h.debounce)((function(){o({variables:{byName:a}})}),200),[a]);Object(n.useEffect)((function(){return B(),B.cancel}),[a,B]);Object(n.useEffect)((function(){if(g&&g.queryArtists&&g.queryArtists!==[]){var e=g.queryArtists.slice(0,5).map((function(e){return e.name}));S(e)}}),[g]);var F=!1;return d&&d.graphQLErrors&&d.graphQLErrors.forEach((function(e){F="Error: 400: No search query"===e.message})),r.a.createElement(p.a,{theme:Q},r.a.createElement(x,null),r.a.createElement(j,{inputValue:a,suggestions:k,handleChange:function(e){i(e)},handleSelect:function(e){for(var t=[],a=g.queryArtists.slice(0,5).map((function(e){return e})),n=0;n<a.length;n++)if(a[n].name===e){var r=null===a||void 0===a?void 0:a.splice(n,1),i=a;t=[].concat(Object(u.a)(r),Object(u.a)(i));break}w(t),L(!0)}}),A&&r.a.createElement(C,{artists:v,handleClick:function(e){for(var t=[],a=0;a<v.length;a++)if(v[a].name===e){var n=v.splice(a,1),r=v;t=[].concat(Object(u.a)(n),Object(u.a)(r));break}w(t)}}),d&&!F&&r.a.createElement("pre",null,d.graphQLErrors.map((function(e,t){var a=e.message;return r.a.createElement("span",{key:t},a)}))))}var Q={global:{colors:{brand:"rgb(24, 177, 147)"},font:{family:"Roboto",size:"18px",height:"20px"}}},B=new c.a({uri:"https://spotify-graphql-server.herokuapp.com/graphql",cache:new o.a});l.a.render(r.a.createElement(r.a.StrictMode,null,r.a.createElement(m.a,{client:B},r.a.createElement(L,null))),document.getElementById("root"))},49:function(e,t,a){e.exports=a.p+"static/media/placeholder-music.97fa2780.jpg"}},[[115,1,2]]]);
//# sourceMappingURL=main.29d93776.chunk.js.map