|
1
|
|
|
import Vue from 'Vue'; |
|
2
|
|
|
|
|
3
|
|
|
export const setConfig = function(state, config) { |
|
4
|
|
|
Vue.set(state, 'config', Object.assign({}, state.config, config)); |
|
5
|
|
|
}; |
|
6
|
|
|
|
|
7
|
|
|
export const setLastCommentTime = function(state) { |
|
8
|
|
|
state.lastCommentTime = new Date(); |
|
9
|
|
|
}; |
|
10
|
|
|
|
|
11
|
|
|
export const setMaxDepth = function(state, depth) { |
|
12
|
|
|
if (typeof depth !== 'number') { |
|
13
|
|
|
throw 'Depth must be an integer'; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
state.maxDepth = depth; |
|
17
|
|
|
}; |
|
18
|
|
|
|
|
19
|
|
|
export const setOrderBy = function(state, orderBy) { |
|
20
|
|
|
state.orderBy = orderBy; |
|
21
|
|
|
}; |
|
22
|
|
|
|
|
23
|
|
|
export const orderByNewest = function(state) { |
|
24
|
|
|
state.orderBy = 'newest'; |
|
25
|
|
|
}; |
|
26
|
|
|
|
|
27
|
|
|
export const oderByOldest = function(state) { |
|
28
|
|
|
state.orderBy = 'oldest'; |
|
29
|
|
|
}; |
|
30
|
|
|
|
|
31
|
|
|
export const setUser = function(state, user) { |
|
32
|
|
|
Vue.set(state, 'user', user); |
|
33
|
|
|
}; |
|
34
|
|
|
|
|
35
|
|
|
export const addComment = function(state, comment) { |
|
36
|
|
|
let comments = state.comments; |
|
37
|
|
|
|
|
38
|
|
|
comment.created = new Date(comment.created); |
|
39
|
|
|
comments.push(comment); |
|
40
|
|
|
|
|
41
|
|
|
Vue.set(state, 'comments', comments); |
|
42
|
|
|
}; |
|
43
|
|
|
|
|
44
|
|
|
export const deleteComment = function(state, comment) { |
|
45
|
|
|
let comments = state.comments.filter(function(commentFromList) { |
|
46
|
|
|
return commentFromList.id !== comment.id; |
|
47
|
|
|
}); |
|
48
|
|
|
Vue.set(state, 'comments', comments); |
|
49
|
|
|
}; |
|
50
|
|
|
|
|
51
|
|
|
export const updateComment = function(state, editedComment) { |
|
52
|
|
|
state.comments.forEach(function(comment) { |
|
53
|
|
|
if (comment.id == editedComment.id) { |
|
54
|
|
|
let index = state.comments.indexOf(comment); |
|
55
|
|
|
state.comments[index] = editedComment; |
|
56
|
|
|
} |
|
57
|
|
|
}); |
|
58
|
|
|
}; |
|
59
|
|
|
|
|
60
|
|
|
export const updatePagination = function(state, data) { |
|
61
|
|
|
let key = data.model + data.modelId + data.parentId; |
|
62
|
|
|
|
|
63
|
|
|
Vue.set(state.pagination, key, data.pagination); |
|
64
|
|
|
}; |
|
65
|
|
|
|
|
66
|
|
|
export const clearComments = function(state) { |
|
67
|
|
|
Vue.set(state, 'comments', []); |
|
68
|
|
|
}; |
|
69
|
|
|
|