<commit_before>'use babel';

import React from 'react';
import AddClient from './AddClient';
import SelectClient from './SelectClient';
import EditClient from './EditClient';
import EditDay from './EditDay';
import AddFood from './AddFood';
import AddDish from './AddDish';
import AddBaking from './AddBaking';
import SelectFood from './SelectFood';
import SelectDish from './SelectDish';
import SelectBaking from './SelectBaking';
import WeekView from './WeekView';
import NavigationButton from './NavigationButton';
import Loki from 'lokijs';

const demoData = require('../scripts/demoData');

let database = new Loki('app.db');

database.loadDatabase({}, () => {
  onDatabaseLoad();
});

// TODO: Refactor all this to just create all databases in one go
// if the first checked database is null
// The if debug mode, populate with demoData

const onDatabaseLoad = () => {
  console.log('database loaded');
  if (database.getCollection('clients') == null) {
    console.log("Creating clients collection");
    var clients = database.addCollection('clients', {
      indices: ['name']
    });
    database.saveDatabase();
  }
  if (database.getCollection('clientsDays') == null) {
    console.log("Creating clientsDays collection");
    var days = database.addCollection('clientsDays', {
      indices: ['clientId']
    });
    database.saveDatabase();
  }
  if (database.getCollection('daysMeals') == null) {
    console.log("Creating daysMeals collection");
    var meals = database.addCollection('daysMeals', {
      indices: ['clientId']
    });
    database.saveDatabase();
  }
  if (database.getCollection('mealsFood') == null) { // Also think: mealsDishes
    console.log("Creating mealsFood collection");
    var meals = database.addCollection('mealsFood', {
      indices: ['mealsId']
    });
    database.saveDatabase();
  }
  if (database.getCollection('foodBank') == null) {
    console.log("Creating foodBank collection");
    var meals = database.addCollection('foodBank', {
      indices: ['name']
    });
    database.saveDatabase();
  }
  if (database.getCollection('dishBank') == null) {
    console.log("Creating dishBank collection");
    var meals = database.addCollection('dishBank', {
      indices: ['name']
    });
    database.saveDatabase();
  }
  if (database.getCollection('dishesFoods') == null) {
    console.log("Creating dishesFoods collection");
    var meals = database.addCollection('dishesFoods', {
      indices: ['dishId']
    });
    database.saveDatabase();
  }
  if (database.getCollection('bakingBank') == null) {
    console.log("Creating bakingBank collection");
    var meals = database.addCollection('bakingBank', {
      indices: ['name']
    });
    database.saveDatabase();
  }
  if (database.getCollection('mealsBaking') == null) {
    console.log("Creating mealsBaking collection");
    var meals = database.addCollection('mealsBaking', {
      indices: ['mealsId']
    });
    database.saveDatabase();
    // Now add demoData
    demoData.setDemoData(database);
  }
}

class View extends React.Component {

  constructor(props) {
    super();
    this.state = props.state;
    this.state.setParentState = props.setParentState;
    this.state.database = database;
  }

  componentWillReceiveProps(props) {
    this.setState(props.state);
  }

  render() {
    if (this.state.currentView == 'SelectClient') {
      return <div><SelectClient state={this.state} /></div>;
    }
    if (this.state.currentView == 'EditClient') {<commit_msg>Refacted collection creation<commit_after>'use babel';

import React from 'react';
import AddClient from './AddClient';
import SelectClient from './SelectClient';
import EditClient from './EditClient';
import EditDay from './EditDay';
import AddFood from './AddFood';
import AddDish from './AddDish';
import AddBaking from './AddBaking';
import SelectFood from './SelectFood';
import SelectDish from './SelectDish';
import SelectBaking from './SelectBaking';
import WeekView from './WeekView';
import NavigationButton from './NavigationButton';
import Loki from 'lokijs';

const debugMode = true;
const demoData = require('../scripts/demoData');

let database = new Loki('app.db');

database.loadDatabase({}, () => {
  onDatabaseLoad();
});

const onDatabaseLoad = () => {
  console.log('database loaded');
  if (database.getCollection('clients') == null) {
    console.log("No collections found. Creating database collections");
    var clients = database.addCollection('clients', {indices: ['name']});
    var days = database.addCollection('clientsDays', {indices: ['clientId']});
    var meals = database.addCollection('daysMeals', {indices: ['clientId']});
    var meals = database.addCollection('mealsFood', {indices: ['mealsId']});
    var meals = database.addCollection('foodBank', {indices: ['name']});
    var meals = database.addCollection('dishBank', {indices: ['name']});
    var meals = database.addCollection('dishesFoods', {indices: ['dishId']});
    var meals = database.addCollection('bakingBank', {indices: ['name']});
    var meals = database.addCollection('mealsBaking', {indices: ['mealsId']});
    // Now add demoData
    if (debugMode) {
      demoData.setDemoData(database);
    }
  }
}

class View extends React.Component {

  constructor(props) {
    super();
    this.state = props.state;
    this.state.setParentState = props.setParentState;
    this.state.database = database;
  }

  componentWillReceiveProps(props) {
    this.setState(props.state);
  }

  render() {
    if (this.state.currentView == 'SelectClient') {
      return <div><SelectClient state={this.state} /></div>;
    }
    if (this.state.currentView == 'EditClient') {
{'fraction_non_alphanumeric': 0.15455349248452696, 'fraction_numerical': 0.0, 'mean_word_length': 4.109304426377597, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '1025588', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1616, 'n_words': 398}