<commit_before><template>
  <div id="app">
    <div class="debug">
      <h1>debug toolbar</h1>
    </div>
    <p>
      <router-link to="/">Home</router-link>
      <router-link to="/queue">Queue</router-link>
      <router-link to="/game">Game</router-link>
      <router-link to="/admin">Admin</router-link>
    </p>
    <router-view></router-view>
  </div>
</template>
<script>
  import store from './components/store'
  import assert from 'assert'

  var request = require('superagent')
  var socketlib = require('socket.io-client')
  var socket = socketlib()
  var VueRouter = require('vue-router')
  var router = new VueRouter()

  function getAdminKey() {
    return window.localStorage.getItem('writeio-admin-key')
  }

  export default {
    name: 'app',
    components: {
      // Add any custom components here
    },
    data: function () {
      return {
        sharedState: store.state,
        consts: store.consts
      }
    },
    created: function () {
      var self = this

      function updateStateForPlayer(playerId) {
        request.get('/api/state')
          .set('Accept', 'application/json')
          .query({
            playerId
          })
          .end((err, res) => {
            assert(!err)
            assert(res.status === 200)

            let state = res.body
            assert(state)

            console.log(
              `Got server state (updated num players from ${self.sharedState.players.length} to ${state.players.length})`
            )
            self.sharedState.players = state.players

            // Populate iVotedFor boolean
            debugger
            let myPlayer = self.sharedState.players.find(player => player.id === self.sharedState.playerId)
            if (myPlayer) {
              self.sharedState.players = self.sharedState.players.map(player => {
                player.iVotedFor = (player.id === myPlayer.votedForId)
                return player
              })
            }

            assert(state.players.length <= self.consts.maxPlayers)
            // TODO Read current location from VueRouter here. router.history.current shows '/' for some reason
            if (state.players.length === self.consts.maxPlayers && window.location.hash.endsWith('/queue')) {
              router.replace('/game')
            }
          })
      }

      function updateAdminState() {
        let adminKey = getAdminKey()
        if (!adminKey) {
          return
        }

        request.get('/api/adminState')
          .set('Accept', 'application/json').query({
            adminKey
          }).end((err, res) => {
            assert(!err)
            assert(res.status === 200)
            self.sharedState.adminState = res.body
          })
      }

      function updateState() {
        // We only ask for state if we're logged in or admin
        if (self.sharedState.playerId) {
          updateStateForPlayer(self.sharedState.playerId)
        } else {
          updateAdminState()
        }
      }

      updateState()

      // Update on change when server state changes
      socket.on('server:state', function () {
        updateState()
      })

      // Routes
      // If we're not on the admin page, reload --> home
      if (!window.location.href.endsWith('admin')) {
        router.replace('/')
      }
    }
  }

</script>
<style>
  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
  }

  .debug {
    background-color: lightgray
  }

  a {
    margin-right: 10px;
  }

  .center {
    top: 50%;
    left: 50%;
    transform: translate3d(-50%, -50%, 0);
    position: absolute;
  }

</style>
<commit_msg>Move router-view out of debug toolbar<commit_after><template>
  <div id="app">
    <div class="debug">
      <h1>debug toolbar</h1>
      <p>
        <router-link to="/">Home</router-link>
        <router-link to="/queue">Queue</router-link>
        <router-link to="/game">Game</router-link>
        <router-link to="/admin">Admin</router-link>
      </p>
    </div>
    <router-view></router-view>
  </div>
</template>
<script>
  import store from './components/store'
  import assert from 'assert'

  var request = require('superagent')
  var socketlib = require('socket.io-client')
  var socket = socketlib()
  var VueRouter = require('vue-router')
  var router = new VueRouter()

  function getAdminKey() {
    return window.localStorage.getItem('writeio-admin-key')
  }

  export default {
    name: 'app',
    components: {
      // Add any custom components here
    },
    data: function () {
      return {
        sharedState: store.state,
        consts: store.consts
      }
    },
    created: function () {
      var self = this

      function updateStateForPlayer(playerId) {
        request.get('/api/state')
          .set('Accept', 'application/json')
          .query({
            playerId
          })
          .end((err, res) => {
            assert(!err)
            assert(res.status === 200)

            let state = res.body
            assert(state)

            console.log(
              `Got server state (updated num players from ${self.sharedState.players.length} to ${state.players.length})`
            )
            self.sharedState.players = state.players

            // Populate iVotedFor boolean
            debugger
            let myPlayer = self.sharedState.players.find(player => player.id === self.sharedState.playerId)
            if (myPlayer) {
              self.sharedState.players = self.sharedState.players.map(player => {
                player.iVotedFor = (player.id === myPlayer.votedForId)
                return player
              })
            }

            assert(state.players.length <= self.consts.maxPlayers)
            // TODO Read current location from VueRouter here. router.history.current shows '/' for some reason
            if (state.players.length === self.consts.maxPlayers && window.location.hash.endsWith('/queue')) {
              router.replace('/game')
            }
          })
      }

      function updateAdminState() {
        let adminKey = getAdminKey()
        if (!adminKey) {
          return
        }

        request.get('/api/adminState')
          .set('Accept', 'application/json').query({
            adminKey
          }).end((err, res) => {
            assert(!err)
            assert(res.status === 200)
            self.sharedState.adminState = res.body
          })
      }

      function updateState() {
        // We only ask for state if we're logged in or admin
        if (self.sharedState.playerId) {
          updateStateForPlayer(self.sharedState.playerId)
        } else {
          updateAdminState()
        }
      }

      updateState()

      // Update on change when server state changes
      socket.on('server:state', function () {
        updateState()
      })

      // Routes
      // If we're not on the admin page, reload --> home
      if (!window.location.href.endsWith('admin')) {
        router.replace('/')
      }
    }
  }

</script>
<style>
  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
  }

  .debug {
    background-color: lightgray
  }

  a {
    margin-right: 10px;
  }

  .center {
    top: 50%;
    left: 50%;
    transform: translate3d(-50%, -50%, 0);
    position: absolute;
  }

</style>

{'fraction_non_alphanumeric': 0.13408190224570674, 'fraction_numerical': 0.006869220607661823, 'mean_word_length': 1.8602191159803552, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1139569', 'n_tokens_mistral': 2301, 'n_tokens_neox': 2201, 'n_words': 475}