File size: 1,798 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import * as types from '../action-types';

export const addNotes = ( notes ) => ( {
	type: types.NOTES_ADD,
	notes,
} );

export const removeNotes = ( noteIds, isComment = false ) => ( {
	type: types.NOTES_REMOVE,
	noteIds,
	isComment,
} );

export const noteAction = ( action ) => ( noteId ) => ( {
	type: action,
	noteId,
} );

export const readNote = noteAction( types.READ_NOTE );
export const spamNote = noteAction( types.SPAM_NOTE );
export const trashNote = noteAction( types.TRASH_NOTE );

export const approveNote = ( noteId, isApproved ) => ( {
	type: types.APPROVE_NOTE,
	noteId,
	isApproved,
} );

export const likeNote = ( noteId, isLiked ) => ( {
	type: types.LIKE_NOTE,
	noteId,
	isLiked,
} );

/**
 * Resets the local cache overrride on note approval status
 *
 * When a note is locally approved we cache an override in
 * the app so that stale data coming in from polling
 * operations don't accidentally change this value to
 * an incorrect state and cause a flash of the approval status.
 * @see approveNote
 * @param {number} noteId
 * @returns {Object} action object
 */
export const resetLocalApproval = ( noteId ) => ( {
	type: types.RESET_LOCAL_APPROVAL,
	noteId,
} );

/**
 * Resets the local cache overrride on note like status
 *
 * When a note is locally liked we cache an override in
 * the app so that stale data coming in from polling
 * operations don't accidentally change this value to
 * an incorrect state and cause a flash of the like status.
 * @see likeNote
 * @param {number} noteId
 * @returns {Object} action object
 */
export const resetLocalLike = ( noteId ) => ( {
	type: types.RESET_LOCAL_LIKE,
	noteId,
} );

export default {
	addNotes,
	approveNote,
	likeNote,
	readNote,
	removeNotes,
	resetLocalApproval,
	resetLocalLike,
	spamNote,
	trashNote,
};