From e3884467d3cf833d690ad22dd05b9133fcb4091f Mon Sep 17 00:00:00 2001
From: donal <donalspring@gmail.com>
Date: Wed, 04 Apr 2018 16:51:23 +0200
Subject: [PATCH] FIX broken vuex stuff

---
 src/store/actions.js |   48 +++++++++++++++++++++++++++++++++++-------------
 1 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/src/store/actions.js b/src/store/actions.js
index deaf05d..844a6b8 100644
--- a/src/store/actions.js
+++ b/src/store/actions.js
@@ -1,6 +1,23 @@
 import axios from "axios";
 import config from "@/config";
 
+const dummyData = [
+  {
+    title: "Learn awesome things about Labs",
+    completed: false,
+    important: false
+  },
+  {
+    title: "Learn about my friend Jenkins",
+    completed: true,
+    important: false
+  },
+  {
+    title: "Have a poop",
+    completed: false,
+    important: true
+  }
+];
 export default {
   loadTodos({ commit }) {
     axios
@@ -9,6 +26,12 @@
       .then(todos => {
         commit("SET_TODOS", todos);
         commit("SET_LOADING", false);
+      }).catch(err => {
+        if (err) {
+          console.info("INFO - setting dummy data because of ", err)
+          commit("SET_TODOS", dummyData);
+          commit("SET_LOADING", false);
+        }
       });
   },
   addTodo({ commit, state }) {
@@ -16,36 +39,35 @@
       // do not add empty todos
       return;
     }
-    debugger
+    // debugger
     const todo = {
       title: state.newTodo,
-      complete: false,
-      important: false,
-      id: Math.floor(1 + (9999 - 1) * Math.random())
+      completed: false,
+      important: false
     };
     axios.post(config.todoEndpoint, todo).then(mongoTodo => {
       commit("ADD_TODO", mongoTodo.data);
     });
   },
-  setNewTodo ({ commit }, todo) {
+  setNewTodo({ commit }, todo) {
     // debugger
-    commit('SET_NEW_TODO', todo)
+    commit("SET_NEW_TODO", todo);
   },
-  updateTodo({ commit,state }, todo) {
+  updateTodo({ commit, state }, todo) {
     // const todo = state.newTodo
-    debugger
+    // debugger;
     const foundIndex = state.todos.findIndex(obj => obj.id === todo.id);
     state.todos[foundIndex] = todo;
-    const newUpdatedArray = state.todos
-    commit("UPDATE_TODO", newUpdatedArray)
+    const newUpdatedArray = state.todos;
+    commit("UPDATE_TODO", newUpdatedArray);
   },
   clearNewTodo({ commit }) {
     commit("CLEAR_NEW_TODO");
   },
   clearAllTodos({ commit }) {
-    commit("CLEAR_ALL_TODOS")
+    commit("CLEAR_ALL_TODOS");
   },
   clearAllDoneTodos({ commit }) {
-    commit("CLEAR_ALL_DONE_TODOS")
-  },
+    commit("CLEAR_ALL_DONE_TODOS");
+  }
 };

--
Gitblit v1.9.3