git.fiddlerwoaroof.com
Browse code

added persistence

fiddlerwoaroof authored on 11/03/2017 23:34:40
Showing 4 changed files
... ...
@@ -1,6 +1,14 @@
1 1
 # time-tracker
2 2
 
3
-> A Vue.js project
3
+A simple stopwatch app written in Vuejs. It's (somewhat unique)
4
+feature is that you can attach an arbitrary number of annotations to
5
+each stopwatch "lap".
6
+
7
+We persist all data in localStorage
8
+
9
+Built with the new CSS Grid properties, so you have to enable that in
10
+chrome://flags or the like.
11
+
4 12
 
5 13
 ## Build Setup
6 14
 
... ...
@@ -10,7 +10,9 @@
10 10
   },
11 11
   "dependencies": {
12 12
     "vue": "^2.2.1",
13
-    "vuex": "^2.2.1"
13
+    "vuex": "^2.2.1",
14
+    "vuex-localstorage": "^1.0.0",
15
+    "vuex-persistedstate": "^1.3.0"
14 16
   },
15 17
   "devDependencies": {
16 18
     "babel-core": "^6.0.0",
... ...
@@ -53,6 +53,13 @@ export default {
53 53
 	times() {
54 54
 	    let result = [];
55 55
 	    for (let cur of this.$store.state.times) {
56
+		if ((typeof cur.time) === "string") {
57
+		    cur = Object.assign(
58
+			Object.create(cur),
59
+			{time: new Date(cur.time)}
60
+		    );
61
+		}
62
+		
56 63
 		let diff = 0, cum = 0;
57 64
 		if (cur.id > 0) {
58 65
 		    cum = cur.time - result[cur.id-1][0].time;
... ...
@@ -1,12 +1,16 @@
1 1
 import Vue from 'vue';
2 2
 import Vuex from 'vuex';
3 3
 import App from './App.vue';
4
+import createPersistedState from 'vuex-persistedstate'
4 5
 Vue.use(Vuex);
5 6
 
6 7
 new Vue({
7 8
     el: '#app',
8 9
     render: h => h(App),
9 10
     store: new Vuex.Store({
11
+	plugins: [
12
+	    createPersistedState()
13
+	],
10 14
 	state: {
11 15
 	    times: []
12 16
 	},