(window.webpackJsonp=window.webpackJsonp||[]).push([[0],{13:function(e,t,a){},14:function(e,t,a){},15:function(e,t,a){"use strict";a.r(t);var n=a(0),r=a.n(n),c=a(5),o=a.n(c),l=(a(13),a(3)),s=a(1),u=a(2),i=(a(14),a(6)),d=new URLSearchParams(document.location.search),m=d.get("host"),f=parseInt(d.get("port")),h=r.a.createContext(!1),p=r.a.createContext({}),E=function(){var e=r.a.useContext(p).state,t=r.a.useContext(h);return r.a.createElement("header",null,r.a.createElement("h1",{className:t?"":"offline"},"Hoist ",r.a.createElement("span",null,e.selectedGroup||"")),r.a.createElement("span",null,t?"Connected":"Connecting"," to ws://",m,":",f))},v=function(){var e=r.a.useContext(p);return r.a.createElement("nav",null,Array.from(e.state.groups).sort().map(function(t){return r.a.createElement("div",{key:t},r.a.createElement("a",{href:"#",onClick:function(){return e.dispatch({type:y,data:t})}},t,e.state.unread[t]?r.a.createElement("span",{className:"unread"},e.state.unread[t]):null))}))},g=function(){var e=r.a.useContext(p);return r.a.createElement("div",{id:"controls"},r.a.createElement("div",{className:"item"},r.a.createElement("label",{htmlFor:"auto-scroll"},r.a.createElement("input",{id:"auto-scroll",type:"checkbox",checked:e.state.autoScroll,onChange:function(t){return e.dispatch({type:C,data:t.target.checked})}})," Auto-scroll")))},w=function(){var e=r.a.useContext(p),t=r.a.useRef(null),a=r.a.useRef(null),n=e.state.messages[e.state.selectedGroup]||[];r.a.useEffect(function(){t.current&&e.state.autoScroll&&t.current.scrollToItem(n.length-1)});return r.a.createElement("main",{ref:a},r.a.createElement(i.a,{ref:t,height:a.current?a.current.clientHeight:16,itemCount:n.length,itemSize:16,width:"100%",overscanCount:24},function(e){var t=e.index,a=e.style,c=n[t];return r.a.createElement("div",{key:c.id,className:"std ".concat(c.std),style:a},r.a.createElement("div",{className:"index"},c.index),c.message)}))},S=function(e){var t=e.host,a=e.port,n=e.setConnected,c=e.onMessage;r.a.useEffect(function(){var e=null,r=[];setInterval(function(){r.length&&(c(r),r.splice(0,r.length))},1e3/12);var o=setInterval(function(){e&&3!==e.readyState?1===e.readyState&&n(!0):((e=new WebSocket("ws://".concat(t,":").concat(a))).onmessage=function(e){var t=JSON.parse(e.data);r.push(t)},e.onclose=function(){n(!1)})},500);return function(){return clearInterval(o)}},[])},y="NEW_SELECTION",C="TOGGLE_AUTOSCROLL",x=function(e,t){switch(t.type){case"NEW_MESSAGE":var a=!0,n=!1,r=void 0;try{for(var c,o=t.data[Symbol.iterator]();!(a=(c=o.next()).done);a=!0){var l=c.value,i=e.messages[l.alias]||[];for(i.length?l.index=i[i.length-1].index+1:(e.unread[l.alias]=0,l.index=1),i=i.concat(l);i.length>=1e4;)i.shift();e.messages[l.alias]=i,e.groups=new Set(e.groups).add(l.alias),e.selectedGroup||(e.selectedGroup=l.alias),e.selectedGroup!==l.alias&&(e.unread[l.alias]+=1)}}catch(m){n=!0,r=m}finally{try{a||null==o.return||o.return()}finally{if(n)throw r}}return Object.assign({},e);case y:var d=Object(u.a)({},e.unread,Object(s.a)({},t.data,0));return Object(u.a)({},e,{selectedGroup:t.data,unread:d});case C:return Object(u.a)({},e,{autoScroll:t.data})}},b=function(){var e=r.a.useState(!1),t=Object(l.a)(e,2),a=t[0],n=t[1],c=r.a.useReducer(x,{groups:new Set,messages:{},selectedGroup:null,autoScroll:!0,unread:{}}),o=Object(l.a)(c,2),s=o[0],u=o[1];return S({host:m,port:f,setConnected:n,onMessage:function(e){u({type:"NEW_MESSAGE",data:e})}}),r.a.createElement(h.Provider,{value:a},r.a.createElement(p.Provider,{value:{state:s,dispatch:u}},r.a.createElement("div",{className:"App"},r.a.createElement(E,null),r.a.createElement("div",{className:"grid"},r.a.createElement(v,null),r.a.createElement(g,null),r.a.createElement(w,null)))))};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}$/));o.a.render(r.a.createElement(b,null),document.getElementById("root")),"serviceWorker"in navigator&&navigator.serviceWorker.ready.then(function(e){e.unregister()})},7:function(e,t,a){e.exports=a(15)}},[[7,1,2]]]);
//# sourceMappingURL=main.59cfe229.chunk.js.map