<commit_before>import React from 'react';

import { getPadStats, customizeEditor } from '../../editor';

import INITIAL_CONFIG from './data/config';
import INITIAL_CONTENT from './data/initialContent';

class Editor extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      ignoreNextLoadEvent: false,
      ignoreTextSynced: false,
      isKintoLoaded: false,
      content: null
    };
    this.editor = null;

    // Process events from chrome runtime onMessage
    this.events = eventData => {
      let content;
      switch (eventData.action) {
        case 'kinto-loaded':
          content = eventData.data;
          this.handleLocalContent(this.editor, content);
          this.setState({
            isKintoLoaded: true
          });
          break;
        case 'text-change':
          this.setState({
            ignoreNextLoadEvent: true
          });
          browser.runtime.sendMessage({
            action: 'kinto-load'
          });
          break;
        case 'text-synced':
          if (!this.state.ignoreTextSynced || eventData.conflict) {
            this.handleLocalContent(this.editor, eventData.content);
          }
          this.setState({
            ignoreTextSynced: false
          });
          break;
      }
    };

    this.handleLocalContent = function(editor, content) {
      if (!content) {
        browser.storage.local.get('notes2').then(data => {

          if (!data.hasOwnProperty('notes2')) {
            if (!this.editor) {
              this.init(content);
            } else {
              this.editor.setData(INITIAL_CONTENT);
            }
            this.setState({
              ignoreNextLoadEvent: true
            });
          } else {
            if (!this.editor) {
              this.init(data.notes2);
            } else {
              this.editor.setData(data.notes2);
            }
            chrome.runtime
              .sendMessage({
                action: 'kinto-save',
                content: data.notes2
              })
              .then(() => {
                // Clean-up<commit_msg>Fix missing initial content on react after refactoring loading<commit_after>import React from 'react';

import { getPadStats, customizeEditor } from '../../editor';

import INITIAL_CONFIG from './data/config';
import INITIAL_CONTENT from './data/initialContent';

class Editor extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      ignoreNextLoadEvent: false,
      ignoreTextSynced: false,
      isKintoLoaded: false,
      content: null
    };
    this.editor = null;

    // Process events from chrome runtime onMessage
    this.events = eventData => {
      let content;
      switch (eventData.action) {
        case 'kinto-loaded':
          content = eventData.data;
          this.handleLocalContent(this.editor, content);
          this.setState({
            isKintoLoaded: true
          });
          break;
        case 'text-change':
          this.setState({
            ignoreNextLoadEvent: true
          });
          browser.runtime.sendMessage({
            action: 'kinto-load'
          });
          break;
        case 'text-synced':
          if (!this.state.ignoreTextSynced || eventData.conflict) {
            this.handleLocalContent(this.editor, eventData.content);
          }
          this.setState({
            ignoreTextSynced: false
          });
          break;
      }
    };

    this.handleLocalContent = function(editor, content) {
      if (!content) {
        browser.storage.local.get('notes2').then(data => {

          if (!data.hasOwnProperty('notes2')) {
            if (!this.editor) {
              this.init(INITIAL_CONTENT);
            } else {
              this.editor.setData(INITIAL_CONTENT);
            }
            this.setState({
              ignoreNextLoadEvent: true
            });
          } else {
            if (!this.editor) {
              this.init(data.notes2);
            } else {
              this.editor.setData(data.notes2);
            }
            chrome.runtime
              .sendMessage({
                action: 'kinto-save',
                content: data.notes2
              })
              .then(() => {
                // Clean-up
{'fraction_non_alphanumeric': 0.11254396248534584, 'fraction_numerical': 0.0023446658851113715, 'mean_word_length': 1.5590881823635272, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3423460', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1120, 'n_words': 219}