import { NEW_SECTION } from '../actions/sectionActions';
import { NEW_ENTRY } from '../actions/entryActions';
import { NEW_FIELD } from '../actions/fieldActions';
import store from './store';

export default class SocketEvents {
  constructor(socket, dispatch) {
    this.dispatch = dispatch;
    this.socket = socket;
  }

  newField() {
    const { fields } = store.getState().fields;
    this.socket.on('new-field', (newField) => {
      if (!fields.some(field => field._id === newField._id)) {
        this.dispatch({ type: NEW_FIELD, json: newField });
      }
    });
  }

  newEntry() {
    const { entries } = store.getState().entries;
    console.log(store.getState());
    this.socket.on('new-entry', (newEntry) => {
      if (!entries.some(entry => entry._id === newEntry._id)) {
        this.dispatch({ type: NEW_ENTRY, json: newEntry });
      }
    });
  }

  deleteEntry() {
    this.socket.on('delete-entry', deletedId => console.log(deletedId));
  }

  newSection() {
    const { sections } = store.getState().sections;
    this.socket.on('new-section', (newSection) => {
      if (!sections.some(section => section._id === newSection._id)) {
        this.dispatch({ type: NEW_SECTION, newSection });
      }
    });
  }

  deleteSection() {
    this.socket.on('delete-section', deletedId => console.log(deletedId));
  }

  listen() {
    this.newField();

    this.newEntry();
    this.deleteEntry();

    this.newSection();
    this.deleteSection();
  }
}

@@ -340,99 +340,101 @@
     
-const %7B fields %7D = store.getState().fields;%0A    this.socket.on('new-field', (newField) =%3E %7B
+this.socket.on('new-field', (newField) =%3E %7B%0A      const %7B fields %7D = store.getState().fields;
 %0A   
@@ -580,153 +580,216 @@
 %0A%0A  
-newEntry() %7B%0A    const %7B entries %7D = store.getState().entries;%0A    console.log(store.getState());%0A    this.socket.on('new-entry', (newEntry) =%3E %7B
+deleteField() %7B%0A    this.socket.on('delete-field', deletedId =%3E console.log(deletedId));%0A  %7D%0A%0A  newEntry() %7B%0A    this.socket.on('new-entry', (newEntry) =%3E %7B%0A      const %7B entries %7D = store.getState().entries;
 %0A   
@@ -1051,107 +1051,109 @@
     
-const %7B sections %7D = store.getState().sections;%0A    this.socket.on('new-section', (newSection) =%3E %7B
+this.socket.on('new-section', (newSection) =%3E %7B%0A      const %7B sections %7D = store.getState().sections;
 %0A   
@@ -1420,25 +1420,129 @@
     
-this.newField();%0A
+// Listen for new or delete Fields%0A    this.newField();%0A    this.deletedField();%0A%0A    // Listen for new or delete Entries
 %0A   
@@ -1580,24 +1580,65 @@
 teEntry();%0A%0A
+    // Listen for new or delete Sections%0A
     this.new

Fix socket events