"use strict"; var App = React.createClass({ getInitialState() { let updateTitle = true; if (storageAvailable('localStorage') && localStorage.getItem("updateTitle") !== null) { updateTitle = JSON.parse(localStorage.getItem("updateTitle")); } return { updateTitle: updateTitle, events: [] }; }, getDefaultProps() { return { gather: { gatherers: [] }, users: [], messages: [], maps: [], user: null, servers: [], archive: [], socket: null, soundController: null }; }, updateTitle() { let gather = this.props.gather; if (gather && this.state.updateTitle) { document.title = `NSL Gathers (${gather.gatherers.length}/12)`; return; } document.title = "NSL Gathers"; }, toggleUpdateTitle(event) { let newState = event.target.checked; this.setState({ updateTitle: newState }); if (storageAvailable('localStorage')) { localStorage.setItem("updateTitle", newState) } this.updateTitle(); }, thisGatherer() { let gather = this.props.gather; let user = this.props.user; if (gather && user && gather.gatherers.length) { return gather.gatherers .filter(gatherer => gatherer.id === user.id) .pop() || null; } return null; }, componentDidMount() { let self = this; let socket = this.props.socket; let soundController = this.props.soundController; this.updateTitle(); socket.on('stateChange', data => { let state = data.state; if (state.from === 'gathering' && state.to === 'election' && this.thisGatherer()) { soundController.playGatherMusic(); } if (state.from === 'election' && state.to === 'gathering') { soundController.stop(); } }); socket.on('event:append', data => { console.log(data) let events = self.state.events; events.unshift(data); self.setState({ events: events.slice(0, 20) }); }); socket.on('users:update', data => self.setProps({ users: data.users, user: data.currentUser }) ); socket.on("message:append", data => { self.setProps({ messages: self.props.messages.concat(data.messages) .sort((a, b) => { return new Date(a.createdAt) - new Date(b.createdAt); }) }); }); socket.on("message:refresh", data => { self.setProps({ messages: data.messages }); }); socket.on("gather:refresh", (data) => { self.setProps({ gather: data.gather, maps: data.maps, servers: data.servers, previousGather: data.previousGather }); this.updateTitle(); }); socket.on("gather:archive:refresh", data => { self.setProps({ archive: data.archive, maps: data.maps, servers: data.servers }); }); socket.emit("users:refresh"); socket.emit("message:refresh"); }, render() { return

} });