<commit_before>/* global chrome */
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { Store } from 'react-chrome-redux'
import OptionsPageApp from './components/options/OptionsPageApp'
import PopupPageApp from './components/popup/PopupPageApp'

function renderOptionsPageApp(root, store) {
  if (window.location.hash.substring(1) !== '') {
    console.log('Updating current view', window.location.hash.substring(1))
    store.dispatch({
      'type': 'SET_CURRENT_VIEW',
      view: window.location.hash.substring(1)
    })
  }

  window.addEventListener('hashchange', function () {
    store.dispatch({
      'type': 'SET_CURRENT_VIEW',
      view: window.location.hash.substring(1)
    })
  })

  ReactDOM.render(
    <Provider store={store}><OptionsPageApp/></Provider>, root)
}

function renderPopupPageApp(root, store) {
  chrome.tabs.query({ 'active': true, 'lastFocusedWindow': true }, function (tabs) {
    window.setTimeout(
      // The timeout is important to remediate a chrome bug: https://bugs.chromium.org/p/chromium/issues/detail?id=307912
      function () {
        ReactDOM.render(
          <Provider store={store}><PopupPageApp currentUrl={tabs[0].url}/></Provider>, root)
      }, 150)
  })
}

function updateCurrentPage() {
  if (window.location.hash !== '#' + store.getState().currentView) {
    console.log('Setting hash by subscribe: #' + store.getState().currentView)
    var cv = typeof store.getState().currentView === 'undefined' ? '' : store.getState().currentView
    window.history.pushState(null, null, '#' + cv)
  }
}

const store = new Store({
  portName: 'DEMO_MONKEY_STORE' // communication port name
})<commit_msg>Fix bug #40<commit_after>/* global chrome */
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { Store } from 'react-chrome-redux'
import OptionsPageApp from './components/options/OptionsPageApp'
import PopupPageApp from './components/popup/PopupPageApp'

function renderOptionsPageApp(root, store) {
  if (window.location.hash.substring(1) !== '') {
    console.log('Updating current view', window.location.hash.substring(1))
    store.dispatch({
      'type': 'SET_CURRENT_VIEW',
      view: window.location.hash.substring(1)
    })
  }

  window.addEventListener('hashchange', function () {
    store.dispatch({
      'type': 'SET_CURRENT_VIEW',
      view: window.location.hash.substring(1)
    })
  })

  ReactDOM.render(
    <Provider store={store}><OptionsPageApp/></Provider>, root)
}

function renderPopupPageApp(root, store) {
  chrome.tabs.query({ 'active': true, 'lastFocusedWindow': true }, function (tabs) {
    ReactDOM.render(
      <Provider store={store}><PopupPageApp currentUrl={tabs[0].url}/></Provider>, root)
    // The following is required to fix https://bugs.chromium.org/p/chromium/issues/detail?id=428044
    window.setTimeout(() => {
      document.body.style.minHeight = (document.body.clientHeight + 1) + 'px'
    }, 200)
  })
}

function updateCurrentPage() {
  if (window.location.hash !== '#' + store.getState().currentView) {
    console.log('Setting hash by subscribe: #' + store.getState().currentView)
    var cv = typeof store.getState().currentView === 'undefined' ? '' : store.getState().currentView
    window.history.pushState(null, null, '#' + cv)
  }
}

const store = new Store({
  portName: 'DEMO_MONKEY_STORE' // communication port name
})
{'fraction_non_alphanumeric': 0.15536231884057972, 'fraction_numerical': 0.008985507246376812, 'mean_word_length': 4.052708638360175, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 2, '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': '851955', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1058, 'n_words': 218}