<commit_before>import React, { Component } from 'react';
import Reboot from 'material-ui/Reboot';
import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles';
import axios from 'axios';

import { storageAvailable } from './Utils.js';

import CategoryView from './CategoryView/CategoryView.js';
import DailyView from './DailyView/DailyView.js';
import HistoryView from './HistoryView/HistoryView.js';
import LoginView from './LoginView/LoginView.js';
import AppTabs from './AppTabs/AppTabs.js';
import APPVIEWS from './APPVIEWS.js';


const theme = createMuiTheme({
  palette: {
    type: 'dark'
  },
});


class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      view: APPVIEWS.home,
      loggedIn: false,
      error: "",
    };
    this.handleTabClick = this.handleTabClick.bind(this);
    this.handleLogOut = this.handleLogOut.bind(this);
  }

  componentDidMount() {
    // TODO: put this in a method and call it whenever view changes.
    if(storageAvailable('localStorage')) {
      let authToken = localStorage.getItem('authToken') || "";
      axios.post('/refresh-token/', {token: authToken})
        .then(
          (response) => {
            axios.defaults.headers.common['Authorization'] = 'JWT ' + response.data.token;
            this.setState({
              loggedIn: true,
            });
          },
          // I suppose I don't really care what happens with the errors here...
          (error) => {
            if (error.response && error.response.status === 400) {
              console.log(error.response.data);
            } else {
              console.log(error);
            }
          }
        );
    } else {
      console.log('localStorage not available. Cannot maintain session.') //TODO
    }
  }

  handleLogOut(e) {
    axios.post('/rest-auth/logout/')
      .then(
        (response) => {
          this.setState({
            loggedIn: false
          });
        },
        (error) => {
          this.setState({
            error: "Error during Log Out: " + error
          });
        }
      )
  }

  handleTabClick(view, e) {
    this.setState({
      view: view
    });
  }

  render() {
    let view = null;
    if (this.state.view === APPVIEWS.categories) {
      view = (
        <CategoryView />
      )
    } else if (this.state.view === APPVIEWS.daily) {
      view = (
        <DailyView />
      )<commit_msg>erasing token from localstorage on logout<commit_after>import React, { Component } from 'react';
import Reboot from 'material-ui/Reboot';
import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles';
import axios from 'axios';

import { storageAvailable } from './Utils.js';

import CategoryView from './CategoryView/CategoryView.js';
import DailyView from './DailyView/DailyView.js';
import HistoryView from './HistoryView/HistoryView.js';
import LoginView from './LoginView/LoginView.js';
import AppTabs from './AppTabs/AppTabs.js';
import APPVIEWS from './APPVIEWS.js';


const theme = createMuiTheme({
  palette: {
    type: 'dark'
  },
});


class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      view: APPVIEWS.home,
      loggedIn: false,
      error: "",
    };
    this.handleTabClick = this.handleTabClick.bind(this);
    this.handleLogOut = this.handleLogOut.bind(this);
  }

  componentDidMount() {
    // TODO: put this in a method and call it whenever view changes.
    if(storageAvailable('localStorage')) {
      let authToken = localStorage.getItem('authToken') || "";
      axios.post('/refresh-token/', {token: authToken})
        .then(
          (response) => {
            axios.defaults.headers.common['Authorization'] = 'JWT ' + response.data.token;
            this.setState({
              loggedIn: true,
            });
          },
          // I suppose I don't really care what happens with the errors here...
          (error) => {
            if (error.response && error.response.status === 400) {
              console.log(error.response.data);
            } else {
              console.log(error);
            }
          }
        );
    } else {
      console.log('localStorage not available. Cannot maintain session.') //TODO
    }
  }

  handleLogOut(e) {
    axios.post('/rest-auth/logout/')
      .then(
        (response) => {
          localStorage.setItem('authToken', "");
          this.setState({
            loggedIn: false,
            view: APPVIEWS.home
          });
        },
        (error) => {
          this.setState({
            error: "Error during Log Out: " + error
          });
        }
      )
  }

  handleTabClick(view, e) {
    this.setState({
      view: view
    });
  }

  render() {
    let view = null;
    if (this.state.view === APPVIEWS.categories) {
      view = (
        <CategoryView />
      )
    } else if (this.state.view === APPVIEWS.daily) {
      view = (
        <DailyView />
      )
{'fraction_non_alphanumeric': 0.1388663967611336, 'fraction_numerical': 0.0012145748987854252, 'mean_word_length': 2.065136476426799, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '6695170', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1471, 'n_words': 328}